Search in sources :

Example 36 with Conduit

use of org.apache.cxf.transport.Conduit in project cxf by apache.

the class RMManagerTest method testRecoverReliableClientEndpointWithAttachment.

@Test
public void testRecoverReliableClientEndpointWithAttachment() throws NoSuchMethodException, IOException {
    Method method = RMManager.class.getDeclaredMethod("createReliableEndpoint", new Class[] { Endpoint.class });
    manager = control.createMock(RMManager.class, new Method[] { method });
    manager.setReliableEndpointsMap(new HashMap<Endpoint, RMEndpoint>());
    Endpoint endpoint = control.createMock(Endpoint.class);
    EndpointInfo ei = control.createMock(EndpointInfo.class);
    ServiceInfo si = control.createMock(ServiceInfo.class);
    BindingInfo bi = control.createMock(BindingInfo.class);
    InterfaceInfo ii = control.createMock(InterfaceInfo.class);
    setUpEndpointForRecovery(endpoint, ei, si, bi, ii);
    Conduit conduit = control.createMock(Conduit.class);
    SourceSequence ss = control.createMock(SourceSequence.class);
    DestinationSequence ds = control.createMock(DestinationSequence.class);
    RMMessage m1 = new RMMessage();
    InputStream fis = getClass().getResourceAsStream("persistence/SerializedRMMessage.txt");
    CachedOutputStream cos = new CachedOutputStream();
    IOUtils.copyAndCloseInput(fis, cos);
    cos.flush();
    m1.setContent(cos);
    m1.setTo("toAddress");
    m1.setMessageNumber(new Long(10));
    m1.setContentType(MULTIPART_TYPE);
    Capture<Message> mc = Capture.newInstance();
    setUpRecoverReliableEndpointWithAttachment(endpoint, conduit, ss, ds, m1, mc);
    control.replay();
    manager.recoverReliableEndpoint(endpoint, conduit);
    control.verify();
    Message msg = mc.getValue();
    assertNotNull(msg);
    assertNotNull(msg.getExchange());
    assertSame(msg, msg.getExchange().getOutMessage());
    CachedOutputStream cos1 = (CachedOutputStream) msg.get(RMMessageConstants.SAVED_CONTENT);
    assertStartsWith(cos1.getInputStream(), "<soap:Envelope");
    assertEquals(1, msg.getAttachments().size());
}
Also used : Message(org.apache.cxf.message.Message) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Method(java.lang.reflect.Method) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) Conduit(org.apache.cxf.transport.Conduit) BindingInfo(org.apache.cxf.service.model.BindingInfo) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) Test(org.junit.Test)

Example 37 with Conduit

use of org.apache.cxf.transport.Conduit in project cxf by apache.

the class RMManagerTest method testGetReliableEndpointClientSideCreate.

@Test
public void testGetReliableEndpointClientSideCreate() throws NoSuchMethodException, RMException {
    Method m1 = RMManager.class.getDeclaredMethod("createReliableEndpoint", new Class[] { Endpoint.class });
    manager = control.createMock(RMManager.class, new Method[] { m1 });
    manager.setReliableEndpointsMap(new HashMap<Endpoint, RMEndpoint>());
    Message message = control.createMock(Message.class);
    Exchange exchange = control.createMock(Exchange.class);
    EasyMock.expect(message.getExchange()).andReturn(exchange).anyTimes();
    Endpoint endpoint = control.createMock(Endpoint.class);
    EasyMock.expect(exchange.getEndpoint()).andReturn(endpoint);
    EndpointInfo ei = control.createMock(EndpointInfo.class);
    EasyMock.expect(endpoint.getEndpointInfo()).andReturn(ei);
    QName name = new QName("http://x.y.z/a", "GreeterPort");
    EasyMock.expect(ei.getName()).andReturn(name);
    RMEndpoint rme = control.createMock(RMEndpoint.class);
    EasyMock.expect(manager.createReliableEndpoint(endpoint)).andReturn(rme);
    EasyMock.expect(exchange.getDestination()).andReturn(null);
    Conduit conduit = control.createMock(Conduit.class);
    EasyMock.expect(exchange.getConduit(message)).andReturn(conduit);
    rme.initialise(manager.getConfiguration(), conduit, null, null, message);
    EasyMock.expectLastCall();
    control.replay();
    assertSame(rme, manager.getReliableEndpoint(message));
    control.verify();
    control.reset();
    EasyMock.expect(message.getExchange()).andReturn(exchange);
    EasyMock.expect(exchange.getEndpoint()).andReturn(endpoint);
    EasyMock.expect(endpoint.getEndpointInfo()).andReturn(ei);
    EasyMock.expect(ei.getName()).andReturn(name);
    control.replay();
    assertSame(rme, manager.getReliableEndpoint(message));
    control.verify();
}
Also used : Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) Message(org.apache.cxf.message.Message) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) QName(javax.xml.namespace.QName) Conduit(org.apache.cxf.transport.Conduit) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 38 with Conduit

use of org.apache.cxf.transport.Conduit in project cxf by apache.

the class RMManagerTest method testRecoverReliableClientEndpoint.

@Test
public void testRecoverReliableClientEndpoint() throws NoSuchMethodException, IOException {
    Method method = RMManager.class.getDeclaredMethod("createReliableEndpoint", new Class[] { Endpoint.class });
    manager = control.createMock(RMManager.class, new Method[] { method });
    manager.setReliableEndpointsMap(new HashMap<Endpoint, RMEndpoint>());
    Endpoint endpoint = control.createMock(Endpoint.class);
    EndpointInfo ei = control.createMock(EndpointInfo.class);
    ServiceInfo si = control.createMock(ServiceInfo.class);
    BindingInfo bi = control.createMock(BindingInfo.class);
    InterfaceInfo ii = control.createMock(InterfaceInfo.class);
    setUpEndpointForRecovery(endpoint, ei, si, bi, ii);
    Conduit conduit = control.createMock(Conduit.class);
    setUpRecoverReliableEndpoint(endpoint, conduit, null, null, null);
    control.replay();
    manager.recoverReliableEndpoint(endpoint, conduit);
    control.verify();
    control.reset();
    setUpEndpointForRecovery(endpoint, ei, si, bi, ii);
    SourceSequence ss = control.createMock(SourceSequence.class);
    DestinationSequence ds = control.createMock(DestinationSequence.class);
    setUpRecoverReliableEndpoint(endpoint, conduit, ss, ds, null);
    control.replay();
    manager.recoverReliableEndpoint(endpoint, conduit);
    control.verify();
    control.reset();
    setUpEndpointForRecovery(endpoint, ei, si, bi, ii);
    RMMessage m = control.createMock(RMMessage.class);
    setUpRecoverReliableEndpoint(endpoint, conduit, ss, ds, m);
    control.replay();
    manager.recoverReliableEndpoint(endpoint, conduit);
    control.verify();
}
Also used : RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) Method(java.lang.reflect.Method) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) Conduit(org.apache.cxf.transport.Conduit) BindingInfo(org.apache.cxf.service.model.BindingInfo) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) Test(org.junit.Test)

Example 39 with Conduit

use of org.apache.cxf.transport.Conduit in project cxf by apache.

the class MtomPolicyTest method sendMtomMessage.

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=\"<soap.xml@xfire.codehaus.org>\"; " + "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());
    }
}
Also used : Message(org.apache.cxf.message.Message) AttachmentDeserializer(org.apache.cxf.attachment.AttachmentDeserializer) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) TestUtilities(org.apache.cxf.test.TestUtilities) Attachment(org.apache.cxf.message.Attachment) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) ByteArrayInputStream(java.io.ByteArrayInputStream) Conduit(org.apache.cxf.transport.Conduit) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 40 with Conduit

use of org.apache.cxf.transport.Conduit in project cxf by apache.

the class MtomServerTest method testURLBasedAttachment.

@Test
public void testURLBasedAttachment() throws Exception {
    JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
    sf.setServiceBean(new EchoService());
    sf.setBus(getStaticBus());
    String address = "http://localhost:" + PORT2 + "/EchoService";
    sf.setAddress(address);
    Map<String, Object> props = new HashMap<>();
    props.put(Message.MTOM_ENABLED, "true");
    sf.setProperties(props);
    Server server = sf.create();
    server.getEndpoint().getService().getDataBinding().setMtomThreshold(0);
    servStatic(getClass().getResource("mtom-policy.xml"), "http://localhost:" + PORT2 + "/policy.xsd");
    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=\"<soap.xml@xfire.codehaus.org>\"; " + "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-url-attachment");
    if (is == null) {
        throw new RuntimeException("Could not find resource " + "request");
    }
    try (ByteArrayOutputStream bout = new ByteArrayOutputStream()) {
        IOUtils.copy(is, bout);
        String s = bout.toString(StandardCharsets.UTF_8.name());
        s = s.replaceAll(":9036/", ":" + PORT2 + "/");
        os.write(s.getBytes(StandardCharsets.UTF_8));
    }
    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);
        assertTrue("Wrong size: " + out.size() + "\n" + out.toString(), out.size() > 970 && out.size() < 1020);
    }
    unregisterServStatic("http://localhost:" + PORT2 + "/policy.xsd");
}
Also used : Server(org.apache.cxf.endpoint.Server) Message(org.apache.cxf.message.Message) AttachmentDeserializer(org.apache.cxf.attachment.AttachmentDeserializer) HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Attachment(org.apache.cxf.message.Attachment) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TestUtilities(org.apache.cxf.test.TestUtilities) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Conduit(org.apache.cxf.transport.Conduit) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Aggregations

Conduit (org.apache.cxf.transport.Conduit)83 Test (org.junit.Test)36 Message (org.apache.cxf.message.Message)35 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)30 Exchange (org.apache.cxf.message.Exchange)28 IOException (java.io.IOException)18 MessageImpl (org.apache.cxf.message.MessageImpl)17 Endpoint (org.apache.cxf.endpoint.Endpoint)16 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)13 MessageObserver (org.apache.cxf.transport.MessageObserver)12 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)12 OutputStream (java.io.OutputStream)11 Bus (org.apache.cxf.Bus)11 Destination (org.apache.cxf.transport.Destination)11 ConduitInitiator (org.apache.cxf.transport.ConduitInitiator)10 InputStream (java.io.InputStream)9 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)9 ConduitInitiatorManager (org.apache.cxf.transport.ConduitInitiatorManager)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6