Java Code Examples for org.apache.cxf.message.message#putAll()
The following examples show how to use
org.apache.cxf.message.message#putAll() .
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: ContextPropertiesMappingTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testCreateWebServiceContext() { Exchange exchange = new ExchangeImpl(); Message inMessage = new MessageImpl(); Message outMessage = new MessageImpl(); inMessage.putAll(message); exchange.setInMessage(inMessage); exchange.setOutMessage(outMessage); MessageContext ctx = new WrappedMessageContext(exchange.getInMessage(), Scope.APPLICATION); Object requestHeader = ctx.get(MessageContext.HTTP_REQUEST_HEADERS); assertNotNull("the request header should not be null", requestHeader); assertEquals("we should get the request header", requestHeader, HEADER); Object responseHeader = ctx.get(MessageContext.HTTP_RESPONSE_HEADERS); assertNull("the response header should be null", responseHeader); Object outMessageHeader = outMessage.get(Message.PROTOCOL_HEADERS); assertEquals("the outMessage PROTOCOL_HEADERS should be update", responseHeader, outMessageHeader); Object inAttachments = ctx.get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS); assertNotNull("inbound attachments object must be initialized", inAttachments); assertTrue("inbound attachments must be in a Map", inAttachments instanceof Map); assertTrue("no inbound attachments expected", ((Map<?, ?>)inAttachments).isEmpty()); }
Example 2
Source File: AbstractClient.java From cxf with Apache License 2.0 | 6 votes |
protected void setContexts(Message message, Exchange exchange, Map<String, Object> context, boolean proxy) { if (context == null) { context = new HashMap<>(); } Map<String, Object> reqContext = CastUtils.cast((Map<?, ?>)context.get(REQUEST_CONTEXT)); Map<String, Object> resContext = CastUtils.cast((Map<?, ?>)context.get(RESPONSE_CONTEXT)); if (reqContext == null) { reqContext = new HashMap<>(cfg.getRequestContext()); context.put(REQUEST_CONTEXT, reqContext); } reqContext.put(Message.PROTOCOL_HEADERS, message.get(Message.PROTOCOL_HEADERS)); reqContext.put(Message.REQUEST_URI, message.get(Message.REQUEST_URI)); reqContext.put(Message.ENDPOINT_ADDRESS, message.get(Message.ENDPOINT_ADDRESS)); reqContext.put(PROXY_PROPERTY, proxy); if (resContext == null) { resContext = new HashMap<>(); context.put(RESPONSE_CONTEXT, resContext); } message.put(Message.INVOCATION_CONTEXT, context); message.putAll(reqContext); exchange.putAll(reqContext); }
Example 3
Source File: BasicAuthInterceptor.java From geofence with GNU General Public License v2.0 | 5 votes |
private Message getOutMessage(Message inMessage) { Exchange exchange = inMessage.getExchange(); Message outMessage = exchange.getOutMessage(); if (outMessage == null) { Endpoint endpoint = exchange.get(Endpoint.class); outMessage = endpoint.getBinding().createMessage(); exchange.setOutMessage(outMessage); } outMessage.putAll(inMessage); return outMessage; }
Example 4
Source File: AuthenticationHandler.java From geofence with GNU General Public License v2.0 | 5 votes |
/** * @param inMessage * @return Message */ private Message getOutMessage(Message inMessage) { Exchange exchange = inMessage.getExchange(); Message outMessage = exchange.getOutMessage(); if (outMessage == null) { Endpoint endpoint = exchange.get(Endpoint.class); outMessage = endpoint.getBinding().createMessage(); exchange.setOutMessage(outMessage); } outMessage.putAll(inMessage); return outMessage; }
Example 5
Source File: ContextPropertiesMappingTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testCreateWebServiceContextWithInAttachments() { Exchange exchange = new ExchangeImpl(); Message inMessage = new MessageImpl(); Collection<Attachment> attachments = new LinkedList<>(); DataSource source = new ByteDataSource(new byte[0], "text/xml"); DataHandler handler1 = new DataHandler(source); attachments.add(new AttachmentImpl("part1", handler1)); DataHandler handler2 = new DataHandler(source); attachments.add(new AttachmentImpl("part2", handler2)); inMessage.setAttachments(attachments); inMessage.putAll(message); exchange.setInMessage(inMessage); exchange.setOutMessage(new MessageImpl()); MessageContext ctx = new WrappedMessageContext(exchange.getInMessage(), Scope.APPLICATION); Object inAttachments = ctx.get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS); assertNotNull("inbound attachments object must be initialized", inAttachments); assertTrue("inbound attachments must be in a Map", inAttachments instanceof Map); Map<String, DataHandler> dataHandlers = CastUtils.cast((Map<?, ?>)inAttachments); assertEquals("two inbound attachments expected", 2, dataHandlers.size()); assertTrue("part1 attachment is missing", dataHandlers.containsKey("part1")); // should do as it's the same instance assertTrue("part1 handler is missing", dataHandlers.get("part1") == handler1); assertTrue("part2 attachment is missing", dataHandlers.containsKey("part2")); assertTrue("part2 handler is missing", dataHandlers.get("part2") == handler2); }
Example 6
Source File: ColocOutInterceptor.java From cxf with Apache License 2.0 | 5 votes |
protected void invokeInboundChain(Exchange ex, Endpoint ep) { Message m = getInBoundMessage(ex); Message inMsg = ep.getBinding().createMessage(); MessageImpl.copyContent(m, inMsg); //Copy Response Context to Client inBound Message //TODO a Context Filter Strategy required. inMsg.putAll(m); inMsg.put(Message.REQUESTOR_ROLE, Boolean.TRUE); inMsg.put(Message.INBOUND_MESSAGE, Boolean.TRUE); inMsg.setExchange(ex); Exception exc = inMsg.getContent(Exception.class); if (exc != null) { ex.setInFaultMessage(inMsg); ColocInFaultObserver observer = new ColocInFaultObserver(bus); observer.onMessage(inMsg); } else { //Handle Response ex.setInMessage(inMsg); PhaseManager pm = bus.getExtension(PhaseManager.class); SortedSet<Phase> phases = new TreeSet<>(pm.getInPhases()); ColocUtil.setPhases(phases, Phase.USER_LOGICAL, Phase.PRE_INVOKE); InterceptorChain chain = ColocUtil.getInInterceptorChain(ex, phases); inMsg.setInterceptorChain(chain); chain.doIntercept(inMsg); } ex.put(ClientImpl.FINISHED, Boolean.TRUE); }
Example 7
Source File: JettyHTTPDestinationTest.java From cxf with Apache License 2.0 | 5 votes |
private Message setUpOutMessage() { Message outMsg = new MessageImpl(); outMsg.putAll(inMessage); outMsg.setExchange(new ExchangeImpl()); outMsg.put(Message.PROTOCOL_HEADERS, new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER)); return outMsg; }
Example 8
Source File: UndertowHTTPDestinationTest.java From cxf with Apache License 2.0 | 5 votes |
private Message setUpOutMessage() { Message outMsg = new MessageImpl(); outMsg.putAll(inMessage); outMsg.setExchange(new ExchangeImpl()); outMsg.put(Message.PROTOCOL_HEADERS, new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER)); return outMsg; }
Example 9
Source File: NettyHttpDestinationTest.java From cxf with Apache License 2.0 | 5 votes |
private Message setUpOutMessage() { Message outMsg = new MessageImpl(); outMsg.putAll(inMessage); outMsg.setExchange(new ExchangeImpl()); outMsg.put(Message.PROTOCOL_HEADERS, new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER)); return outMsg; }
Example 10
Source File: ClientImpl.java From cxf with Apache License 2.0 | 5 votes |
protected void setContext(Map<String, Object> ctx, Message message) { if (ctx != null) { message.putAll(ctx); if (LOG.isLoggable(Level.FINE)) { LOG.fine("set requestContext to message be" + ctx); } } }
Example 11
Source File: ClientImpl.java From cxf with Apache License 2.0 | 5 votes |
public Conduit getConduit() { Message message = new MessageImpl(); Exchange exchange = new ExchangeImpl(); message.setExchange(exchange); message.putAll(getRequestContext()); setExchangeProperties(exchange, getEndpoint(), null); return getConduitSelector().selectConduit(message); }
Example 12
Source File: BasicAuthenticationInterceptor.java From dropwizard-jaxws with Apache License 2.0 | 5 votes |
private Message getOutMessage(Message inMessage) { Exchange exchange = inMessage.getExchange(); Message outMessage = exchange.getOutMessage(); if (outMessage == null) { Endpoint endpoint = exchange.get(Endpoint.class); outMessage = endpoint.getBinding().createMessage(); exchange.setOutMessage(outMessage); } outMessage.putAll(inMessage); return outMessage; }
Example 13
Source File: ColocMessageObserver.java From cxf with Apache License 2.0 | 4 votes |
public void onMessage(Message m) { Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus); ClassLoaderHolder origLoader = null; try { if (loader != null) { origLoader = ClassLoaderUtils.setThreadContextClassloader(loader); } if (LOG.isLoggable(Level.FINER)) { LOG.finer("Processing Message at collocated endpoint. Request message: " + m); } Exchange ex = new ExchangeImpl(); setExchangeProperties(ex, m); Message inMsg = endpoint.getBinding().createMessage(); MessageImpl.copyContent(m, inMsg); //Copy Request Context to Server inBound Message //TODO a Context Filter Strategy required. inMsg.putAll(m); inMsg.put(COLOCATED, Boolean.TRUE); inMsg.put(Message.REQUESTOR_ROLE, Boolean.FALSE); inMsg.put(Message.INBOUND_MESSAGE, Boolean.TRUE); BindingOperationInfo boi = ex.getBindingOperationInfo(); OperationInfo oi = boi != null ? boi.getOperationInfo() : null; if (oi != null) { inMsg.put(MessageInfo.class, oi.getInput()); } ex.setInMessage(inMsg); inMsg.setExchange(ex); if (LOG.isLoggable(Level.FINEST)) { LOG.finest("Build inbound interceptor chain."); } //Add all interceptors between USER_LOGICAL and INVOKE. SortedSet<Phase> phases = new TreeSet<>(bus.getExtension(PhaseManager.class).getInPhases()); ColocUtil.setPhases(phases, Phase.USER_LOGICAL, Phase.INVOKE); InterceptorChain chain = ColocUtil.getInInterceptorChain(ex, phases); chain.add(addColocInterceptors()); inMsg.setInterceptorChain(chain); //Convert the coloc object type if necessary BindingOperationInfo bop = m.getExchange().getBindingOperationInfo(); OperationInfo soi = bop != null ? bop.getOperationInfo() : null; if (soi != null && oi != null) { if (ColocUtil.isAssignableOperationInfo(soi, Source.class) && !ColocUtil.isAssignableOperationInfo(oi, Source.class)) { // converting source -> pojo ColocUtil.convertSourceToObject(inMsg); } else if (ColocUtil.isAssignableOperationInfo(oi, Source.class) && !ColocUtil.isAssignableOperationInfo(soi, Source.class)) { // converting pojo -> source ColocUtil.convertObjectToSource(inMsg); } } chain.doIntercept(inMsg); if (soi != null && oi != null) { if (ColocUtil.isAssignableOperationInfo(soi, Source.class) && !ColocUtil.isAssignableOperationInfo(oi, Source.class) && ex.getOutMessage() != null) { // converting pojo -> source ColocUtil.convertObjectToSource(ex.getOutMessage()); } else if (ColocUtil.isAssignableOperationInfo(oi, Source.class) && !ColocUtil.isAssignableOperationInfo(soi, Source.class) && ex.getOutMessage() != null) { // converting pojo -> source ColocUtil.convertSourceToObject(ex.getOutMessage()); } } //Set Server OutBound Message onto InBound Exchange. setOutBoundMessage(ex, m.getExchange()); } finally { if (origBus != bus) { BusFactory.setThreadDefaultBus(origBus); } if (origLoader != null) { origLoader.reset(); } } }