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();
}
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();
}
}
});
}
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);
}
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) {
}
};
}
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;
}
Aggregations