use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class RMManagerTest method testRecoverReliableClientEndpointWithAttachment.
@Test
public void testRecoverReliableClientEndpointWithAttachment() throws NoSuchMethodException, IOException {
Method method = RMManager.class.getDeclaredMethod("createReliableEndpoint", new Class[] { Endpoint.class });
manager = control.createMock(RMManager.class, new Method[] { method });
manager.setReliableEndpointsMap(new HashMap<Endpoint, RMEndpoint>());
Endpoint endpoint = control.createMock(Endpoint.class);
EndpointInfo ei = control.createMock(EndpointInfo.class);
ServiceInfo si = control.createMock(ServiceInfo.class);
BindingInfo bi = control.createMock(BindingInfo.class);
InterfaceInfo ii = control.createMock(InterfaceInfo.class);
setUpEndpointForRecovery(endpoint, ei, si, bi, ii);
Conduit conduit = control.createMock(Conduit.class);
SourceSequence ss = control.createMock(SourceSequence.class);
DestinationSequence ds = control.createMock(DestinationSequence.class);
RMMessage m1 = new RMMessage();
InputStream fis = getClass().getResourceAsStream("persistence/SerializedRMMessage.txt");
CachedOutputStream cos = new CachedOutputStream();
IOUtils.copyAndCloseInput(fis, cos);
cos.flush();
m1.setContent(cos);
m1.setTo("toAddress");
m1.setMessageNumber(new Long(10));
m1.setContentType(MULTIPART_TYPE);
Capture<Message> mc = Capture.newInstance();
setUpRecoverReliableEndpointWithAttachment(endpoint, conduit, ss, ds, m1, mc);
control.replay();
manager.recoverReliableEndpoint(endpoint, conduit);
control.verify();
Message msg = mc.getValue();
assertNotNull(msg);
assertNotNull(msg.getExchange());
assertSame(msg, msg.getExchange().getOutMessage());
CachedOutputStream cos1 = (CachedOutputStream) msg.get(RMMessageConstants.SAVED_CONTENT);
assertStartsWith(cos1.getInputStream(), "<soap:Envelope");
assertEquals(1, msg.getAttachments().size());
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class RMManagerTest method testGetReliableEndpointClientSideCreate.
@Test
public void testGetReliableEndpointClientSideCreate() throws NoSuchMethodException, RMException {
Method m1 = RMManager.class.getDeclaredMethod("createReliableEndpoint", new Class[] { Endpoint.class });
manager = control.createMock(RMManager.class, new Method[] { m1 });
manager.setReliableEndpointsMap(new HashMap<Endpoint, RMEndpoint>());
Message message = control.createMock(Message.class);
Exchange exchange = control.createMock(Exchange.class);
EasyMock.expect(message.getExchange()).andReturn(exchange).anyTimes();
Endpoint endpoint = control.createMock(Endpoint.class);
EasyMock.expect(exchange.getEndpoint()).andReturn(endpoint);
EndpointInfo ei = control.createMock(EndpointInfo.class);
EasyMock.expect(endpoint.getEndpointInfo()).andReturn(ei);
QName name = new QName("http://x.y.z/a", "GreeterPort");
EasyMock.expect(ei.getName()).andReturn(name);
RMEndpoint rme = control.createMock(RMEndpoint.class);
EasyMock.expect(manager.createReliableEndpoint(endpoint)).andReturn(rme);
EasyMock.expect(exchange.getDestination()).andReturn(null);
Conduit conduit = control.createMock(Conduit.class);
EasyMock.expect(exchange.getConduit(message)).andReturn(conduit);
rme.initialise(manager.getConfiguration(), conduit, null, null, message);
EasyMock.expectLastCall();
control.replay();
assertSame(rme, manager.getReliableEndpoint(message));
control.verify();
control.reset();
EasyMock.expect(message.getExchange()).andReturn(exchange);
EasyMock.expect(exchange.getEndpoint()).andReturn(endpoint);
EasyMock.expect(endpoint.getEndpointInfo()).andReturn(ei);
EasyMock.expect(ei.getName()).andReturn(name);
control.replay();
assertSame(rme, manager.getReliableEndpoint(message));
control.verify();
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class RMManagerTest method testRecoverReliableClientEndpoint.
@Test
public void testRecoverReliableClientEndpoint() throws NoSuchMethodException, IOException {
Method method = RMManager.class.getDeclaredMethod("createReliableEndpoint", new Class[] { Endpoint.class });
manager = control.createMock(RMManager.class, new Method[] { method });
manager.setReliableEndpointsMap(new HashMap<Endpoint, RMEndpoint>());
Endpoint endpoint = control.createMock(Endpoint.class);
EndpointInfo ei = control.createMock(EndpointInfo.class);
ServiceInfo si = control.createMock(ServiceInfo.class);
BindingInfo bi = control.createMock(BindingInfo.class);
InterfaceInfo ii = control.createMock(InterfaceInfo.class);
setUpEndpointForRecovery(endpoint, ei, si, bi, ii);
Conduit conduit = control.createMock(Conduit.class);
setUpRecoverReliableEndpoint(endpoint, conduit, null, null, null);
control.replay();
manager.recoverReliableEndpoint(endpoint, conduit);
control.verify();
control.reset();
setUpEndpointForRecovery(endpoint, ei, si, bi, ii);
SourceSequence ss = control.createMock(SourceSequence.class);
DestinationSequence ds = control.createMock(DestinationSequence.class);
setUpRecoverReliableEndpoint(endpoint, conduit, ss, ds, null);
control.replay();
manager.recoverReliableEndpoint(endpoint, conduit);
control.verify();
control.reset();
setUpEndpointForRecovery(endpoint, ei, si, bi, ii);
RMMessage m = control.createMock(RMMessage.class);
setUpRecoverReliableEndpoint(endpoint, conduit, ss, ds, m);
control.replay();
manager.recoverReliableEndpoint(endpoint, conduit);
control.verify();
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class MtomPolicyTest method sendMtomMessage.
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=\"<soap.xml@xfire.codehaus.org>\"; " + "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());
}
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class MtomServerTest method testURLBasedAttachment.
@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=\"<soap.xml@xfire.codehaus.org>\"; " + "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");
}
Aggregations