org.apache.cxf.transport.ConduitInitiator Java Examples

The following examples show how to use org.apache.cxf.transport.ConduitInitiator. 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: ConduitInitiatorManagerImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the conduit initiator for the given namespace, constructing it
 * (and storing in the cache for future reference) if necessary, using its
 * list of factory classname to namespace mappings.
 *
 * @param namespace the namespace.
 */
public ConduitInitiator getConduitInitiator(String namespace) throws BusException {
    ConduitInitiator factory = conduitInitiators.get(namespace);
    if (factory == null && !failed.contains(namespace)) {
        factory = new TransportFinder<>(bus,
                conduitInitiators,
                loaded,
                ConduitInitiator.class)
            .findTransportForNamespace(namespace);
    }
    if (factory == null) {
        failed.add(namespace);
        throw new BusException(new Message("NO_CONDUIT_INITIATOR", BUNDLE, namespace));
    }
    return factory;
}
 
Example #2
Source File: TestUtilities.java    From cxf with Apache License 2.0 6 votes vote down vote up
public byte[] invokeBytes(String address, String transport, byte[] message) throws Exception {
    EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
    ei.setAddress(address);

    ConduitInitiatorManager conduitMgr = getBus().getExtension(ConduitInitiatorManager.class);
    ConduitInitiator conduitInit = conduitMgr.getConduitInitiator(transport);
    Conduit conduit = conduitInit.getConduit(ei, getBus());

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

    Message m = new MessageImpl();
    conduit.prepare(m);

    OutputStream os = m.getContent(OutputStream.class);
    os.write(message);

    // TODO: shouldn't have to do this. IO caching needs cleaning
    // up or possibly removal...
    os.flush();
    os.close();

    return obs.getResponseStream().toByteArray();
}
 
Example #3
Source File: TestUtilities.java    From cxf with Apache License 2.0 5 votes vote down vote up
public byte[] invokeBytes(String address, String transport, String message) throws Exception {
    EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
    ei.setAddress(address);

    ConduitInitiatorManager conduitMgr = getBus().getExtension(ConduitInitiatorManager.class);
    ConduitInitiator conduitInit = conduitMgr.getConduitInitiator(transport);
    Conduit conduit = conduitInit.getConduit(ei, getBus());

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

    Message m = new MessageImpl();
    conduit.prepare(m);

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

    IOUtils.copy(is, os);

    // TODO: shouldn't have to do this. IO caching needs cleaning
    // up or possibly removal...
    os.flush();
    is.close();
    os.close();

    return obs.getResponseStream().toByteArray();
}
 
Example #4
Source File: ServiceUtils.java    From fuchsia with Apache License 2.0 5 votes vote down vote up
public static String getTransportId(Bus bus, String address) {
    ConduitInitiatorManager conduitInitiatorMgr = bus
            .getExtension(ConduitInitiatorManager.class);
    ConduitInitiator conduitInitiator = null;

    if (conduitInitiatorMgr != null) {
        conduitInitiator = conduitInitiatorMgr
                .getConduitInitiatorForUri(address);
    }
    if (conduitInitiator != null) {
        return conduitInitiator.getTransportIds().get(0);
    } else {
        return null;
    }
}
 
Example #5
Source File: AbstractConduitSelector.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected Conduit createConduit(Message message, Exchange exchange, ConduitInitiator conduitInitiator)
    throws IOException {
    Conduit c;
    synchronized (endpoint) {
        if (!conduits.isEmpty()) {
            c = findCompatibleConduit(message);
            if (c != null) {
                return c;
            }
        }
        EndpointInfo ei = endpoint.getEndpointInfo();
        String add = (String)message.get(Message.ENDPOINT_ADDRESS);
        String basePath = (String)message.get(Message.BASE_PATH);
        if (StringUtils.isEmpty(add)
            || add.equals(ei.getAddress())) {
            c = conduitInitiator.getConduit(ei, exchange.getBus());
            replaceEndpointAddressPropertyIfNeeded(message, add, c);
        } else {
            EndpointReferenceType epr = new EndpointReferenceType();
            AttributedURIType ad = new AttributedURIType();
            ad.setValue(StringUtils.isEmpty(basePath) ? add : basePath);
            epr.setAddress(ad);
            c = conduitInitiator.getConduit(ei, epr, exchange.getBus());
        }
        MessageObserver observer =
            exchange.get(MessageObserver.class);
        if (observer != null) {
            c.setMessageObserver(observer);
        } else {
            getLogger().warning("MessageObserver not found");
        }
        conduits.add(c);
    }
    return c;
}
 
Example #6
Source File: AbstractConduitSelector.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Mechanics to actually get the Conduit from the ConduitInitiator
 * if necessary.
 *
 * @param message the current Message
 */
protected Conduit getSelectedConduit(Message message) {
    Conduit c = findCompatibleConduit(message);
    if (c == null) {
        Exchange exchange = message.getExchange();
        EndpointInfo ei = endpoint.getEndpointInfo();
        String transportID = ei.getTransportId();
        try {
            ConduitInitiatorManager conduitInitiatorMgr = exchange.getBus()
                .getExtension(ConduitInitiatorManager.class);
            if (conduitInitiatorMgr != null) {
                ConduitInitiator conduitInitiator =
                    conduitInitiatorMgr.getConduitInitiator(transportID);
                if (conduitInitiator != null) {
                    c = createConduit(message, exchange, conduitInitiator);
                } else {
                    getLogger().warning("ConduitInitiator not found: "
                                        + ei.getAddress());
                }
            } else {
                getLogger().warning("ConduitInitiatorManager not found");
            }
        } catch (BusException | IOException ex) {
            throw new Fault(ex);
        }
    }
    if (c != null && c.getTarget() != null && c.getTarget().getAddress() != null) {
        replaceEndpointAddressPropertyIfNeeded(message, c.getTarget().getAddress().getValue(), c);
    }
    //the search for the conduit could cause extra properties to be reset/loaded.
    message.resetContextCache();
    message.put(Conduit.class, c);
    return c;
}
 
Example #7
Source File: SoapTransportFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
public Conduit getConduit(EndpointInfo ei, EndpointReferenceType target, Bus bus) throws IOException {
    String address = target == null ? ei.getAddress() : target.getAddress().getValue();
    BindingInfo bi = ei.getBinding();
    String transId = ei.getTransportId();
    if (bi instanceof SoapBindingInfo) {
        transId = ((SoapBindingInfo)bi).getTransportURI();
        if (transId == null) {
            transId = ei.getTransportId();
        }
    }
    ConduitInitiator conduitInit;
    try {
        ConduitInitiatorManager mgr = bus.getExtension(ConduitInitiatorManager.class);
        if (StringUtils.isEmpty(address)
            || address.startsWith("http")
            || address.startsWith("jms")
            || address.startsWith("soap.udp")) {
            conduitInit = mgr.getConduitInitiator(mapTransportURI(transId, address));
        } else {
            conduitInit = mgr.getConduitInitiatorForUri(address);
        }
        if (conduitInit == null) {
            throw new RuntimeException(String.format(CANNOT_GET_CONDUIT_ERROR, address, transId));
        }
        return conduitInit.getConduit(ei, target, bus);
    } catch (BusException e) {
        throw new RuntimeException(String.format(CANNOT_GET_CONDUIT_ERROR, address, transId));
    }
}
 
Example #8
Source File: InternalContextUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public Conduit getBackChannel(Message inMessage) throws IOException {
    if (ContextUtils.isNoneAddress(reference)) {
        return null;
    }
    Bus bus = inMessage.getExchange().getBus();
    //this is a response targeting a decoupled endpoint.   Treat it as a oneway so
    //we don't wait for a response.
    inMessage.getExchange().setOneWay(true);
    ConduitInitiator conduitInitiator
        = bus.getExtension(ConduitInitiatorManager.class)
            .getConduitInitiatorForUri(reference.getAddress().getValue());
    if (conduitInitiator != null) {
        Conduit c = conduitInitiator.getConduit(ei, reference, bus);
        // ensure decoupled back channel input stream is closed
        c.setMessageObserver(new MessageObserver() {
            public void onMessage(Message m) {
                InputStream is = m.getContent(InputStream.class);
                if (is != null) {
                    try {
                        is.close();
                    } catch (Exception e) {
                        // ignore
                    }
                }
            }
        });
        return c;
    }
    return null;
}
 
Example #9
Source File: InternalContextUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public Conduit getBackChannel(Message inMessage) throws IOException {
    if (ContextUtils.isNoneAddress(reference)) {
        return null;
    }
    Bus bus = inMessage.getExchange().getBus();
    //this is a response targeting a decoupled endpoint.   Treat it as a oneway so
    //we don't wait for a response.
    inMessage.getExchange().setOneWay(true);
    ConduitInitiator conduitInitiator
        = bus.getExtension(ConduitInitiatorManager.class)
            .getConduitInitiatorForUri(reference.getAddress().getValue());
    if (conduitInitiator != null) {
        Conduit c = conduitInitiator.getConduit(ei, reference, bus);
        // ensure decoupled back channel input stream is closed
        c.setMessageObserver(new MessageObserver() {
            public void onMessage(Message m) {
                InputStream is = m.getContent(InputStream.class);
                if (is != null) {
                    try {
                        is.close();
                    } catch (Exception e) {
                        // ignore
                    }
                }
            }
        });
        return c;
    }
    return null;
}
 
Example #10
Source File: ClientFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected String detectTransportIdFromAddress(String ad) {
    ConduitInitiatorManager cim = getBus().getExtension(ConduitInitiatorManager.class);
    ConduitInitiator ci = cim.getConduitInitiatorForUri(getAddress());
    if (ci != null) {
        return ci.getTransportIds().get(0);
    }
    return null;
}
 
Example #11
Source File: AbstractWSDLBasedEndpointFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void modifyTransportIdPerAddress(EndpointInfo ei) {
    //get chance to set transportId according to the the publish address prefix
    //this is useful for local & camel transport
    if (transportId == null && getAddress() != null) {
        DestinationFactory df = getDestinationFactory();
        if (df == null) {
            DestinationFactoryManager dfm = getBus().getExtension(
                    DestinationFactoryManager.class);
            df = dfm.getDestinationFactoryForUri(getAddress());
        }

        if (df != null) {
            transportId = df.getTransportIds().get(0);
        } else {
            // check conduits (the address could be supported on
            // client only)
            ConduitInitiatorManager cim = getBus().getExtension(
                    ConduitInitiatorManager.class);
            ConduitInitiator ci = cim
                    .getConduitInitiatorForUri(getAddress());
            if (ci != null) {
                transportId = ci.getTransportIds().get(0);
            }
        }
    }
    if (transportId != null) {
        ei.setTransportId(transportId);
    }
}
 
Example #12
Source File: AbstractServiceFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected String detectTransportIdFromAddress(String ad) {
    ConduitInitiatorManager cim = getBus().getExtension(ConduitInitiatorManager.class);
    ConduitInitiator ci = cim.getConduitInitiatorForUri(getAddress());
    if (ci != null) {
        return ci.getTransportIds().get(0);
    }
    return null;
}
 
Example #13
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 #14
Source File: ContextUtils.java    From cxf with Apache License 2.0 4 votes vote down vote up
public static Destination createDecoupledDestination(Exchange exchange,
                                                     final EndpointReferenceType reference) {
    final EndpointInfo ei = exchange.getEndpoint().getEndpointInfo();
    return new Destination() {
        public EndpointReferenceType getAddress() {
            return reference;
        }
        public Conduit getBackChannel(Message inMessage) throws IOException {
            Bus bus = inMessage.getExchange().getBus();
            //this is a response targeting a decoupled endpoint.   Treat it as a oneway so
            //we don't wait for a response.
            inMessage.getExchange().setOneWay(true);
            ConduitInitiator conduitInitiator
                = bus.getExtension(ConduitInitiatorManager.class)
                    .getConduitInitiatorForUri(reference.getAddress().getValue());
            if (conduitInitiator != null) {
                Conduit c = conduitInitiator.getConduit(ei, reference, bus);
                //ensure decoupled back channel input stream is closed
                c.setMessageObserver(new MessageObserver() {
                    public void onMessage(Message m) {
                        InputStream is = m.getContent(InputStream.class);
                        if (is != null) {
                            try {
                                is.close();
                            } catch (Exception e) {
                                //ignore
                            }
                        }
                    }
                });
                return c;
            }
            return null;
        }
        public MessageObserver getMessageObserver() {
            return null;
        }
        public void shutdown() {
        }
        public void setMessageObserver(MessageObserver observer) {
        }
    };
}
 
Example #15
Source File: ConduitInitiatorManagerImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void registerConduitInitiator(String namespace, ConduitInitiator factory) {
    conduitInitiators.put(namespace, factory);
}
 
Example #16
Source File: ConduitInitiatorManagerImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
public ConduitInitiator getConduitInitiatorForUri(String uri) {
    return new TransportFinder<ConduitInitiator>(bus,
        conduitInitiators,
        loaded,
        ConduitInitiator.class).findTransportForURI(uri);
}
 
Example #17
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());
    }
}
 
Example #18
Source File: MtomServerTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@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=\"<[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-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");

}