org.apache.cxf.transport.ConduitInitiatorManager Java Examples

The following examples show how to use org.apache.cxf.transport.ConduitInitiatorManager. 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: SpringBusFactoryTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: SpringBusFactoryTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
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"));
}
 
Example #3
Source File: ServerFactoryBean.java    From cxf with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #4
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 #5
Source File: AbstractServiceFactory.java    From cxf with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #6
Source File: WebClientSubstitution.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #7
Source File: AbstractSimpleFrontendTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #8
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 #9
Source File: CXFBusImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #10
Source File: SpringBusFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@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());

}
 
Example #11
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 #12
Source File: ConduitInitiatorManagerImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Resource
public void setBus(Bus b) {
    bus = b;
    if (null != bus) {
        bus.setExtension(this, ConduitInitiatorManager.class);
    }
}
 
Example #13
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 #14
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 #15
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 #16
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 #17
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 #18
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 #19
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 #20
Source File: AbstractJaxWsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #21
Source File: AbstractAegisTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@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);

}
 
Example #22
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 #23
Source File: ExtensionManagerBus.java    From cxf with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example #24
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 #25
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");

}
 
Example #26
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());
    }
}