Java Code Examples for org.apache.cxf.message.MessageImpl#setExchange()

The following examples show how to use org.apache.cxf.message.MessageImpl#setExchange() . 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: SseEventSinkContextProviderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    provider = new SseEventSinkContextProvider();
    
    final Exchange exchange = mock(Exchange.class);
    final Endpoint endpoint = mock(Endpoint.class);
    final ContinuationProvider continuationProvider = mock(ContinuationProvider.class);
    
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockAsyncContext ctx = new MockAsyncContext(request, response) {
        @Override
        public void start(Runnable runnable) {
            /* do nothing */
        } 
    };
    request.setAsyncContext(ctx);
    
    message = new MessageImpl();
    message.setExchange(exchange);
    message.put(ContinuationProvider.class.getName(), continuationProvider);
    message.put(AbstractHTTPDestination.HTTP_REQUEST, request);
    
    when(exchange.getEndpoint()).thenReturn(endpoint);
}
 
Example 2
Source File: LoggingInInterceptorTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    loggingMessage = new LoggingMessage("", "");
    control = EasyMock.createNiceControl();

    StringWriter sw = new StringWriter();
    sw.append("<today/>");
    message = new MessageImpl();
    message.setExchange(new ExchangeImpl());
    message.put(Message.CONTENT_TYPE, "application/xml");
    message.setContent(Writer.class, sw);

    inputStream = control.createMock(InputStream.class);
    EasyMock.expect(inputStream.read(EasyMock.anyObject(byte[].class), EasyMock.anyInt(), EasyMock.anyInt()))
            .andAnswer(new IAnswer<Integer>() {
                public Integer answer() {
                    System.arraycopy(bufferContent.getBytes(), 0,
                            EasyMock.getCurrentArguments()[0], 0,
                            bufferLength);
                    return bufferLength;
                }
            }).andStubReturn(-1);
    control.replay();
}
 
Example 3
Source File: CorbaConduit.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void handleResponse() throws IOException {
    LOG.log(Level.FINE, "incoming observer is " + incomingObserver);
    Exchange exchange = message.getExchange();
    CorbaMessage corbaMsg = (CorbaMessage) message;
    MessageImpl inMessage = new MessageImpl();
    CorbaDestination destination = new CorbaDestination(endpointInfo, orbConfig, typeMap);
    inMessage.setDestination(destination);
    exchange.put(ORB.class, orb);
    inMessage.setExchange(exchange);
    CorbaMessage inCorbaMsg = new CorbaMessage(inMessage);
    inCorbaMsg.setCorbaTypeMap(typeMap);
    if (corbaMsg.getStreamableException() != null) {
        exchange.setInFaultMessage(corbaMsg);
        inCorbaMsg.setStreamableException(corbaMsg.getStreamableException());
    } else if (corbaMsg.getSystemException() != null) {
        exchange.setInFaultMessage(corbaMsg);
        inCorbaMsg.setSystemException(corbaMsg.getSystemException());
    }
    LOG.log(Level.FINE, "incoming observer is " + incomingObserver);
    incomingObserver.onMessage(inCorbaMsg);
    message.setContent(Exception.class, inCorbaMsg.getContent(Exception.class));
}
 
Example 4
Source File: ContextUtilsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testIsOutbound() {
    assertThat(isOutbound(null), is(false));

    MessageImpl message = new MessageImpl();
    assertThat(isOutbound(message), is(false));

    message.setExchange(new ExchangeImpl());
    assertThat(isOutbound(message), is(false));

    message.getExchange().setOutMessage(message);
    assertThat(isOutbound(message), is(true));

    message.getExchange().setOutMessage(null);
    message.getExchange().setOutFaultMessage(message);
    assertThat(isOutbound(message), is(true));
}
 
Example 5
Source File: DocLiteralInInterceptorTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void setUpUsingDocLit() throws Exception {
    String ns = "http://apache.org/hello_world_doc_lit_bare";
    WSDLServiceFactory factory = new WSDLServiceFactory(bus, getClass()
        .getResource("/wsdl/jaxb/doc_lit_bare.wsdl").toString(), new QName(ns, "SOAPService"));

    service = factory.create();
    endpointInfo = service.getEndpointInfo(new QName(ns, "SoapPort"));
    endpoint = new EndpointImpl(bus, service, endpointInfo);
    JAXBDataBinding db = new JAXBDataBinding();
    db.setContext(JAXBContext.newInstance(new Class[] {TradePriceData.class}));
    service.setDataBinding(db);

    operation = endpointInfo.getBinding().getOperation(new QName(ns, "SayHi"));
    operation.getOperationInfo().getInput().getMessagePartByIndex(0).setTypeClass(TradePriceData.class);
    operation.getOperationInfo().getOutput().getMessagePartByIndex(0).setTypeClass(TradePriceData.class);

    message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);

    exchange.put(Service.class, service);
    exchange.put(Endpoint.class, endpoint);
    exchange.put(Binding.class, endpoint.getBinding());
}
 
Example 6
Source File: ContextUtilsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testIsFault() {
    assertThat(isFault(null), is(false));

    MessageImpl message = new MessageImpl();
    assertThat(isFault(message), is(false));

    message.setExchange(new ExchangeImpl());
    assertThat(isFault(message), is(false));

    message.getExchange().setInFaultMessage(message);
    assertThat(isFault(message), is(true));

    message.getExchange().setInFaultMessage(null);
    message.getExchange().setOutFaultMessage(message);
    assertThat(isFault(message), is(true));
}
 
Example 7
Source File: ServiceModelUtilsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    super.setUpBus();

    message = new MessageImpl();
    exchange = new ExchangeImpl();
    message.setExchange(exchange);

    bean = new JaxWsServiceFactoryBean();
    bean.setBus(getBus());
}
 
Example 8
Source File: TestUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static SoapMessage createEmptySoapMessage(SoapVersion soapVersion, InterceptorChain chain) {
    Exchange exchange = new ExchangeImpl();
    MessageImpl messageImpl = new MessageImpl();
    messageImpl.setInterceptorChain(chain);
    messageImpl.setExchange(exchange);
    SoapMessage soapMessage = new SoapMessage(messageImpl);
    soapMessage.setVersion(soapVersion);
    soapMessage.put(Message.HTTP_REQUEST_METHOD, "POST");
    return soapMessage;
}
 
Example 9
Source File: GZIPAcceptEncodingTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    interceptor = new GZIPOutInterceptor();
    inMessage = new MessageImpl();
    outMessage = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    exchange.setInMessage(inMessage);
    inMessage.setExchange(exchange);
    inMessage.setContent(InputStream.class, new ByteArrayInputStream(new byte[0]));
    exchange.setOutMessage(outMessage);
    outMessage.setExchange(exchange);
    outMessage.setContent(OutputStream.class, new ByteArrayOutputStream());
    outInterceptors = EasyMock.createMock(InterceptorChain.class);
    outMessage.setInterceptorChain(outInterceptors);
}
 
Example 10
Source File: JMSContinuationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    m = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    m.setExchange(exchange);
    m.setInterceptorChain(EasyMock.createMock(InterceptorChain.class));
    exchange.setInMessage(m);

    b = BusFactory.getDefaultBus();
    observer = EasyMock.createMock(MessageObserver.class);
}
 
Example 11
Source File: CorbaDSIServant.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void invoke(ServerRequest request) throws CorbaBindingException {
    String opName = request.operation();
    QName requestOperation = operationMap.get(opName);

    MessageImpl msgImpl = new MessageImpl();
    msgImpl.setDestination(getDestination());
    Exchange exg = new ExchangeImpl();
    exg.put(String.class, requestOperation.getLocalPart());
    exg.put(ORB.class, getOrb());
    exg.put(ServerRequest.class, request);
    msgImpl.setExchange(exg);
    CorbaMessage msg = new CorbaMessage(msgImpl);
    msg.setCorbaTypeMap(typeMap);

    // If there's no output message part in our operation then it's a oneway op
    BindingMessageInfo bindingMsgOutputInfo = null;
    BindingOperationInfo bindingOpInfo = null;
    try {
        bindingOpInfo = this.destination.getEndPointInfo().getBinding().getOperation(requestOperation);
    } catch (Exception ex) {
        throw new CorbaBindingException("Invalid Request. Operation unknown: " + opName);
    }
    if (bindingOpInfo != null) {
        bindingMsgOutputInfo = bindingOpInfo.getOutput();
        if (bindingMsgOutputInfo == null) {
            exg.setOneWay(true);
        }
    }

    // invokes the interceptors
    getObserver().onMessage(msg);
}
 
Example 12
Source File: WSPolicyFeature.java    From cxf with Apache License 2.0 5 votes vote down vote up
private MessageImpl createMessage(Endpoint e, Bus b) {
    MessageImpl m = new MessageImpl();
    Exchange ex = new ExchangeImpl();
    m.setExchange(ex);
    ex.put(Endpoint.class, e);
    ex.put(Bus.class, b);
    ex.put(Service.class, e.getService());
    return m;
}
 
Example 13
Source File: OutgoingChainInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testInterceptor() throws Exception {
    OutgoingChainInterceptor intc = new OutgoingChainInterceptor();

    MessageImpl m = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    m.setExchange(exchange);
    exchange.put(Bus.class, bus);
    exchange.put(Endpoint.class, endpoint);
    exchange.put(Binding.class, binding);
    exchange.put(BindingOperationInfo.class, bopInfo);
    exchange.setOutMessage(m);
    intc.handleMessage(m);
}
 
Example 14
Source File: HandlerChainInvokerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
    public void setUp() {
        AbstractHandlerBase.clear();

        @SuppressWarnings("rawtypes")
        List<Handler> handlers = new ArrayList<>();
        for (int i = 0; i < logicalHandlers.length; i++) {
            logicalHandlers[i] = new TestLogicalHandler();
            handlers.add(logicalHandlers[i]);
        }
        for (int i = 0; i < protocolHandlers.length; i++) {
            protocolHandlers[i] = new TestProtocolHandler();
            handlers.add(protocolHandlers[i]);
        }

        invoker = new HandlerChainInvoker(handlers);

        message = new MessageImpl();
        Exchange e = new ExchangeImpl();
        message.setExchange(e);
        lmc = new LogicalMessageContextImpl(message);
        pmc = new WrappedMessageContext(message);
/*
        payload = new DOMSource();
        message.setContent(Source.class, payload);*/

    }
 
Example 15
Source File: BareInInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void setUpUsingDocLit() throws Exception {
    String ns = "http://apache.org/hello_world_doc_lit_bare";
    WSDLServiceFactory factory = new WSDLServiceFactory(bus, getClass()
        .getResource("/wsdl/jaxb/doc_lit_bare.wsdl").toString(),
                                                        new QName(ns, "SOAPService"));

    service = factory.create();
    endpointInfo = service.getServiceInfos().get(0).getEndpoint(new QName(ns, "SoapPort"));
    endpoint = new EndpointImpl(bus, service, endpointInfo);
    JAXBDataBinding db = new JAXBDataBinding();
    db.setContext(JAXBContext.newInstance(new Class[] {
        TradePriceData.class
    }));
    service.setDataBinding(db);

    operation = endpointInfo.getBinding().getOperation(new QName(ns, "SayHi"));
    operation.getOperationInfo().getInput().getMessagePartByIndex(0).setTypeClass(TradePriceData.class);
    operation.getOperationInfo().getOutput()
        .getMessagePartByIndex(0).setTypeClass(TradePriceData.class);

    message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);

    exchange.put(Service.class, service);
    exchange.put(Endpoint.class, endpoint);
    exchange.put(Binding.class, endpoint.getBinding());
}
 
Example 16
Source File: BareInInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void setUpUsingHelloWorld() throws Exception {
    String ns = "http://apache.org/hello_world_soap_http";
    WSDLServiceFactory factory = new WSDLServiceFactory(bus, getClass()
        .getResource("/wsdl/jaxb/hello_world.wsdl").toString(),
                                                        new QName(ns, "SOAPService"));

    service = factory.create();
    endpointInfo = service.getServiceInfos().get(0).getEndpoint(new QName(ns, "SoapPort"));
    endpoint = new EndpointImpl(bus, service, endpointInfo);
    JAXBDataBinding db = new JAXBDataBinding();
    db.setContext(JAXBContext.newInstance(new Class[] {
        GreetMe.class,
        GreetMeResponse.class
    }));
    service.setDataBinding(db);

    operation = endpointInfo.getBinding().getOperation(new QName(ns, "greetMe"));
    operation.getOperationInfo().getInput().getMessagePartByIndex(0).setTypeClass(GreetMe.class);
    operation.getOperationInfo().getOutput()
        .getMessagePartByIndex(0).setTypeClass(GreetMeResponse.class);

    message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);

    exchange.put(Service.class, service);
    exchange.put(Endpoint.class, endpoint);
    exchange.put(Binding.class, endpoint.getBinding());
}
 
Example 17
Source File: LocalTransportFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void testInvocation(boolean isDirectDispatch) throws Exception {
    // Need to create a DefaultBus
    Bus bus = BusFactory.getDefaultBus();
    LocalTransportFactory factory = new LocalTransportFactory();

    EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
    ei.setAddress("http://localhost/test");

    LocalDestination d = (LocalDestination) factory.getDestination(ei, bus);
    d.setMessageObserver(new EchoObserver());

    // Set up a listener for the response
    Conduit conduit = factory.getConduit(ei, bus);
    TestMessageObserver obs = new TestMessageObserver();
    conduit.setMessageObserver(obs);

    MessageImpl m = new MessageImpl();
    if (isDirectDispatch) {
        m.put(LocalConduit.DIRECT_DISPATCH, Boolean.TRUE);
    }
    m.setDestination(d);
    Exchange ex = new ExchangeImpl();
    ex.put(Bus.class, bus);
    m.setExchange(ex);
    conduit.prepare(m);

    OutputStream out = m.getContent(OutputStream.class);

    StringBuilder builder = new StringBuilder();
    for (int x = 0; x < 1000; x++) {
        builder.append("hello");
    }
    out.write(builder.toString().getBytes());
    out.close();
    conduit.close(m);

    assertEquals(builder.toString(), obs.getResponseStream().toString());
}
 
Example 18
Source File: MtomServerTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testMtomRequest() throws Exception {
    JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
    sf.setServiceBean(new EchoService());
    sf.setBus(getStaticBus());
    String address = "http://localhost:" + PORT1 + "/EchoService";
    sf.setAddress(address);
    Map<String, Object> props = new HashMap<>();
    props.put(Message.MTOM_ENABLED, "true");
    sf.setProperties(props);
    sf.create();

    EndpointInfo ei = new EndpointInfo(null, HTTP_ID);
    ei.setAddress(address);

    ConduitInitiatorManager conduitMgr = getStaticBus().getExtension(ConduitInitiatorManager.class);
    ConduitInitiator conduitInit = conduitMgr.getConduitInitiator("http://schemas.xmlsoap.org/soap/http");
    Conduit conduit = conduitInit.getConduit(ei, getStaticBus());

    TestUtilities.TestMessageObserver obs = new TestUtilities.TestMessageObserver();
    conduit.setMessageObserver(obs);

    Message m = new MessageImpl();
    String ct = "multipart/related; type=\"application/xop+xml\"; "
                + "start=\"<[email protected]>\"; "
                + "start-info=\"text/xml\"; "
                + "boundary=\"----=_Part_4_701508.1145579811786\"";

    m.put(Message.CONTENT_TYPE, ct);
    conduit.prepare(m);

    OutputStream os = m.getContent(OutputStream.class);
    InputStream is = testUtilities.getResourceAsStream("request");
    if (is == null) {
        throw new RuntimeException("Could not find resource " + "request");
    }

    IOUtils.copy(is, os);

    os.flush();
    is.close();
    os.close();

    byte[] res = obs.getResponseStream().toByteArray();
    MessageImpl resMsg = new MessageImpl();
    resMsg.setContent(InputStream.class, new ByteArrayInputStream(res));
    resMsg.put(Message.CONTENT_TYPE, obs.getResponseContentType());
    resMsg.setExchange(new ExchangeImpl());
    AttachmentDeserializer deserializer = new AttachmentDeserializer(resMsg);
    deserializer.initializeAttachments();

    Collection<Attachment> attachments = resMsg.getAttachments();
    assertNotNull(attachments);
    assertEquals(1, attachments.size());

    Attachment inAtt = attachments.iterator().next();
    try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        IOUtils.copy(inAtt.getDataHandler().getInputStream(), out);
        assertEquals(27364, out.size());
    }
}
 
Example 19
Source File: TestBase.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
    bus = BusFactory.newInstance().createBus();

    BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class);

    IMocksControl control = createNiceControl();
    BindingFactory bf = control.createMock(BindingFactory.class);
    Binding binding = control.createMock(Binding.class);
    expect(bf.createBinding(null)).andStubReturn(binding);
    expect(binding.getInFaultInterceptors())
        .andStubReturn(new ArrayList<Interceptor<? extends Message>>());
    expect(binding.getOutFaultInterceptors())
        .andStubReturn(new ArrayList<Interceptor<? extends Message>>());

    bfm.registerBindingFactory("http://schemas.xmlsoap.org/wsdl/soap/", bf);

    String ns = "http://apache.org/hello_world_soap_http";
    WSDLServiceFactory factory = new WSDLServiceFactory(bus, getClass()
        .getResource("/org/apache/cxf/jaxb/resources/wsdl/hello_world.wsdl").toString(),
                                                        new QName(ns, "SOAPService"));

    service = factory.create();
    endpointInfo = service.getEndpointInfo(new QName(ns, "SoapPort"));
    endpoint = new EndpointImpl(bus, service, endpointInfo);
    JAXBDataBinding db = new JAXBDataBinding();
    db.setContext(JAXBContext.newInstance(new Class[] {
        GreetMe.class,
        GreetMeResponse.class
    }));
    service.setDataBinding(db);

    operation = endpointInfo.getBinding().getOperation(new QName(ns, "greetMe"));
    operation.getOperationInfo().getInput().getMessagePartByIndex(0).setTypeClass(GreetMe.class);
    operation.getOperationInfo().getOutput()
        .getMessagePartByIndex(0).setTypeClass(GreetMeResponse.class);

    message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);

    exchange.put(Service.class, service);
    exchange.put(Endpoint.class, endpoint);
    exchange.put(Binding.class, endpoint.getBinding());
}
 
Example 20
Source File: MtomPolicyTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void sendMtomMessage(String a) throws Exception {
    EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/wsdl/http");
    ei.setAddress(a);

    ConduitInitiatorManager conduitMgr = getStaticBus().getExtension(ConduitInitiatorManager.class);
    ConduitInitiator conduitInit = conduitMgr.getConduitInitiator("http://schemas.xmlsoap.org/soap/http");
    Conduit conduit = conduitInit.getConduit(ei, getStaticBus());

    TestUtilities.TestMessageObserver obs = new TestUtilities.TestMessageObserver();
    conduit.setMessageObserver(obs);

    Message m = new MessageImpl();
    String ct = "multipart/related; type=\"application/xop+xml\"; "
                + "start=\"<[email protected]>\"; "
                + "start-info=\"text/xml; charset=utf-8\"; "
                + "boundary=\"----=_Part_4_701508.1145579811786\"";

    m.put(Message.CONTENT_TYPE, ct);
    conduit.prepare(m);

    OutputStream os = m.getContent(OutputStream.class);
    InputStream is = testUtilities.getResourceAsStream("request");
    if (is == null) {
        throw new RuntimeException("Could not find resource " + "request");
    }

    IOUtils.copy(is, os);

    os.flush();
    is.close();
    os.close();

    byte[] res = obs.getResponseStream().toByteArray();
    MessageImpl resMsg = new MessageImpl();
    resMsg.setContent(InputStream.class, new ByteArrayInputStream(res));
    resMsg.put(Message.CONTENT_TYPE, obs.getResponseContentType());
    resMsg.setExchange(new ExchangeImpl());
    AttachmentDeserializer deserializer = new AttachmentDeserializer(resMsg);
    deserializer.initializeAttachments();

    Collection<Attachment> attachments = resMsg.getAttachments();
    assertNotNull(attachments);
    assertEquals(1, attachments.size());

    Attachment inAtt = attachments.iterator().next();
    try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        IOUtils.copy(inAtt.getDataHandler().getInputStream(), out);
        assertEquals(27364, out.size());
    }
}