Search in sources :

Example 21 with ConduitInitiator

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

the class STSUtils method createSTSEndpoint.

// CHECKSTYLE:OFF
private static Endpoint createSTSEndpoint(Bus bus, String namespace, String transportId, String location, String soapVersion, Policy policy, QName epName, boolean sc) throws BusException, EndpointException {
    // CHECKSTYLE:ON
    String ns = namespace + "/wsdl";
    ServiceInfo si = new ServiceInfo();
    QName iName = new QName(ns, sc ? "SecureConversationTokenService" : "SecurityTokenService");
    si.setName(iName);
    InterfaceInfo ii = new InterfaceInfo(si, iName);
    OperationInfo ioi = addIssueOperation(ii, namespace, ns);
    OperationInfo coi = addCancelOperation(ii, namespace, ns);
    OperationInfo roi = addRenewOperation(ii, namespace, ns);
    si.setInterface(ii);
    Service service = new ServiceImpl(si);
    BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class);
    BindingFactory bindingFactory = bfm.getBindingFactory(soapVersion);
    BindingInfo bi = bindingFactory.createBindingInfo(service, soapVersion, null);
    si.addBinding(bi);
    if (transportId == null) {
        ConduitInitiatorManager cim = bus.getExtension(ConduitInitiatorManager.class);
        ConduitInitiator ci = cim.getConduitInitiatorForUri(location);
        transportId = ci.getTransportIds().get(0);
    }
    EndpointInfo ei = new EndpointInfo(si, transportId);
    ei.setBinding(bi);
    ei.setName(epName == null ? iName : epName);
    ei.setAddress(location);
    si.addEndpoint(ei);
    if (policy != null) {
        ei.addExtensor(policy);
    }
    BindingOperationInfo boi = bi.getOperation(ioi);
    SoapOperationInfo soi = boi.getExtensor(SoapOperationInfo.class);
    if (soi == null) {
        soi = new SoapOperationInfo();
        boi.addExtensor(soi);
    }
    soi.setAction(namespace + (sc ? "/RST/SCT" : "/RST/Issue"));
    boi = bi.getOperation(coi);
    soi = boi.getExtensor(SoapOperationInfo.class);
    if (soi == null) {
        soi = new SoapOperationInfo();
        boi.addExtensor(soi);
    }
    soi.setAction(namespace + (sc ? "/RST/SCT/Cancel" : "/RST/Cancel"));
    boi = bi.getOperation(roi);
    soi = boi.getExtensor(SoapOperationInfo.class);
    if (soi == null) {
        soi = new SoapOperationInfo();
        boi.addExtensor(soi);
    }
    soi.setAction(namespace + (sc ? "/RST/SCT/Renew" : "/RST/Renew"));
    service.setDataBinding(new SourceDataBinding());
    return new EndpointImpl(bus, service, ei);
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) QName(javax.xml.namespace.QName) ServiceImpl(org.apache.cxf.service.ServiceImpl) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) Service(org.apache.cxf.service.Service) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) BindingFactory(org.apache.cxf.binding.BindingFactory)

Example 22 with ConduitInitiator

use of org.apache.cxf.transport.ConduitInitiator 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 23 with ConduitInitiator

use of org.apache.cxf.transport.ConduitInitiator in project camel by apache.

the class CamelDestinationTest method setupCamelDestination.

public CamelDestination setupCamelDestination(EndpointInfo endpointInfo, boolean send) throws IOException {
    ConduitInitiator conduitInitiator = EasyMock.createMock(ConduitInitiator.class);
    CamelDestination camelDestination = new CamelDestination(context, bus, conduitInitiator, endpointInfo);
    if (send) {
        // setMessageObserver
        observer = new MessageObserver() {

            public void onMessage(Message m) {
                Exchange exchange = new ExchangeImpl();
                exchange.setInMessage(m);
                m.setExchange(exchange);
                destMessage = m;
            }
        };
        camelDestination.setMessageObserver(observer);
    }
    return camelDestination;
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.cxf.message.Exchange) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 24 with ConduitInitiator

use of org.apache.cxf.transport.ConduitInitiator 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

ConduitInitiator (org.apache.cxf.transport.ConduitInitiator)24 ConduitInitiatorManager (org.apache.cxf.transport.ConduitInitiatorManager)21 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)18 Message (org.apache.cxf.message.Message)12 Conduit (org.apache.cxf.transport.Conduit)11 Bus (org.apache.cxf.Bus)8 IOException (java.io.IOException)7 QName (javax.xml.namespace.QName)7 MessageImpl (org.apache.cxf.message.MessageImpl)7 OutputStream (java.io.OutputStream)6 Exchange (org.apache.cxf.message.Exchange)6 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)6 MessageObserver (org.apache.cxf.transport.MessageObserver)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 InputStream (java.io.InputStream)5 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Destination (org.apache.cxf.transport.Destination)4 DestinationFactory (org.apache.cxf.transport.DestinationFactory)4 DestinationFactoryManager (org.apache.cxf.transport.DestinationFactoryManager)4