Search in sources :

Example 16 with Destination

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

the class JAXWSHttpSpiTransportFactoryTest method getDestination.

public void getDestination(String endpointAddress) throws Exception {
    context.setHandler(EasyMock.isA(HttpHandler.class));
    control.replay();
    EndpointInfo endpoint = new EndpointInfo();
    endpoint.setAddress(endpointAddress);
    Destination destination = factory.getDestination(endpoint, bus);
    assertNotNull(destination);
    assertNotNull(destination.getAddress());
    assertNotNull(destination.getAddress().getAddress());
    assertEquals(endpointAddress, destination.getAddress().getAddress().getValue());
    assertEquals(endpointAddress, endpoint.getAddress());
    control.verify();
}
Also used : HttpHandler(javax.xml.ws.spi.http.HttpHandler) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Destination(org.apache.cxf.transport.Destination)

Example 17 with Destination

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

the class MtomServerTest method servStatic.

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

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

Example 18 with Destination

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

the class MtomServerTest method unregisterServStatic.

private void unregisterServStatic(String add) throws Exception {
    Bus bus = getStaticBus();
    DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
    DestinationFactory df = dfm.getDestinationFactory("http://cxf.apache.org/transports/http/configuration");
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress(add);
    Destination d = df.getDestination(ei, bus);
    d.setMessageObserver(null);
}
Also used : Bus(org.apache.cxf.Bus) DestinationFactory(org.apache.cxf.transport.DestinationFactory) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Destination(org.apache.cxf.transport.Destination) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager)

Example 19 with Destination

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

the class ContextUtils method createDecoupledDestination.

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) {
        }
    };
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Destination(org.apache.cxf.transport.Destination) Bus(org.apache.cxf.Bus) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) Conduit(org.apache.cxf.transport.Conduit) InputStream(java.io.InputStream) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException)

Example 20 with Destination

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

the class EndpointReferenceUtils method getEndpointReferenceId.

/**
 * Obtain the id String from the endpoint reference of the current dispatch.
 * @param messageContext the current message context
 * @return the id embedded in the current endpoint reference or null if not found
 */
public static String getEndpointReferenceId(Map<String, Object> messageContext) {
    String id = null;
    Destination destination = (Destination) messageContext.get(Destination.class.getName());
    if (destination instanceof MultiplexDestination) {
        id = ((MultiplexDestination) destination).getId(messageContext);
    }
    return id;
}
Also used : Destination(org.apache.cxf.transport.Destination) MultiplexDestination(org.apache.cxf.transport.MultiplexDestination) MultiplexDestination(org.apache.cxf.transport.MultiplexDestination)

Aggregations

Destination (org.apache.cxf.transport.Destination)41 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)25 Test (org.junit.Test)14 Message (org.apache.cxf.message.Message)13 QName (javax.xml.namespace.QName)12 Bus (org.apache.cxf.Bus)12 Exchange (org.apache.cxf.message.Exchange)12 Conduit (org.apache.cxf.transport.Conduit)11 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)8 AbstractHTTPDestination (org.apache.cxf.transport.http.AbstractHTTPDestination)8 Endpoint (org.apache.cxf.endpoint.Endpoint)7 DestinationFactory (org.apache.cxf.transport.DestinationFactory)7 DestinationFactoryManager (org.apache.cxf.transport.DestinationFactoryManager)7 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)6 HTTPTransportFactory (org.apache.cxf.transport.http.HTTPTransportFactory)6 MessageObserver (org.apache.cxf.transport.MessageObserver)5 IOException (java.io.IOException)4 Fault (org.apache.cxf.interceptor.Fault)4 ConduitInitiator (org.apache.cxf.transport.ConduitInitiator)4 Policy (org.apache.neethi.Policy)4