Search in sources :

Example 1 with Server

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

the class CxfConsumer method createServer.

protected Server createServer() throws Exception {
    ServerFactoryBean svrBean = cxfEndpoint.createServerFactoryBean();
    svrBean.setInvoker(new CxfConsumerInvoker(cxfEndpoint));
    Server server = svrBean.create();
    // Apply the server configurer if it is possible
    if (cxfEndpoint.getCxfEndpointConfigurer() != null) {
        cxfEndpoint.getCxfEndpointConfigurer().configureServer(server);
    }
    if (ObjectHelper.isNotEmpty(cxfEndpoint.getPublishedEndpointUrl())) {
        server.getEndpoint().getEndpointInfo().setProperty("publishedEndpointUrl", cxfEndpoint.getPublishedEndpointUrl());
    }
    return server;
}
Also used : Server(org.apache.cxf.endpoint.Server) ServerFactoryBean(org.apache.cxf.frontend.ServerFactoryBean)

Example 2 with Server

use of org.apache.cxf.endpoint.Server in project fabric8 by jboss-fuse.

the class Java2SwaggerJsonMojo method execute.

public void execute() throws MojoExecutionException {
    List<Class<?>> resourceClasses = loadResourceClasses();
    List<Object> resourceObjects = new ArrayList<Object>();
    for (Class<?> resourceClass : resourceClasses) {
        try {
            resourceObjects.add(resourceClass.newInstance());
        } catch (InstantiationException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        } catch (IllegalAccessException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
    Thread.currentThread().setContextClassLoader(getClassLoader());
    List<Feature> features = new ArrayList<Feature>();
    features.add(new SwaggerFeature());
    JAXRSServerFactoryBean serverFacBean = new JAXRSServerFactoryBean();
    serverFacBean.setAddress(address);
    serverFacBean.setServiceBeans(resourceObjects);
    serverFacBean.setFeatures(features);
    Server server = serverFacBean.create();
    InputStream in = null;
    try {
        String res = "";
        for (Class<?> resourceClass : resourceClasses) {
            com.wordnik.swagger.annotations.Api api = resourceClass.getAnnotation(com.wordnik.swagger.annotations.Api.class);
            if (api != null) {
                String apiPath = api.value();
                String serverAddress = server.getEndpoint().getEndpointInfo().getAddress();
                String apiDocs = serverAddress + "/api-docs";
                URL url = new URL(apiDocs + apiPath);
                in = url.openStream();
                res = res + getStringFromInputStream(in);
            }
        }
        generateJson(resourceClasses, res);
    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } finally {
        server.stop();
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Server(org.apache.cxf.endpoint.Server) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) SwaggerFeature(io.fabric8.cxf.endpoint.SwaggerFeature) Feature(org.apache.cxf.feature.Feature) URL(java.net.URL) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) SwaggerFeature(io.fabric8.cxf.endpoint.SwaggerFeature)

Example 3 with Server

use of org.apache.cxf.endpoint.Server in project fabric8 by jboss-fuse.

the class EnableJMXFeature method initialize.

@Override
public void initialize(Bus bus) {
    List<Server> servers = new ArrayList<Server>();
    ServerRegistry serverRegistry = bus.getExtension(ServerRegistry.class);
    servers.addAll(serverRegistry.getServers());
    for (Iterator<Server> iter = servers.iterator(); iter.hasNext(); ) {
        Server server = (Server) iter.next();
        ManagedApi mApi = new ManagedApi(bus, server.getEndpoint(), server);
        InstrumentationManager iMgr = bus.getExtension(InstrumentationManager.class);
        if (iMgr == null) {
            iMgr = new InstrumentationManagerImpl(bus);
        }
        ((InstrumentationManagerImpl) iMgr).setUsePlatformMBeanServer(true);
        ((InstrumentationManagerImpl) iMgr).setCreateMBServerConnectorFactory(false);
        ((InstrumentationManagerImpl) iMgr).setEnabled(true);
        ((InstrumentationManagerImpl) iMgr).init();
        if (iMgr != null) {
            try {
                iMgr.register(mApi);
            } catch (JMException jmex) {
                jmex.printStackTrace();
                LOG.log(Level.WARNING, "Registering ManagedApi failed.", jmex);
            }
        }
    }
}
Also used : InstrumentationManagerImpl(org.apache.cxf.management.jmx.InstrumentationManagerImpl) Server(org.apache.cxf.endpoint.Server) ArrayList(java.util.ArrayList) JMException(javax.management.JMException) ServerRegistry(org.apache.cxf.endpoint.ServerRegistry) InstrumentationManager(org.apache.cxf.management.InstrumentationManager)

Example 4 with Server

use of org.apache.cxf.endpoint.Server in project fabric8 by jboss-fuse.

the class ManagedApiFeature method initializeProvider.

@Override
protected void initializeProvider(InterceptorProvider provider, final Bus bus) {
    if (provider instanceof Endpoint) {
        EndpointImpl endpointImpl = (EndpointImpl) provider;
        List<Feature> features = endpointImpl.getActiveFeatures();
        if (features == null) {
            features = new ArrayList<Feature>();
            features.add(this);
            endpointImpl.initializeActiveFeatures(features);
        } else {
            features.add(this);
        }
    } else if (provider instanceof Bus) {
        FactoryBeanListenerManager factoryBeanListenerManager = bus.getExtension(FactoryBeanListenerManager.class);
        if (factoryBeanListenerManager == null) {
            factoryBeanListenerManager = new FactoryBeanListenerManager(bus);
        }
        factoryBeanListenerManager.addListener(new FactoryBeanListener() {

            @Override
            public void handleEvent(Event arg0, AbstractServiceFactoryBean arg1, Object... arg2) {
                if (arg0.equals(Event.SERVER_CREATED) && (arg2[0] instanceof Server)) {
                    Server server = (Server) arg2[0];
                    initialize(server, bus);
                }
            }
        });
    } else {
        List<Feature> features = (List<Feature>) bus.getFeatures();
        if (features == null) {
            features = new ArrayList<Feature>();
            features.add(this);
        } else {
            features.add(this);
        }
    }
}
Also used : AbstractServiceFactoryBean(org.apache.cxf.service.factory.AbstractServiceFactoryBean) Bus(org.apache.cxf.Bus) MBeanServer(javax.management.MBeanServer) Server(org.apache.cxf.endpoint.Server) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) ArrayList(java.util.ArrayList) Feature(org.apache.cxf.feature.Feature) AbstractFeature(org.apache.cxf.feature.AbstractFeature) FactoryBeanListenerManager(org.apache.cxf.service.factory.FactoryBeanListenerManager) Endpoint(org.apache.cxf.endpoint.Endpoint) ArrayList(java.util.ArrayList) List(java.util.List) FactoryBeanListener(org.apache.cxf.service.factory.FactoryBeanListener)

Example 5 with Server

use of org.apache.cxf.endpoint.Server in project tesb-rt-se by Talend.

the class ApplicationServer method startApplication.

private static Server startApplication(Application app) {
    RuntimeDelegate delegate = RuntimeDelegate.getInstance();
    JAXRSServerFactoryBean bean = delegate.createEndpoint(app, JAXRSServerFactoryBean.class);
    bean.setAddress("http://localhost:8080" + bean.getAddress());
    bean.setStart(false);
    Server server = bean.create();
    JettyHTTPDestination dest = (JettyHTTPDestination) server.getDestination();
    JettyHTTPServerEngine engine = (JettyHTTPServerEngine) dest.getEngine();
    engine.setSessionSupport(true);
    server.start();
    return server;
}
Also used : Server(org.apache.cxf.endpoint.Server) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) JettyHTTPServerEngine(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine) JettyHTTPDestination(org.apache.cxf.transport.http_jetty.JettyHTTPDestination) RuntimeDelegate(javax.ws.rs.ext.RuntimeDelegate)

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