use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class UndertowHTTPDestinationTest method testGetBackChannelSendDecoupled.
@Test
public void testGetBackChannelSendDecoupled() throws Exception {
destination = setUpDestination(false, false);
setUpDoService(false, true, true, 202);
destination.doService(request, response);
setUpInMessage();
Message partialResponse = setUpOutMessage();
partialResponse.put(Message.PARTIAL_RESPONSE_MESSAGE, Boolean.TRUE);
Conduit partialBackChannel = destination.getBackChannel(inMessage);
partialBackChannel.prepare(partialResponse);
verifyBackChannelSend(partialBackChannel, partialResponse, 202);
outMessage = setUpOutMessage();
Conduit fullBackChannel = destination.getBackChannel(inMessage);
fullBackChannel.prepare(outMessage);
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class UndertowHTTPDestinationTest method testGetBackChannelSendOneway.
@Test
public void testGetBackChannelSendOneway() throws Exception {
destination = setUpDestination(false, false);
setUpDoService(false, true, 500);
destination.doService(request, response);
setUpInMessage();
Conduit backChannel = destination.getBackChannel(inMessage);
outMessage = setUpOutMessage();
backChannel.prepare(outMessage);
verifyBackChannelSend(backChannel, outMessage, 500, true);
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class MtomServerTest method testMtomRequest.
@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=\"<soap.xml@xfire.codehaus.org>\"; " + "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());
}
}
use of org.apache.cxf.transport.Conduit 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.Conduit 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) {
}
};
}
Aggregations