Search in sources :

Example 96 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl 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)

Example 97 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.

the class ClientConfiguration method getConduit.

/**
 * Gets the conduit responsible for a transport-level
 * communication with the remote service.
 * @return the conduit
 */
public Conduit getConduit() {
    Message message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    exchange.put(MessageObserver.class, new ClientMessageObserver(this));
    if (conduitSelector != null) {
        exchange.put(Endpoint.class, conduitSelector.getEndpoint());
    }
    exchange.put(Bus.class, bus);
    prepareConduitSelector(message);
    return getConduitSelector().selectConduit(message);
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 98 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.

the class MAPCodecTest method getMAPs.

private AddressingProperties getMAPs(boolean requestor, boolean outbound, String uri) {
    AddressingProperties maps = new AddressingProperties();
    boolean exposeAsNative = Names.WSA_NAMESPACE_NAME.equals(uri);
    boolean exposeAs200408 = Names200408.WSA_NAMESPACE_NAME.equals(uri);
    boolean exposeAs200403 = Names200403.WSA_NAMESPACE_NAME.equals(uri);
    AttributedURIType id = ContextUtils.getAttributedURI("urn:uuid:12345");
    maps.setMessageID(id);
    AttributedURIType to = ContextUtils.getAttributedURI("foobar");
    EndpointReferenceType toEpr = EndpointReferenceUtils.getEndpointReference(to);
    maps.setTo(toEpr);
    EndpointReferenceType replyTo = new EndpointReferenceType();
    String anonymous = exposeAsNative ? Names.WSA_ANONYMOUS_ADDRESS : exposeAs200408 ? Names200408.WSA_ANONYMOUS_ADDRESS : Names200403.WSA_ANONYMOUS_ADDRESS;
    replyTo.setAddress(ContextUtils.getAttributedURI(anonymous));
    maps.setReplyTo(replyTo);
    EndpointReferenceType from = EndpointReferenceUtils.getEndpointReference("snafu");
    maps.setFrom(from);
    EndpointReferenceType faultTo = new EndpointReferenceType();
    anonymous = exposeAsNative ? Names.WSA_ANONYMOUS_ADDRESS : exposeAs200408 ? Names200408.WSA_ANONYMOUS_ADDRESS : Names200403.WSA_ANONYMOUS_ADDRESS;
    faultTo.setAddress(ContextUtils.getAttributedURI(anonymous));
    maps.setFaultTo(faultTo);
    RelatesToType relatesTo = null;
    if (expectRelatesTo) {
        String correlationID = "urn:uuid:67890";
        relatesTo = new RelatesToType();
        relatesTo.setValue(correlationID);
        maps.setRelatesTo(relatesTo);
        if (nonReplyRelationship == null) {
            correlatedExchange = new ExchangeImpl();
            codec.uncorrelatedExchanges.put(correlationID, correlatedExchange);
        } else {
            relatesTo.setRelationshipType(nonReplyRelationship);
        }
    }
    AttributedURIType action = ContextUtils.getAttributedURI("http://foo/bar/SEI/opRequest");
    maps.setAction(action);
    maps.exposeAs(uri);
    expectedNamespaceURI = uri;
    expectedNames = new QName[] { new QName(uri, Names.WSA_ACTION_NAME), new QName(uri, Names.WSA_MESSAGEID_NAME), new QName(uri, Names.WSA_TO_NAME), new QName(uri, Names.WSA_REPLYTO_NAME), new QName(uri, Names.WSA_RELATESTO_NAME), new QName(uri, Names.WSA_FROM_NAME), new QName(uri, Names.WSA_FAULTTO_NAME) };
    if (exposeAsNative) {
        expectedValues = new Object[] { action, id, to, replyTo, relatesTo, from, faultTo };
    } else if (exposeAs200408) {
        expectedValues = new Object[] { org.apache.cxf.ws.addressing.VersionTransformer.convert(action), org.apache.cxf.ws.addressing.VersionTransformer.convert(id), org.apache.cxf.ws.addressing.VersionTransformer.convert(to), org.apache.cxf.ws.addressing.VersionTransformer.convert(replyTo), org.apache.cxf.ws.addressing.VersionTransformer.convert(relatesTo), org.apache.cxf.ws.addressing.VersionTransformer.convert(from), org.apache.cxf.ws.addressing.VersionTransformer.convert(faultTo) };
        if (!outbound) {
            // conversion from 2004/08 to 2005/08 anonymous address
            // occurs transparently in VersionTransformer
            Names200408.EPR_TYPE.cast(expectedValues[3]).getAddress().setValue(Names.WSA_ANONYMOUS_ADDRESS);
            Names200408.EPR_TYPE.cast(expectedValues[5]).getAddress().setValue(Names.WSA_ANONYMOUS_ADDRESS);
        }
    } else if (exposeAs200403) {
        expectedValues = new Object[] { org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(action), org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(id), org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(to), org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(replyTo), org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(relatesTo), org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(from), org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(faultTo) };
        if (!outbound) {
            // conversion from 2004/03 to 2005/08 anonymous address
            // occurs transparently in VersionTransformer
            Names200403.EPR_TYPE.cast(expectedValues[3]).getAddress().setValue(Names.WSA_ANONYMOUS_ADDRESS);
            Names200403.EPR_TYPE.cast(expectedValues[5]).getAddress().setValue(Names.WSA_ANONYMOUS_ADDRESS);
        }
    } else {
        fail("unexpected namespace URI: " + uri);
    }
    return maps;
}
Also used : RelatesToType(org.apache.cxf.ws.addressing.RelatesToType) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) QName(javax.xml.namespace.QName) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 99 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.

the class MAPCodecTest method setUpOutbound.

private void setUpOutbound(Message message, boolean outbound) {
    Exchange exchange = new ExchangeImpl();
    exchange.setOutMessage(outbound ? message : new MessageImpl());
    message.setExchange(exchange);
}
Also used : Exchange(org.apache.cxf.message.Exchange) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 100 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.

the class ServantTest method createTestCloseSequenceMessage.

private static Message createTestCloseSequenceMessage(String sidstr) {
    Message message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    exchange.setInMessage(message);
    message.put(Message.REQUESTOR_ROLE, Boolean.FALSE);
    AddressingProperties maps = new AddressingProperties();
    String msgId = "urn:uuid:12345-" + Math.random();
    AttributedURIType id = ContextUtils.getAttributedURI(msgId);
    maps.setMessageID(id);
    maps.setAction(ContextUtils.getAttributedURI(RM10Constants.INSTANCE.getTerminateSequenceAction()));
    maps.setTo(ContextUtils.getAttributedURI(SERVICE_URL));
    maps.setReplyTo(RMUtils.createReference(DECOUPLED_URL));
    message.put(JAXWSAConstants.ADDRESSING_PROPERTIES_INBOUND, maps);
    CloseSequenceType cs = new CloseSequenceType();
    org.apache.cxf.ws.rm.v200702.Identifier sid = new org.apache.cxf.ws.rm.v200702.Identifier();
    sid.setValue(sidstr);
    cs.setIdentifier(sid);
    MessageContentsList contents = new MessageContentsList();
    contents.add(cs);
    message.setContent(List.class, contents);
    RMContextUtils.setProtocolVariation(message, ProtocolVariation.RM11WSA200508);
    return message;
}
Also used : Message(org.apache.cxf.message.Message) MessageContentsList(org.apache.cxf.message.MessageContentsList) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) Exchange(org.apache.cxf.message.Exchange) Identifier(org.apache.cxf.ws.rm.v200502.Identifier) CloseSequenceType(org.apache.cxf.ws.rm.v200702.CloseSequenceType) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Aggregations

ExchangeImpl (org.apache.cxf.message.ExchangeImpl)227 MessageImpl (org.apache.cxf.message.MessageImpl)189 Message (org.apache.cxf.message.Message)166 Exchange (org.apache.cxf.message.Exchange)159 Test (org.junit.Test)107 Endpoint (org.apache.cxf.endpoint.Endpoint)42 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)30 ByteArrayInputStream (java.io.ByteArrayInputStream)28 QName (javax.xml.namespace.QName)23 Bus (org.apache.cxf.Bus)23 HashMap (java.util.HashMap)22 List (java.util.List)22 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)20 SOAPMessage (javax.xml.soap.SOAPMessage)16 LogEvent (org.apache.cxf.ext.logging.event.LogEvent)16 ArrayList (java.util.ArrayList)15 IOException (java.io.IOException)14 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)14 Conduit (org.apache.cxf.transport.Conduit)14