Search in sources :

Example 61 with Server

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);
    }
}
Also used : WSAddressingFeature(org.apache.cxf.ws.addressing.WSAddressingFeature) Server(org.apache.cxf.endpoint.Server) Endpoint(javax.xml.ws.Endpoint) ServerLifeCycleListener(org.apache.cxf.endpoint.ServerLifeCycleListener) List(java.util.List) ControlImpl(org.apache.cxf.greeter_control.ControlImpl) Endpoint(javax.xml.ws.Endpoint) Test(org.junit.Test)

Example 62 with Server

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");
}
Also used : Server(org.apache.cxf.endpoint.Server) Message(org.apache.cxf.message.Message) AttachmentDeserializer(org.apache.cxf.attachment.AttachmentDeserializer) HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Attachment(org.apache.cxf.message.Attachment) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TestUtilities(org.apache.cxf.test.TestUtilities) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Conduit(org.apache.cxf.transport.Conduit) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 63 with Server

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();
    }
}
Also used : Server(org.apache.cxf.endpoint.Server) AfterClass(org.junit.AfterClass)

Example 64 with Server

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;
}
Also used : Server(org.apache.cxf.endpoint.Server) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) Service(org.apache.cxf.service.Service) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean)

Example 65 with Server

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);
            }
        });
    }
}
Also used : ClientLifeCycleListener(org.apache.cxf.endpoint.ClientLifeCycleListener) Server(org.apache.cxf.endpoint.Server) ServerLifeCycleManager(org.apache.cxf.endpoint.ServerLifeCycleManager) ClientLifeCycleManager(org.apache.cxf.endpoint.ClientLifeCycleManager) ServerLifeCycleListener(org.apache.cxf.endpoint.ServerLifeCycleListener) Client(org.apache.cxf.endpoint.Client) PostConstruct(javax.annotation.PostConstruct)

Aggregations

Server (org.apache.cxf.endpoint.Server)199 Test (org.junit.Test)119 ReferenceParametersType (org.apache.cxf.ws.addressing.ReferenceParametersType)54 ResourceManager (org.apache.cxf.ws.transfer.manager.ResourceManager)52 MemoryResourceManager (org.apache.cxf.ws.transfer.manager.MemoryResourceManager)50 Resource (org.apache.cxf.ws.transfer.resource.Resource)50 ExpressionType (org.apache.cxf.ws.transfer.dialect.fragment.ExpressionType)47 ValueType (org.apache.cxf.ws.transfer.dialect.fragment.ValueType)44 Element (org.w3c.dom.Element)44 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)33 Put (org.apache.cxf.ws.transfer.Put)33 Fragment (org.apache.cxf.ws.transfer.dialect.fragment.Fragment)32 Service (org.apache.cxf.service.Service)27 Bus (org.apache.cxf.Bus)25 PutResponse (org.apache.cxf.ws.transfer.PutResponse)25 Endpoint (org.apache.cxf.endpoint.Endpoint)21 ArrayList (java.util.ArrayList)18 QName (javax.xml.namespace.QName)18 ServerRegistry (org.apache.cxf.endpoint.ServerRegistry)18 Document (org.w3c.dom.Document)18