Search in sources :

Example 86 with Conduit

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

the class MAPAggregatorTest method setUpConduit.

private void setUpConduit(Message message, Exchange exchange) {
    setUpMessageExchange(message, exchange);
    Conduit conduit = EasyMock.createMock(Conduit.class);
    setUpExchangeConduit(message, exchange, conduit);
    EndpointReferenceType to = ContextUtils.WSA_OBJECT_FACTORY.createEndpointReferenceType();
    to.setAddress(ContextUtils.getAttributedURI(expectedTo));
    conduit.getTarget();
    EasyMock.expectLastCall().andReturn(to).anyTimes();
}
Also used : EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) Conduit(org.apache.cxf.transport.Conduit)

Example 87 with Conduit

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

the class SimpleBatchSTSClient method findOperation.

protected BindingOperationInfo findOperation(String suffix) {
    BindingInfo bi = client.getEndpoint().getBinding().getBindingInfo();
    for (BindingOperationInfo boi : bi.getOperations()) {
        SoapOperationInfo soi = boi.getExtensor(SoapOperationInfo.class);
        if (soi != null && soi.getAction() != null && soi.getAction().endsWith(suffix)) {
            PolicyEngine pe = bus.getExtension(PolicyEngine.class);
            Conduit conduit = client.getConduit();
            EffectivePolicy effectivePolicy = pe.getEffectiveClientRequestPolicy(client.getEndpoint().getEndpointInfo(), boi, conduit, PhaseInterceptorChain.getCurrentMessage());
            setPolicyInternal(effectivePolicy.getPolicy());
            return boi;
        }
    }
    // we can at least find it by name and then set the action and such manually later.
    for (BindingOperationInfo boi : bi.getOperations()) {
        if (boi.getInput().getMessageInfo().getMessageParts().size() > 0) {
            MessagePartInfo mpi = boi.getInput().getMessageInfo().getMessagePart(0);
            if ("RequestSecurityToken".equals(mpi.getConcreteName().getLocalPart())) {
                return boi;
            }
        }
    }
    return null;
}
Also used : EffectivePolicy(org.apache.cxf.ws.policy.EffectivePolicy) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Conduit(org.apache.cxf.transport.Conduit) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 88 with Conduit

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

the class MtomServerTest method testMtomRequest.

@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=\"<soap.xml@xfire.codehaus.org>\"; " + "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());
    }
}
Also used : 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 89 with Conduit

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

the class MtomServerTest method servStatic.

/**
 * Serve static file
 */
private void servStatic(final URL resource, final String add) throws Exception {
    Bus bus = getStaticBus();
    DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
    DestinationFactory df = dfm.getDestinationFactory("http://cxf.apache.org/transports/http/configuration");
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress(add);
    Destination d = df.getDestination(ei, bus);
    d.setMessageObserver(new MessageObserver() {

        public void onMessage(Message message) {
            try {
                // HTTP seems to need this right now...
                ExchangeImpl ex = new ExchangeImpl();
                ex.setInMessage(message);
                Conduit backChannel = message.getDestination().getBackChannel(message);
                MessageImpl res = new MessageImpl();
                ex.setOutMessage(res);
                res.put(Message.CONTENT_TYPE, "text/xml");
                backChannel.prepare(res);
                OutputStream out = res.getContent(OutputStream.class);
                InputStream is = resource.openStream();
                IOUtils.copy(is, out, 2048);
                out.flush();
                out.close();
                is.close();
                backChannel.close(res);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : Bus(org.apache.cxf.Bus) DestinationFactory(org.apache.cxf.transport.DestinationFactory) Destination(org.apache.cxf.transport.Destination) MessageObserver(org.apache.cxf.transport.MessageObserver) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) Message(org.apache.cxf.message.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Conduit(org.apache.cxf.transport.Conduit) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 90 with Conduit

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

the class SOAPConnectionImpl method call.

@Override
public SOAPMessage call(SOAPMessage msgOut, Object addressObject) throws SOAPException {
    checkClosed();
    String address = getAddress(addressObject);
    ConduitInitiator ci = getConduitInitiator(address);
    // create a new Message and Exchange
    EndpointInfo info = new EndpointInfo();
    info.setAddress(address);
    Message outMessage = new MessageImpl();
    Exchange exch = new ExchangeImpl();
    outMessage.setExchange(exch);
    // JBWS-3945
    exch.put("org.apache.cxf.transport.process_fault_on_http_400", true);
    // sent SOAPMessage
    try {
        // TODO verify bus
        final Conduit c = ci.getConduit(info, BusFactory.getThreadDefaultBus(false));
        if (msgOut.saveRequired()) {
            msgOut.saveChanges();
        }
        Map<String, List<String>> outHeaders = new HashMap<String, List<String>>();
        for (Iterator<?> it = msgOut.getMimeHeaders().getAllHeaders(); it.hasNext(); ) {
            MimeHeader mimeHeader = (MimeHeader) it.next();
            if ("Content-Type".equals(mimeHeader.getName())) {
                outMessage.put(Message.CONTENT_TYPE, mimeHeader.getValue());
            }
            // disable the chunked encoding if requested
            if ("Transfer-Encoding".equals(mimeHeader.getName()) && "disabled".equals(mimeHeader.getValue()) && c instanceof HTTPConduit) {
                ((HTTPConduit) c).getClient().setAllowChunking(false);
                continue;
            }
            List<String> values = outHeaders.get(mimeHeader.getName());
            if (values == null) {
                values = new ArrayList<String>();
                outHeaders.put(mimeHeader.getName(), values);
            }
            values.add(mimeHeader.getValue());
        }
        outMessage.put(Message.HTTP_REQUEST_METHOD, "POST");
        outMessage.put(Message.PROTOCOL_HEADERS, outHeaders);
        c.prepare(outMessage);
        OutputStream outs = outMessage.getContent(OutputStream.class);
        msgOut.writeTo(outs);
        c.setMessageObserver(createMessageObserver(c));
        c.close(outMessage);
    } catch (Exception ex) {
        throw MESSAGES.soapMessageCouldNotBeSent(ex);
    }
    // read SOAPMessage
    return readSoapMessage(exch);
}
Also used : Message(org.apache.cxf.message.Message) SOAPMessage(javax.xml.soap.SOAPMessage) HashMap(java.util.HashMap) OutputStream(java.io.OutputStream) LoadingByteArrayOutputStream(org.apache.cxf.helpers.LoadingByteArrayOutputStream) SOAPException(javax.xml.soap.SOAPException) IOException(java.io.IOException) Exchange(org.apache.cxf.message.Exchange) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Conduit(org.apache.cxf.transport.Conduit) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) MimeHeader(javax.xml.soap.MimeHeader) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) ArrayList(java.util.ArrayList) List(java.util.List) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Aggregations

Conduit (org.apache.cxf.transport.Conduit)90 Message (org.apache.cxf.message.Message)39 Test (org.junit.Test)38 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)35 Exchange (org.apache.cxf.message.Exchange)32 MessageImpl (org.apache.cxf.message.MessageImpl)19 IOException (java.io.IOException)18 Endpoint (org.apache.cxf.endpoint.Endpoint)16 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)15 MessageObserver (org.apache.cxf.transport.MessageObserver)15 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)13 OutputStream (java.io.OutputStream)11 Bus (org.apache.cxf.Bus)11 ConduitInitiator (org.apache.cxf.transport.ConduitInitiator)11 Destination (org.apache.cxf.transport.Destination)11 InputStream (java.io.InputStream)9 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)9 ConduitInitiatorManager (org.apache.cxf.transport.ConduitInitiatorManager)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 Fault (org.apache.cxf.interceptor.Fault)7