use of org.apache.cxf.endpoint.Server in project cxf by apache.
the class LifeCycleTest method testGetActiveFeatures.
@Test
public void testGetActiveFeatures() {
assertNotNull("unexpected non-null ServerLifeCycleManager", manager);
manager.registerListener(new ServerLifeCycleListener() {
public void startServer(Server server) {
org.apache.cxf.endpoint.Endpoint endpoint = server.getEndpoint();
updateMap(startNotificationMap, endpoint.getEndpointInfo().getAddress());
String portName = endpoint.getEndpointInfo().getName().getLocalPart();
if ("SoapPort".equals(portName)) {
List<Feature> active = endpoint.getActiveFeatures();
assertNotNull(active);
assertEquals(1, active.size());
assertTrue(active.get(0) instanceof WSAddressingFeature);
assertSame(active.get(0), AbstractFeature.getActive(active, WSAddressingFeature.class));
} else {
List<Feature> active = endpoint.getActiveFeatures();
assertNotNull(active);
assertEquals(0, active.size());
assertNull(AbstractFeature.getActive(active, WSAddressingFeature.class));
}
}
public void stopServer(Server server) {
updateMap(stopNotificationMap, server.getEndpoint().getEndpointInfo().getAddress());
}
});
Endpoint greeter = Endpoint.publish(ADDRESSES[0], new GreeterImpl());
Endpoint control = Endpoint.publish(ADDRESSES[1], new ControlImpl());
greeter.stop();
control.stop();
for (int i = 0; i < 2; i++) {
verifyNotification(startNotificationMap, ADDRESSES[i], 1);
verifyNotification(stopNotificationMap, ADDRESSES[i], 1);
}
}
use of org.apache.cxf.endpoint.Server 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");
}
use of org.apache.cxf.endpoint.Server in project cxf by apache.
the class SseEventSourceImplTest method stopServer.
@AfterClass
public static void stopServer() {
for (Server server : SERVERS.values()) {
server.stop();
server.destroy();
}
}
use of org.apache.cxf.endpoint.Server in project cxf by apache.
the class DOMToStaxRoundTripTest method createService.
private Service createService() {
// Create the Service
JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
factory.setServiceBean(new EchoImpl());
factory.setAddress("local://Echo");
factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
Server server = factory.create();
Service service = server.getEndpoint().getService();
service.getInInterceptors().add(new LoggingInInterceptor());
service.getOutInterceptors().add(new LoggingOutInterceptor());
return service;
}
use of org.apache.cxf.endpoint.Server in project cxf by apache.
the class RMManager method registerListeners.
@PostConstruct
void registerListeners() {
if (null == bus) {
return;
}
ServerLifeCycleManager slm = bus.getExtension(ServerLifeCycleManager.class);
if (null != slm) {
slm.registerListener(new ServerLifeCycleListener() {
public void startServer(Server server) {
RMManager.this.startServer(server);
}
public void stopServer(Server server) {
RMManager.this.stopServer(server);
}
});
}
ClientLifeCycleManager clm = bus.getExtension(ClientLifeCycleManager.class);
if (null != clm) {
clm.registerListener(new ClientLifeCycleListener() {
public void clientCreated(Client client) {
RMManager.this.clientCreated(client);
}
public void clientDestroyed(Client client) {
RMManager.this.clientDestroyed(client);
}
});
}
}
Aggregations