Java Code Examples for javax.xml.ws.handler.MessageContext.Scope#APPLICATION
The following examples show how to use
javax.xml.ws.handler.MessageContext.Scope#APPLICATION .
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: JaxWsClientProxy.java From cxf with Apache License 2.0 | 5 votes |
public Map<String, Object> getRequestContext() { if (client == null) { throw new IllegalStateException("The client has been closed."); } return new WrappedMessageContext(this.getClient().getRequestContext(), null, Scope.APPLICATION); }
Example 3
Source File: JaxWsClientProxy.java From cxf with Apache License 2.0 | 5 votes |
public Map<String, Object> getResponseContext() { if (client == null) { throw new IllegalStateException("The client has been closed."); } return new WrappedMessageContext(this.getClient().getResponseContext(), null, Scope.APPLICATION); }
Example 4
Source File: DispatchImpl.java From cxf with Apache License 2.0 | 5 votes |
private void setupEndpointAddressContext(Endpoint endpoint) { //NOTE for jms transport the address would be null if (null != endpoint && null != endpoint.getEndpointInfo().getAddress()) { Map<String, Object> requestContext = new WrappedMessageContext(client.getRequestContext(), null, Scope.APPLICATION); requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint.getEndpointInfo().getAddress()); } }
Example 5
Source File: WrappedMessageContextTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testContainsKey() throws Exception { WrappedMessageContext context = new WrappedMessageContext(new HashMap<String, Object>(), null, Scope.APPLICATION); Map<String, List<String>> headers = new HashMap<>(); context.put(MessageContext.HTTP_REQUEST_HEADERS, headers); assertNotNull(context.get(MessageContext.HTTP_REQUEST_HEADERS)); assertTrue(context.containsKey(MessageContext.HTTP_REQUEST_HEADERS)); }
Example 6
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 7
Source File: DispatchImpl.java From cxf with Apache License 2.0 | 4 votes |
public Map<String, Object> getRequestContext() { return new WrappedMessageContext(client.getRequestContext(), null, Scope.APPLICATION); }
Example 8
Source File: DispatchImpl.java From cxf with Apache License 2.0 | 4 votes |
public Map<String, Object> getResponseContext() { return new WrappedMessageContext(client.getResponseContext(), null, Scope.APPLICATION); }
Example 9
Source File: JAXWSMethodInvoker.java From cxf with Apache License 2.0 | 4 votes |
@Override protected Object invoke(Exchange exchange, final Object serviceObject, Method m, List<Object> params) { // set up the webservice request context WrappedMessageContext ctx = new WrappedMessageContext(exchange.getInMessage(), Scope.APPLICATION); Map<String, Object> handlerScopedStuff = removeHandlerProperties(ctx); final MessageContext oldCtx = WebServiceContextImpl.setMessageContext(ctx); List<Object> res = null; try { if ((params == null || params.isEmpty()) && serviceObject instanceof Provider) { params = Collections.singletonList(null); } res = CastUtils.cast((List<?>)super.invoke(exchange, serviceObject, m, params)); if ((serviceObject instanceof Provider) && MessageUtils.getContextualBoolean(exchange.getInMessage(), "jaxws.provider.interpretNullAsOneway", true) && (res != null && !res.isEmpty() && res.get(0) == null) && exchange.getInMessage().getInterceptorChain().getState() == InterceptorChain.State.EXECUTING) { // treat the non-oneway call as oneway when a provider returns null // and the chain is not suspended due to a continuation suspend res = null; changeToOneway(exchange); } //update the webservice response context updateWebServiceContext(exchange, ctx); } catch (Fault f) { //get chance to copy over customer's header if (MessageUtils.getContextualBoolean(exchange.getInMessage(), COPY_SOAP_HEADERS_BY_FAULT, true)) { updateHeader(exchange, ctx); } throw f; } finally { //restore the WebServiceContextImpl's ThreadLocal variable to the previous value if (oldCtx == null) { WebServiceContextImpl.clear(); } else { WebServiceContextImpl.setMessageContext(oldCtx); } addHandlerProperties(ctx, handlerScopedStuff); } return res; }
Example 10
Source File: WrappedMessageContextTest.java From cxf with Apache License 2.0 | 4 votes |
@Test public void testPutAndGetJaxwsAttachments() throws Exception { WrappedMessageContext context = new WrappedMessageContext(new HashMap<String, Object>(), null, Scope.APPLICATION); DataHandler dh1 = new DataHandler(new ByteArrayDataSource("Hello world!".getBytes(), "text/plain")); DataHandler dh2 = new DataHandler(new ByteArrayDataSource("Hola mundo!".getBytes(), "text/plain")); DataHandler dh3 = new DataHandler(new ByteArrayDataSource("Bonjour tout le monde!".getBytes(), "text/plain")); Map<String, DataHandler> jattachments = new HashMap<>(); context.put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS, jattachments); jattachments.put("attachment-1", dh1); Set<Attachment> cattachments = CastUtils.cast((Set<?>)context.get(Message.ATTACHMENTS)); assertNotNull(cattachments); assertEquals(1, cattachments.size()); jattachments.put("attachment-2", dh2); assertEquals(2, cattachments.size()); AttachmentImpl ca = new AttachmentImpl("attachment-3", dh3); ca.setHeader("X-test", "true"); cattachments.add(ca); assertEquals(3, jattachments.size()); assertEquals(3, cattachments.size()); for (Attachment a : cattachments) { if ("attachment-1".equals(a.getId())) { assertEquals("Hello world!", a.getDataHandler().getContent()); } else if ("attachment-2".equals(a.getId())) { assertEquals("Hola mundo!", a.getDataHandler().getContent()); } else if ("attachment-3".equals(a.getId())) { assertEquals("Bonjour tout le monde!", a.getDataHandler().getContent()); assertEquals("true", a.getHeader("X-test")); } else { fail("unknown attachment"); } } }