Search in sources :

Example 51 with Server

use of org.apache.cxf.endpoint.Server in project cxf by apache.

the class RESTLoggingTest method testSlf4j.

@Test
public void testSlf4j() throws IOException {
    LoggingFeature loggingFeature = new LoggingFeature();
    Server server = createService(SERVICE_URI, new TestServiceRest(), loggingFeature);
    server.start();
    WebClient client = createClient(SERVICE_URI, loggingFeature);
    String result = client.get(String.class);
    server.destroy();
    Assert.assertEquals("test1", result);
}
Also used : Server(org.apache.cxf.endpoint.Server) LoggingFeature(org.apache.cxf.ext.logging.LoggingFeature) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 52 with Server

use of org.apache.cxf.endpoint.Server in project cxf by apache.

the class RESTLoggingTest method testBinary.

@Test
public void testBinary() throws IOException, InterruptedException {
    LoggingFeature loggingFeature = new LoggingFeature();
    TestEventSender sender = new TestEventSender();
    loggingFeature.setSender(sender);
    loggingFeature.setLogBinary(true);
    Server server = createService(SERVICE_URI_BINARY, new TestServiceRestBinary(), loggingFeature);
    server.start();
    WebClient client = createClient(SERVICE_URI_BINARY, loggingFeature);
    client.get(InputStream.class).close();
    client.close();
    List<LogEvent> events = sender.getEvents();
    await().until(() -> events.size(), is(4));
    server.stop();
    server.destroy();
    Assert.assertEquals(4, events.size());
    assertContentLogged(events.get(0));
    assertContentLogged(events.get(1));
    assertContentLogged(events.get(2));
    assertContentLogged(events.get(3));
}
Also used : Server(org.apache.cxf.endpoint.Server) LogEvent(org.apache.cxf.ext.logging.event.LogEvent) InputStream(java.io.InputStream) LoggingFeature(org.apache.cxf.ext.logging.LoggingFeature) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 53 with Server

use of org.apache.cxf.endpoint.Server in project cxf by apache.

the class RESTLoggingTest method testEvents.

@Test
public void testEvents() throws MalformedURLException {
    LoggingFeature loggingFeature = new LoggingFeature();
    loggingFeature.setLogBinary(true);
    TestEventSender sender = new TestEventSender();
    loggingFeature.setSender(sender);
    Server server = createService(SERVICE_URI, new TestServiceRest(), loggingFeature);
    server.start();
    WebClient client = createClient(SERVICE_URI, loggingFeature);
    String result = client.get(String.class);
    Assert.assertEquals("test1", result);
    List<LogEvent> events = sender.getEvents();
    await().until(() -> events.size(), is(4));
    server.stop();
    server.destroy();
    Assert.assertEquals(4, events.size());
    checkRequestOut(events.get(0));
    checkRequestIn(events.get(1));
    checkResponseOut(events.get(2));
    checkResponseIn(events.get(3));
}
Also used : Server(org.apache.cxf.endpoint.Server) LogEvent(org.apache.cxf.ext.logging.event.LogEvent) LoggingFeature(org.apache.cxf.ext.logging.LoggingFeature) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 54 with Server

use of org.apache.cxf.endpoint.Server in project cxf by apache.

the class ServerFactoryBean method create.

public Server create() {
    ClassLoaderHolder orig = null;
    try {
        Server server = null;
        try {
            if (bus != null) {
                ClassLoader loader = bus.getExtension(ClassLoader.class);
                if (loader != null) {
                    orig = ClassLoaderUtils.setThreadContextClassloader(loader);
                }
            }
            if (getServiceFactory().getProperties() == null) {
                getServiceFactory().setProperties(getProperties());
            } else if (getProperties() != null) {
                getServiceFactory().getProperties().putAll(getProperties());
            }
            if (serviceBean != null && getServiceClass() == null) {
                setServiceClass(ClassHelper.getRealClass(bus, serviceBean));
            }
            if (invoker != null) {
                getServiceFactory().setInvoker(invoker);
            } else if (serviceBean != null) {
                invoker = createInvoker();
                getServiceFactory().setInvoker(invoker);
            }
            Endpoint ep = createEndpoint();
            getServiceFactory().sendEvent(FactoryBeanListener.Event.PRE_SERVER_CREATE, server, serviceBean, serviceBean == null ? getServiceClass() == null ? getServiceFactory().getServiceClass() : getServiceClass() : getServiceClass() == null ? ClassHelper.getRealClass(getBus(), getServiceBean()) : getServiceClass());
            server = new ServerImpl(getBus(), ep, getDestinationFactory(), getBindingFactory());
            if (ep.getService().getInvoker() == null) {
                if (invoker == null) {
                    ep.getService().setInvoker(createInvoker());
                } else {
                    ep.getService().setInvoker(invoker);
                }
            }
        } catch (EndpointException | BusException | IOException e) {
            throw new ServiceConstructionException(e);
        }
        if (serviceBean != null) {
            Class<?> cls = ClassHelper.getRealClass(getServiceBean());
            if (getServiceClass() == null || cls.equals(getServiceClass())) {
                initializeAnnotationInterceptors(server.getEndpoint(), cls);
            } else {
                initializeAnnotationInterceptors(server.getEndpoint(), cls, getServiceClass());
            }
        } else if (getServiceClass() != null) {
            initializeAnnotationInterceptors(server.getEndpoint(), getServiceClass());
        }
        applyFeatures(server);
        getServiceFactory().sendEvent(FactoryBeanListener.Event.SERVER_CREATED, server, serviceBean, serviceBean == null ? getServiceClass() == null ? getServiceFactory().getServiceClass() : getServiceClass() : getServiceClass() == null ? ClassHelper.getRealClass(getServiceBean()) : getServiceClass());
        if (start) {
            try {
                server.start();
            } catch (RuntimeException re) {
                // prevent resource leak
                server.destroy();
                throw re;
            }
        }
        getServiceFactory().reset();
        return server;
    } finally {
        if (orig != null) {
            orig.reset();
        }
    }
}
Also used : Server(org.apache.cxf.endpoint.Server) Endpoint(org.apache.cxf.endpoint.Endpoint) ServerImpl(org.apache.cxf.endpoint.ServerImpl) EndpointException(org.apache.cxf.endpoint.EndpointException) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder) IOException(java.io.IOException) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) BusException(org.apache.cxf.BusException)

Example 55 with Server

use of org.apache.cxf.endpoint.Server in project cxf by apache.

the class ReflectionServiceFactoryTest method testServerFactoryBean.

@Test
public void testServerFactoryBean() throws Exception {
    Service service = createService(true);
    assertEquals("test", service.get("test"));
    ServerFactoryBean svrBean = new ServerFactoryBean();
    svrBean.setAddress("http://localhost/Hello");
    svrBean.setServiceFactory(serviceFactory);
    svrBean.setServiceBean(new HelloServiceImpl());
    svrBean.setBus(getBus());
    Map<String, Object> props = new HashMap<>();
    props.put("test", "test");
    serviceFactory.setProperties(props);
    svrBean.setProperties(props);
    Server server = svrBean.create();
    assertNotNull(server);
    Map<QName, Endpoint> eps = service.getEndpoints();
    assertEquals(1, eps.size());
    Endpoint ep = eps.values().iterator().next();
    EndpointInfo endpointInfo = ep.getEndpointInfo();
    assertEquals("test", ep.get("test"));
    BindingInfo b = endpointInfo.getService().getBindings().iterator().next();
    assertTrue(b instanceof SoapBindingInfo);
    SoapBindingInfo sb = (SoapBindingInfo) b;
    assertEquals("HelloServiceSoapBinding", b.getName().getLocalPart());
    assertEquals("document", sb.getStyle());
    assertEquals(4, b.getOperations().size());
    BindingOperationInfo bop = b.getOperations().iterator().next();
    SoapOperationInfo sop = bop.getExtensor(SoapOperationInfo.class);
    assertNotNull(sop);
    assertEquals("", sop.getAction());
    assertEquals("document", sop.getStyle());
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Server(org.apache.cxf.endpoint.Server) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(org.apache.cxf.service.Service) ServerFactoryBean(org.apache.cxf.frontend.ServerFactoryBean) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) Test(org.junit.Test)

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