Java源码示例:org.apache.cxf.transport.ConduitInitiatorManager

示例1
@Substitute
static JAXRSClientFactoryBean getBean(String baseAddress, String configLocation) {
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    // configLocation is always null and no need to create SpringBusFactory.
    CXFBusFactory bf = new CXFBusFactory();

    // It can not load the extensions from the bus-extensions.txt dynamically.
    // So have to set all of necessary ones here.
    List<Extension> extensions = new ArrayList<>();
    Extension http = new Extension();
    http.setClassname(HTTPTransportFactory.class.getName());
    http.setDeferred(true);
    extensions.add(http);
    ExtensionRegistry.addExtensions(extensions);

    Bus bus = bf.createBus();
    bus.setExtension(new PhaseManagerImpl(), PhaseManager.class);
    bus.setExtension(new ClientLifeCycleManagerImpl(), ClientLifeCycleManager.class);
    bus.setExtension(new ConduitInitiatorManagerImpl(bus), ConduitInitiatorManager.class);

    bean.setBus(bus);
    bean.setAddress(baseAddress);
    return bean;
}
 
示例2
@Test
public void testKnownExtensions() throws BusException {
    Bus bus = new SpringBusFactory().createBus();
    assertNotNull(bus);

    checkBindingExtensions(bus);

    DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
    assertNotNull("No destination factory manager", dfm);
    ConduitInitiatorManager cim = bus.getExtension(ConduitInitiatorManager.class);
    assertNotNull("No conduit initiator manager", cim);

    checkTransportFactories(bus);
    checkOtherCoreExtensions(bus);
    //you should include instumentation extenstion to get the instrumentation manager
    assertNotNull("No instrumentation manager", bus.getExtension(InstrumentationManager.class));
    bus.shutdown(true);
}
 
示例3
private void checkHTTPTransportFactories(Bus bus) throws BusException {
    ConduitInitiatorManager cim = bus.getExtension(ConduitInitiatorManager.class);
    assertNotNull("No conduit initiator manager", cim);

    assertNotNull("conduit initiator not available",
                  cim.getConduitInitiator("http://schemas.xmlsoap.org/wsdl/soap/http"));
    assertNotNull("conduit initiator not available",
                  cim.getConduitInitiator("http://schemas.xmlsoap.org/wsdl/http/"));
    assertNotNull("conduit initiator not available",
                  cim.getConduitInitiator("http://cxf.apache.org/transports/http/configuration"));

    DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
    assertNotNull("No destination factory manager", dfm);

    assertNotNull("destination factory not available",
                  dfm.getDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/"));
    assertNotNull("destination factory not available",
                  dfm.getDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/http"));
    assertNotNull("destination factory not available",
                  dfm.getDestinationFactory("http://schemas.xmlsoap.org/wsdl/http/"));
    assertNotNull("destination factory not available",
                  dfm.getDestinationFactory("http://cxf.apache.org/transports/http/configuration"));
}
 
示例4
@Override
protected WSDLEndpointFactory getWSDLEndpointFactory() {
    if (destinationFactory == null) {
        try {
            destinationFactory = getBus().getExtension(DestinationFactoryManager.class)
                .getDestinationFactory(transportId);
        } catch (Throwable t) {
            try {
                Object o = getBus().getExtension(ConduitInitiatorManager.class)
                    .getConduitInitiator(transportId);
                if (o instanceof WSDLEndpointFactory) {
                    return (WSDLEndpointFactory)o;
                }
            } catch (Throwable th) {
                //ignore
            }
        }
    }
    if (destinationFactory instanceof WSDLEndpointFactory) {
        return (WSDLEndpointFactory)destinationFactory;
    }
    return null;
}
 
示例5
@Override
protected WSDLEndpointFactory getWSDLEndpointFactory() {
    if (destinationFactory == null) {
        try {
            destinationFactory = getBus().getExtension(DestinationFactoryManager.class)
                .getDestinationFactory(transportId);
        } catch (Throwable t) {
            try {
                Object o = getBus().getExtension(ConduitInitiatorManager.class)
                    .getConduitInitiator(transportId);
                if (o instanceof WSDLEndpointFactory) {
                    return (WSDLEndpointFactory)o;
                }
            } catch (Throwable th) {
                //ignore
            }
        }
    }
    if (destinationFactory instanceof WSDLEndpointFactory) {
        return (WSDLEndpointFactory)destinationFactory;
    }
    return null;
}
 
示例6
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();
}
 
示例7
@Before
public void setUp() throws Exception {
    super.setUpBus();

    SoapBindingFactory bindingFactory = new SoapBindingFactory();
    bindingFactory.setBus(bus);

    bus.getExtension(BindingFactoryManager.class)
        .registerBindingFactory("http://schemas.xmlsoap.org/wsdl/soap/", bindingFactory);

    DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);

    SoapTransportFactory soapDF = new SoapTransportFactory();
    dfm.registerDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/", soapDF);
    dfm.registerDestinationFactory(SoapBindingConstants.SOAP11_BINDING_ID, soapDF);
    dfm.registerDestinationFactory("http://cxf.apache.org/transports/local", soapDF);

    localTransport = new LocalTransportFactory();
    dfm.registerDestinationFactory("http://schemas.xmlsoap.org/soap/http", localTransport);
    dfm.registerDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/http", localTransport);
    dfm.registerDestinationFactory("http://cxf.apache.org/bindings/xformat", localTransport);
    dfm.registerDestinationFactory("http://cxf.apache.org/transports/local", localTransport);

    ConduitInitiatorManager extension = bus.getExtension(ConduitInitiatorManager.class);
    extension.registerConduitInitiator(LocalTransportFactory.TRANSPORT_ID, localTransport);
    extension.registerConduitInitiator("http://schemas.xmlsoap.org/wsdl/soap/", localTransport);
    extension.registerConduitInitiator("http://schemas.xmlsoap.org/soap/http", localTransport);
    extension.registerConduitInitiator(SoapBindingConstants.SOAP11_BINDING_ID, localTransport);

    bus.setExtension(new WSDLManagerImpl(), WSDLManager.class);
    //WoodstoxValidationImpl wstxVal = new WoodstoxValidationImpl();



    addNamespace("wsdl", WSDLConstants.NS_WSDL11);
    addNamespace("wsdlsoap", WSDLConstants.NS_SOAP11);
    addNamespace("xsd", WSDLConstants.NS_SCHEMA_XSD);

}
 
示例8
@Before
public void setUpBus() throws Exception {
    super.setUpBus();

    SoapBindingFactory bindingFactory = new SoapBindingFactory();
    bindingFactory.setBus(bus);
    bus.getExtension(BindingFactoryManager.class)
        .registerBindingFactory("http://schemas.xmlsoap.org/wsdl/soap/", bindingFactory);
    bus.getExtension(BindingFactoryManager.class)
        .registerBindingFactory("http://schemas.xmlsoap.org/wsdl/soap/http", bindingFactory);

    DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);

    SoapTransportFactory soapDF = new SoapTransportFactory();
    dfm.registerDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/", soapDF);
    dfm.registerDestinationFactory(SoapBindingConstants.SOAP11_BINDING_ID, soapDF);
    dfm.registerDestinationFactory(SoapBindingConstants.SOAP12_BINDING_ID, soapDF);
    dfm.registerDestinationFactory("http://cxf.apache.org/transports/local", soapDF);

    localTransport = new LocalTransportFactory();
    localTransport.setUriPrefixes(new HashSet<>(Arrays.asList("http", "local")));
    dfm.registerDestinationFactory(LocalTransportFactory.TRANSPORT_ID, localTransport);
    dfm.registerDestinationFactory("http://cxf.apache.org/transports/http", localTransport);
    dfm.registerDestinationFactory("http://cxf.apache.org/transports/http/configuration", localTransport);

    ConduitInitiatorManager extension = bus.getExtension(ConduitInitiatorManager.class);
    extension.registerConduitInitiator(LocalTransportFactory.TRANSPORT_ID, localTransport);
    extension.registerConduitInitiator("http://schemas.xmlsoap.org/soap/http", localTransport);
    extension.registerConduitInitiator("http://cxf.apache.org/transports/http", localTransport);
    extension.registerConduitInitiator("http://cxf.apache.org/transports/http/configuration",
                                       localTransport);
}
 
示例9
@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;
}
 
示例10
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);
    }
}
 
示例11
@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;
}
 
示例12
@Before
public void setUp() throws Exception {
    super.setUpBus();

    Bus bus = getBus();

    SoapBindingFactory bindingFactory = new SoapBindingFactory();

    bus.getExtension(BindingFactoryManager.class)
        .registerBindingFactory("http://schemas.xmlsoap.org/wsdl/soap/", bindingFactory);

    DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
    SoapTransportFactory soapTF = new SoapTransportFactory();
    dfm.registerDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/", soapTF);
    dfm.registerDestinationFactory("http://schemas.xmlsoap.org/soap/", soapTF);

    LocalTransportFactory localTransport = new LocalTransportFactory();
    localTransport.getUriPrefixes().add("http");
    dfm.registerDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/http", localTransport);
    dfm.registerDestinationFactory("http://schemas.xmlsoap.org/soap/http", localTransport);

    ConduitInitiatorManager extension = bus.getExtension(ConduitInitiatorManager.class);
    extension.registerConduitInitiator(LocalTransportFactory.TRANSPORT_ID, localTransport);
    extension.registerConduitInitiator("http://schemas.xmlsoap.org/wsdl/soap/http", localTransport);
    extension.registerConduitInitiator("http://schemas.xmlsoap.org/soap/http", localTransport);

    extension.registerConduitInitiator("http://schemas.xmlsoap.org/wsdl/soap/", soapTF);
}
 
示例13
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;
}
 
示例14
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;
}
 
示例15
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));
    }
}
 
示例16
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();
}
 
示例17
@Resource
public void setBus(Bus b) {
    bus = b;
    if (null != bus) {
        bus.setExtension(this, ConduitInitiatorManager.class);
    }
}
 
示例18
/**
 * 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;
}
 
示例19
@Test
public void testDefault() {
    Bus bus = new SpringBusFactory().createBus();
    assertNotNull(bus);
    BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class);
    assertNotNull("No binding factory manager", bfm);
    assertNotNull("No configurer", bus.getExtension(Configurer.class));
    assertNotNull("No resource manager", bus.getExtension(ResourceManager.class));
    assertNotNull("No destination factory manager", bus.getExtension(DestinationFactoryManager.class));
    assertNotNull("No conduit initiator manager", bus.getExtension(ConduitInitiatorManager.class));
    assertNotNull("No phase manager", bus.getExtension(PhaseManager.class));
    assertNotNull("No workqueue manager", bus.getExtension(WorkQueueManager.class));
    assertNotNull("No lifecycle manager", bus.getExtension(BusLifeCycleManager.class));
    assertNotNull("No service registry", bus.getExtension(ServerRegistry.class));

    try {
        bfm.getBindingFactory("http://cxf.apache.org/unknown");
    } catch (BusException ex) {
        // expected
    }

    assertEquals("Unexpected interceptors", 0, bus.getInInterceptors().size());
    assertEquals("Unexpected interceptors", 0, bus.getInFaultInterceptors().size());
    assertEquals("Unexpected interceptors", 0, bus.getOutInterceptors().size());
    assertEquals("Unexpected interceptors", 0, bus.getOutFaultInterceptors().size());

}
 
示例20
@Test
public void testConstructionWithoutExtensions() throws BusException {

    Bus bus = new ExtensionManagerBus();
    assertNotNull(bus.getExtension(BindingFactoryManager.class));
    assertNotNull(bus.getExtension(ConduitInitiatorManager.class));
    assertNotNull(bus.getExtension(DestinationFactoryManager.class));
    assertNotNull(bus.getExtension(PhaseManager.class));
    bus.shutdown(true);
}
 
示例21
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;
    }
}
 
示例22
@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());
    }
}
 
示例23
@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");

}
 
示例24
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());
    }
}
 
示例25
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) {
        }
    };
}
 
示例26
public ExtensionManagerBus(Map<Class<?>, Object> extensions, Map<String, Object> props,
      ClassLoader extensionClassLoader) {
    this.extensions = extensions == null ? new ConcurrentHashMap<>(16, 0.75f, 4)
            : new ConcurrentHashMap<>(extensions);
    this.missingExtensions = new CopyOnWriteArraySet<>();


    state = BusState.INITIAL;

    BusFactory.possiblySetDefaultBus(this);
    if (null != props) {
        properties.putAll(props);
    }

    Configurer configurer = (Configurer)this.extensions.get(Configurer.class);
    if (null == configurer) {
        configurer = new NullConfigurer();
        this.extensions.put(Configurer.class, configurer);
    }

    id = getBusId(properties);

    ResourceManager resourceManager = new DefaultResourceManager();

    properties.put(BUS_ID_PROPERTY_NAME, BUS_PROPERTY_NAME);
    properties.put(BUS_PROPERTY_NAME, this);
    properties.put(DEFAULT_BUS_ID, this);

    ResourceResolver propertiesResolver = new PropertiesResolver(properties);
    resourceManager.addResourceResolver(propertiesResolver);

    ResourceResolver busResolver = new SinglePropertyResolver(BUS_PROPERTY_NAME, this);
    resourceManager.addResourceResolver(busResolver);
    resourceManager.addResourceResolver(new ObjectTypeResolver(this));

    busResolver = new SinglePropertyResolver(DEFAULT_BUS_ID, this);
    resourceManager.addResourceResolver(busResolver);
    resourceManager.addResourceResolver(new ObjectTypeResolver(this));
    resourceManager.addResourceResolver(new ResourceResolver() {
        public <T> T resolve(String resourceName, Class<T> resourceType) {
            if (extensionManager != null) {
                return extensionManager.getExtension(resourceName, resourceType);
            }
            return null;
        }
        public InputStream getAsStream(String name) {
            return null;
        }
    });

    this.extensions.put(ResourceManager.class, resourceManager);

    extensionManager = new ExtensionManagerImpl(new String[0],
                                                extensionClassLoader,
                                                this.extensions,
                                                resourceManager,
                                                this);

    setState(BusState.INITIAL);

    if (null == this.getExtension(DestinationFactoryManager.class)) {
        new DestinationFactoryManagerImpl(this);
    }

    if (null == this.getExtension(ConduitInitiatorManager.class)) {
        new ConduitInitiatorManagerImpl(this);
    }

    if (null == this.getExtension(BindingFactoryManager.class)) {
        new BindingFactoryManagerImpl(this);
    }
    extensionManager.load(new String[] {ExtensionManagerImpl.BUS_EXTENSION_RESOURCE});
    extensionManager.activateAllByType(ResourceResolver.class);

    this.extensions.put(ExtensionManager.class, extensionManager);
}