use of org.apache.cxf.transport.ConduitInitiator in project cxf by apache.
the class TestUtilities method invokeBytes.
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();
}
use of org.apache.cxf.transport.ConduitInitiator in project cxf by apache.
the class TestUtilities method invokeBytes.
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();
}
use of org.apache.cxf.transport.ConduitInitiator in project cxf by apache.
the class AbstractConduitSelector method getSelectedConduit.
/**
* 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 ex) {
throw new Fault(ex);
} catch (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;
}
use of org.apache.cxf.transport.ConduitInitiator in project cxf by apache.
the class JettyHTTPDestinationTest method setUpDestination.
private JettyHTTPDestination setUpDestination(boolean contextMatchOnStem, boolean mockedBus) throws Exception {
policy = new HTTPServerPolicy();
address = getEPR("bar/foo");
transportFactory = new HTTPTransportFactory();
final ConduitInitiator ci = new ConduitInitiator() {
public Conduit getConduit(EndpointInfo targetInfo, Bus b) throws IOException {
return decoupledBackChannel;
}
public Conduit getConduit(EndpointInfo localInfo, EndpointReferenceType target, Bus b) throws IOException {
return decoupledBackChannel;
}
public List<String> getTransportIds() {
return null;
}
public Set<String> getUriPrefixes() {
return new HashSet<>(Collections.singletonList("http"));
}
};
ConduitInitiatorManager mgr = new ConduitInitiatorManager() {
public void deregisterConduitInitiator(String name) {
}
public ConduitInitiator getConduitInitiator(String name) throws BusException {
return null;
}
public ConduitInitiator getConduitInitiatorForUri(String uri) {
return ci;
}
public void registerConduitInitiator(String name, ConduitInitiator factory) {
}
};
if (!mockedBus) {
bus = new ExtensionManagerBus();
bus.setExtension(mgr, ConduitInitiatorManager.class);
} else {
bus = EasyMock.createMock(Bus.class);
bus.getExtension(EndpointResolverRegistry.class);
EasyMock.expectLastCall().andReturn(null);
bus.getExtension(ContinuationProviderFactory.class);
EasyMock.expectLastCall().andReturn(null).anyTimes();
bus.getExtension(PolicyDataEngine.class);
EasyMock.expectLastCall().andReturn(null).anyTimes();
bus.hasExtensionByName("org.apache.cxf.ws.policy.PolicyEngine");
EasyMock.expectLastCall().andReturn(false);
bus.getExtension(ClassLoader.class);
EasyMock.expectLastCall().andReturn(this.getClass().getClassLoader());
EasyMock.replay(bus);
}
engine = EasyMock.createNiceMock(JettyHTTPServerEngine.class);
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setName(new QName("bla", "Service"));
endpointInfo = new EndpointInfo(serviceInfo, "");
endpointInfo.setName(new QName("bla", "Port"));
endpointInfo.setAddress(NOWHERE + "bar/foo");
endpointInfo.addExtensor(policy);
engine.addServant(EasyMock.eq(new URL(NOWHERE + "bar/foo")), EasyMock.isA(JettyHTTPHandler.class));
EasyMock.expectLastCall();
engine.getContinuationsEnabled();
EasyMock.expectLastCall().andReturn(true);
EasyMock.replay(engine);
JettyHTTPDestination dest = new EasyMockJettyHTTPDestination(bus, transportFactory.getRegistry(), endpointInfo, null, engine);
dest.retrieveEngine();
policy = dest.getServer();
observer = new MessageObserver() {
public void onMessage(Message m) {
inMessage = m;
threadDefaultBus = BusFactory.getThreadDefaultBus();
}
};
dest.setMessageObserver(observer);
return dest;
}
use of org.apache.cxf.transport.ConduitInitiator in project cxf by apache.
the class NettyHttpDestinationTest method setUpDestination.
private NettyHttpDestination setUpDestination(boolean contextMatchOnStem, boolean mockedBus) throws Exception {
policy = new HTTPServerPolicy();
address = getEPR("bar/foo");
transportFactory = new HTTPTransportFactory();
final ConduitInitiator ci = new ConduitInitiator() {
public Conduit getConduit(EndpointInfo targetInfo, Bus b) throws IOException {
return decoupledBackChannel;
}
public Conduit getConduit(EndpointInfo localInfo, EndpointReferenceType target, Bus b) throws IOException {
return decoupledBackChannel;
}
public List<String> getTransportIds() {
return null;
}
public Set<String> getUriPrefixes() {
return new HashSet<>(Collections.singletonList("http"));
}
};
ConduitInitiatorManager mgr = new ConduitInitiatorManager() {
public void deregisterConduitInitiator(String name) {
}
public ConduitInitiator getConduitInitiator(String name) throws BusException {
return null;
}
public ConduitInitiator getConduitInitiatorForUri(String uri) {
return ci;
}
public void registerConduitInitiator(String name, ConduitInitiator factory) {
}
};
if (!mockedBus) {
bus = new ExtensionManagerBus();
bus.setExtension(mgr, ConduitInitiatorManager.class);
} else {
bus = EasyMock.createMock(Bus.class);
bus.getExtension(EndpointResolverRegistry.class);
EasyMock.expectLastCall().andReturn(null);
bus.getExtension(ContinuationProviderFactory.class);
EasyMock.expectLastCall().andReturn(null).anyTimes();
bus.getExtension(PolicyDataEngine.class);
EasyMock.expectLastCall().andReturn(null).anyTimes();
bus.hasExtensionByName("org.apache.cxf.ws.policy.PolicyEngine");
EasyMock.expectLastCall().andReturn(false);
bus.getExtension(ClassLoader.class);
EasyMock.expectLastCall().andReturn(this.getClass().getClassLoader());
EasyMock.replay(bus);
}
engine = EasyMock.createNiceMock(NettyHttpServerEngine.class);
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setName(new QName("bla", "Service"));
endpointInfo = new EndpointInfo(serviceInfo, "");
endpointInfo.setName(new QName("bla", "Port"));
endpointInfo.setAddress(NOWHERE + "bar/foo");
endpointInfo.addExtensor(policy);
engine.addServant(EasyMock.eq(new URL(NOWHERE + "bar/foo")), EasyMock.isA(NettyHttpHandler.class));
EasyMock.expectLastCall();
EasyMock.replay(engine);
NettyHttpDestination dest = new EasyMockJettyHTTPDestination(bus, transportFactory.getRegistry(), endpointInfo, null, engine);
dest.retrieveEngine();
policy = dest.getServer();
observer = new MessageObserver() {
public void onMessage(Message m) {
inMessage = m;
threadDefaultBus = BusFactory.getThreadDefaultBus();
}
};
dest.setMessageObserver(observer);
return dest;
}
Aggregations