Java Code Examples for org.apache.cxf.message.Message#containsKey()
The following examples show how to use
org.apache.cxf.message.Message#containsKey() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpUtils.java From cxf with Apache License 2.0 | 6 votes |
public static String getEndpointAddress(Message m) { String address = null; Destination d = m.getExchange().getDestination(); if (d != null) { if (d instanceof AbstractHTTPDestination) { EndpointInfo ei = ((AbstractHTTPDestination)d).getEndpointInfo(); HttpServletRequest request = (HttpServletRequest)m.get(AbstractHTTPDestination.HTTP_REQUEST); Object property = request != null ? request.getAttribute("org.apache.cxf.transport.endpoint.address") : null; address = property != null ? property.toString() : ei.getAddress(); } else { address = m.containsKey(Message.BASE_PATH) ? (String)m.get(Message.BASE_PATH) : d.getAddress().getAddress().getValue(); } } else { address = (String)m.get(Message.ENDPOINT_ADDRESS); } if (address.startsWith("http") && address.endsWith("//")) { address = address.substring(0, address.length() - 1); } return address; }
Example 2
Source File: WireTapIn.java From cxf with Apache License 2.0 | 6 votes |
@Override public void handleMessage(final Message message) throws Fault { if (message.containsKey(WIRE_TAP_STARTED)) { return; } message.put(WIRE_TAP_STARTED, Boolean.TRUE); try { InputStream is = message.getContent(InputStream.class); if (is != null) { handleInputStream(message, is); } else { Reader reader = message.getContent(Reader.class); if (reader != null) { handleReader(message, reader); } } } catch (Exception e) { throw new Fault(e); } }
Example 3
Source File: XMLBinding.java From cxf with Apache License 2.0 | 6 votes |
public Message createMessage(Message m) { if (!m.containsKey(Message.CONTENT_TYPE)) { String ct = null; // Should this be done in ServiceInvokerInterceptor to support a case where the // response content type is detected early on the inbound chain for all the bindings ? Exchange exchange = m.getExchange(); if (exchange != null) { ct = (String)exchange.get(Message.CONTENT_TYPE); } if (ct == null) { ct = "text/xml"; } m.put(Message.CONTENT_TYPE, ct); } return new XMLMessage(m); }
Example 4
Source File: AbstractClient.java From cxf with Apache License 2.0 | 6 votes |
private void setRequestMethod(Message m, String httpMethod) { m.put(Message.HTTP_REQUEST_METHOD, httpMethod); if (!KNOWN_METHODS.contains(httpMethod)) { if (!m.containsKey("use.async.http.conduit")) { // if the async conduit is loaded then let it handle this method without users // having to explicitly request it given that, without reflectively updating // HTTPUrlConnection, it will not work without the async conduit anyway m.put("use.async.http.conduit", true); } if (!m.containsKey("use.httpurlconnection.method.reflection")) { // if the async conduit is not loaded then the only way for the custom HTTP verb // to be supported is to attempt to reflectively modify HTTPUrlConnection m.put("use.httpurlconnection.method.reflection", true); } } }
Example 5
Source File: BackChannelConduit.java From cxf with Apache License 2.0 | 6 votes |
/** * Send an outbound message, assumed to contain all the name-value mappings of the corresponding input * message (if any). * * @param message the message to be sent. */ public void prepare(final Message message) throws IOException { // setup the message to be sent back javax.jms.Message jmsMessage = (javax.jms.Message)inMessage .get(JMSConstants.JMS_REQUEST_MESSAGE); message.put(JMSConstants.JMS_REQUEST_MESSAGE, jmsMessage); if (!message.containsKey(JMSConstants.JMS_SERVER_RESPONSE_HEADERS) && inMessage.containsKey(JMSConstants.JMS_SERVER_RESPONSE_HEADERS)) { message.put(JMSConstants.JMS_SERVER_RESPONSE_HEADERS, inMessage .get(JMSConstants.JMS_SERVER_RESPONSE_HEADERS)); } Exchange exchange = inMessage.getExchange(); exchange.setOutMessage(message); boolean isTextMessage = (jmsMessage instanceof TextMessage) && !JMSMessageUtils.isMtomEnabled(message); MessageStreamUtil.prepareStream(message, isTextMessage, this); }
Example 6
Source File: GiornaleEventiUtilities.java From govpay with GNU General Public License v3.0 | 5 votes |
public static String safeGet(Message message, String key) { if (message == null || !message.containsKey(key)) { return null; } Object value = message.get(key); return (value instanceof String) ? value.toString() : null; }
Example 7
Source File: AbstractJAXWSMethodInvoker.java From cxf with Apache License 2.0 | 5 votes |
protected void updateWebServiceContext(Exchange exchange, MessageContext ctx) { // Guard against wrong type associated with header list. // Need to copy header only if the message is going out. if (ctx.containsKey(Header.HEADER_LIST) && ctx.get(Header.HEADER_LIST) instanceof List<?>) { List<?> list = (List<?>) ctx.get(Header.HEADER_LIST); if (list != null && !list.isEmpty()) { SoapMessage sm = (SoapMessage) createResponseMessage(exchange); if (sm != null) { Iterator<?> iter = list.iterator(); while (iter.hasNext()) { sm.getHeaders().add((Header) iter.next()); } } } } if (exchange.getOutMessage() != null) { Message out = exchange.getOutMessage(); if (out.containsKey(Message.PROTOCOL_HEADERS)) { Map<String, List<String>> heads = CastUtils .cast((Map<?, ?>)exchange.getOutMessage().get(Message.PROTOCOL_HEADERS)); if (heads.containsKey("Content-Type")) { List<String> ct = heads.get("Content-Type"); exchange.getOutMessage().put(Message.CONTENT_TYPE, ct.get(0)); heads.remove("Content-Type"); } } } }
Example 8
Source File: DefaultLogEventMapper.java From cxf with Apache License 2.0 | 5 votes |
private static String safeGet(Message message, String key) { if (message == null || !message.containsKey(key)) { return null; } Object value = message.get(key); return (value instanceof String) ? value.toString() : null; }
Example 9
Source File: SimpleThrottlingManager.java From cxf with Apache License 2.0 | 5 votes |
@Override public ThrottleResponse getThrottleResponse(String phase, Message m) { if (m.containsKey(THROTTLED_KEY)) { return null; } m.getExchange().put(ThrottlingCounter.class, counter); if (counter.incrementAndGet() >= threshold) { m.put(THROTTLED_KEY, true); return this; } return null; }
Example 10
Source File: AbstractTracingProvider.java From cxf with Apache License 2.0 | 5 votes |
private static String safeGet(Message message, String key) { if (!message.containsKey(key)) { return null; } Object value = message.get(key); return (value instanceof String) ? value.toString() : null; }
Example 11
Source File: OAuthInvoker.java From cxf with Apache License 2.0 | 5 votes |
@Override protected Object performInvocation(Exchange exchange, final Object serviceObject, Method m, Object[] paramArray) throws Exception { Message inMessage = exchange.getInMessage(); ClientTokenContext tokenContext = inMessage.getContent(ClientTokenContext.class); try { if (tokenContext != null) { StaticClientTokenContext.setClientTokenContext(tokenContext); } return super.performInvocation(exchange, serviceObject, m, paramArray); } catch (InvocationTargetException ex) { if (tokenContext != null && ex.getCause() instanceof NotAuthorizedException && !inMessage.containsKey(OAUTH2_CALL_RETRIED)) { ClientAccessToken accessToken = tokenContext.getToken(); String refreshToken = accessToken.getRefreshToken(); if (refreshToken != null) { accessToken = OAuthClientUtils.refreshAccessToken(accessTokenServiceClient, consumer, accessToken); validateRefreshedToken(tokenContext, accessToken); MessageContext mc = new MessageContextImpl(inMessage); ((ClientTokenContextImpl)tokenContext).setToken(accessToken); clientTokenContextManager.setClientTokenContext(mc, tokenContext); //retry inMessage.put(OAUTH2_CALL_RETRIED, true); return super.performInvocation(exchange, serviceObject, m, paramArray); } } throw ex; } finally { if (tokenContext != null) { StaticClientTokenContext.removeClientTokenContext(); } } }
Example 12
Source File: JettyHTTPDestination.java From cxf with Apache License 2.0 | 5 votes |
protected void setupContinuation(Message inMessage, final HttpServletRequest req, final HttpServletResponse resp) { if (engine != null && engine.getContinuationsEnabled()) { super.setupContinuation(inMessage, req, resp); if (!inMessage.containsKey(ContinuationProvider.class.getName())) { inMessage.put(ContinuationProvider.class.getName(), new JettyContinuationProvider(req, resp, inMessage)); } } }
Example 13
Source File: LoggingOutInterceptor.java From cxf with Apache License 2.0 | 5 votes |
public void handleMessage(Message message) { final OutputStream os = message.getContent(OutputStream.class); final Writer iowriter = message.getContent(Writer.class); if (os == null && iowriter == null) { return; } Logger logger = getMessageLogger(message); if (logger != null && (logger.isLoggable(Level.INFO) || writer != null)) { // Write the output while caching it for the log message boolean hasLogged = message.containsKey(LOG_SETUP); if (!hasLogged) { message.put(LOG_SETUP, Boolean.TRUE); if (os != null) { final CacheAndWriteOutputStream newOut = new CacheAndWriteOutputStream(os); if (threshold > 0) { newOut.setThreshold(threshold); } if (limit > 0) { newOut.setCacheLimit(limit); } message.setContent(OutputStream.class, newOut); newOut.registerCallback(new LoggingCallback(logger, message, os)); } else { message.setContent(Writer.class, new LogWriter(logger, message, iowriter)); } } } }
Example 14
Source File: PropertyHolderFactory.java From cxf with Apache License 2.0 | 4 votes |
public static PropertyHolder getPropertyHolder(Message m) { return m.containsKey("HTTP.REQUEST") ? new ServletRequestPropertyHolder(m) : new MessagePropertyHolder(m); }
Example 15
Source File: LoggingInInterceptor.java From cxf with Apache License 2.0 | 4 votes |
protected void logging(Logger logger, Message message) { if (message.containsKey(LoggingMessage.ID_KEY)) { return; } String id = (String)message.getExchange().get(LoggingMessage.ID_KEY); if (id == null) { id = LoggingMessage.nextId(); message.getExchange().put(LoggingMessage.ID_KEY, id); } message.put(LoggingMessage.ID_KEY, id); final LoggingMessage buffer = new LoggingMessage("Inbound Message\n----------------------------", id); if (!Boolean.TRUE.equals(message.get(Message.DECOUPLED_CHANNEL_MESSAGE))) { // avoid logging the default responseCode 200 for the decoupled responses Integer responseCode = (Integer)message.get(Message.RESPONSE_CODE); if (responseCode != null) { buffer.getResponseCode().append(responseCode); } } String encoding = (String)message.get(Message.ENCODING); if (encoding != null) { buffer.getEncoding().append(encoding); } String httpMethod = (String)message.get(Message.HTTP_REQUEST_METHOD); if (httpMethod != null) { buffer.getHttpMethod().append(httpMethod); } String ct = (String)message.get(Message.CONTENT_TYPE); if (ct != null) { buffer.getContentType().append(ct); } Object headers = message.get(Message.PROTOCOL_HEADERS); if (headers != null) { buffer.getHeader().append(headers); } String uri = (String)message.get(Message.REQUEST_URL); if (uri == null) { String address = (String)message.get(Message.ENDPOINT_ADDRESS); uri = (String)message.get(Message.REQUEST_URI); if (uri != null && uri.startsWith("/")) { if (address != null && !address.startsWith(uri)) { if (address.endsWith("/") && address.length() > 1) { address = address.substring(0, address.length() - 1); } uri = address + uri; } } else { uri = address; } } if (uri != null) { buffer.getAddress().append(uri); String query = (String)message.get(Message.QUERY_STRING); if (query != null) { buffer.getAddress().append('?').append(query); } } if (!isShowBinaryContent() && isBinaryContent(ct)) { buffer.getMessage().append(BINARY_CONTENT_MESSAGE).append('\n'); log(logger, buffer.toString()); return; } if (!isShowMultipartContent() && isMultipartContent(ct)) { buffer.getMessage().append(MULTIPART_CONTENT_MESSAGE).append('\n'); log(logger, buffer.toString()); return; } InputStream is = message.getContent(InputStream.class); if (is != null) { logInputStream(message, is, buffer, encoding, ct); } else { Reader reader = message.getContent(Reader.class); if (reader != null) { logReader(message, reader, buffer); } } log(logger, formatLoggingMessage(buffer)); }