Java Code Examples for org.apache.cxf.endpoint.Server

The following are top voted examples for showing how to use org.apache.cxf.endpoint.Server. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: jwala   File: WebServiceConfig.java   View source code 6 votes vote down vote up
@Bean
public Server getJaxRestServer(final GroupServiceRest groupServiceRest, final JvmServiceRest jvmServiceRest) {
    final JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();

    factory.setAddress("/v2.0");

    final List<Object> serviceBeans = new ArrayList<>();
    serviceBeans.add(groupServiceRest);
    serviceBeans.add(jvmServiceRest);
    factory.setServiceBeans(serviceBeans);

    List<Object> providers = new ArrayList<>();
    providers.add(getJacksonJsonProvider());
    providers.add(getInternalServerErrorHandler());
    factory.setProviders(providers);
    return factory.create();
}
 
Example 2
Project: oasp-tutorial-sources   File: ServiceConfig.java   View source code 6 votes vote down vote up
@Bean
public Server jaxRsServer() {

  // List<Object> restServiceBeans = new
  // ArrayList<>(this.applicationContext.getBeansOfType(RestService.class).values());
  Collection<Object> restServices = findRestServices();
  if (restServices.isEmpty()) {
    LOG.info("No REST Services have been found. Rest Endpoint will not be enabled in CXF.");
    return null;
  }
  Collection<Object> providers = this.applicationContext.getBeansWithAnnotation(Provider.class).values();

  JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
  factory.setBus(springBus());
  factory.setAddress(URL_FOLDER_REST);
  // factory.set
  factory.setServiceBeans(new ArrayList<>(restServices));
  factory.setProviders(new ArrayList<>(providers));

  return factory.create();
}
 
Example 3
Project: steve-plugsurfing   File: MediatorInInterceptor.java   View source code 6 votes vote down vote up
/**
 * Iterate over all available servers registered on the bus and build a map
 * consisting of (namespace, server) pairs for later lookup, so we can
 * redirect to the version-specific implementation according to the namespace
 * of the incoming message.
 */
private void initServerLookupMap(SoapMessage message) {
    Bus bus = message.getExchange().getBus();

    ServerRegistry serverRegistry = bus.getExtension(ServerRegistry.class);
    if (serverRegistry == null) {
        return;
    }

    List<Server> temp = serverRegistry.getServers();
    for (Server server : temp) {
        EndpointInfo info = server.getEndpoint().getEndpointInfo();
        String address = info.getAddress();

        // exclude the 'dummy' routing server
        if (CONFIG.getRouterEndpointPath().equals(address)) {
            continue;
        }

        String serverNamespace = info.getName().getNamespaceURI();
        actualServers.put(serverNamespace, server);
    }
}
 
Example 4
Project: microbule   File: DefaultJaxrsServerFactory.java   View source code 6 votes vote down vote up
@Override
public JaxrsServer createJaxrsServer(Class<?> serviceInterface, Object serviceImplementation) {
    final String serviceName = namingStrategy.get().serviceName(serviceInterface);
    final Config serverConfig = configService.createServerConfig(serviceInterface, serviceName);
    final String baseAddress = serverConfig.value(BASE_ADDRESS_PROP).orElse(StringUtils.EMPTY);
    final String serverAddress = serverConfig.value(SERVER_ADDRESS_PROP).orElse(namingStrategy.get().serverAddress(serviceInterface));
    final String fullAddress = baseAddress + serverAddress;
    LOGGER.info("Starting {} JAX-RS server ({})...", serviceInterface.getSimpleName(), fullAddress);

    final DefaultJaxrsServiceDescriptor descriptor = new DefaultJaxrsServiceDescriptor(serviceInterface, serviceName);
    decorate(descriptor, serverConfig);
    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setBus(BusFactory.getDefaultBus(true));
    sf.setServiceBean(serviceImplementation);

    sf.setAddress(fullAddress);
    sf.setFeatures(descriptor.getFeatures());
    sf.setProviders(descriptor.getProviders());
    final Server server = sf.create();
    LOGGER.info("Successfully started {} JAX-RS server ({}).", serviceInterface.getSimpleName(), serverAddress);
    return server::destroy;
}
 
Example 5
Project: metasfresh-procurement-webui   File: SyncConfiguration.java   View source code 6 votes vote down vote up
@Bean
public Server serverEndPoint(final SpringBus bus)
{
	final JacksonJaxbJsonProvider jacksonJaxbJsonProvider = new JacksonJaxbJsonProvider();

	final JMSConfigFeature jmsConfigFeature = createJMSConfigFeature();

	final JAXRSServerFactoryBean svrFactory = new JAXRSServerFactoryBean();
	svrFactory.setBus(bus);
	svrFactory.setResourceClasses(AgentSync.class);

	svrFactory.getFeatures().add(jmsConfigFeature);
	svrFactory.getFeatures().add(loggingFeature);

	svrFactory.setProvider(jacksonJaxbJsonProvider);
	svrFactory.setAddress("/");
	svrFactory.setTransportId("http://cxf.apache.org/transports/jms");

	final Server server = svrFactory.create();
	return server;
}
 
Example 6
Project: restful-api-cxf-spring-java   File: CxfConfig.java   View source code 6 votes vote down vote up
@Bean
  @DependsOn("cxf")
  public Server jaxRsServer() {
      JAXRSServerFactoryBean serverFactory = RuntimeDelegate.getInstance().createEndpoint(jaxRsApiApplication(), JAXRSServerFactoryBean.class);
      
      //factory.setServiceBean(new DenialCategoryRest());
      
// get all the class annotated with @JaxrsService
      List<Object> beans = configUtil.findBeans( JaxrsService.class );

if (beans.size() > 0) {
	
	// add all the CXF service classes into the CXF stack
	serverFactory.setServiceBeans( beans );
	serverFactory.setAddress("/"+ serverFactory.getAddress());
	serverFactory.setBus(springBus);
	serverFactory.setStart(true);
	
	// set JSON as the response serializer
	JacksonJsonProvider provider = new JacksonJsonProvider();
	serverFactory.setProvider(provider);
       
}
      
return serverFactory.create();
  }
 
Example 7
Project: Camel   File: PayLoadDataFormatFeature.java   View source code 6 votes vote down vote up
@Override
public void initialize(Server server, Bus bus) {
    server.getEndpoint().put("org.apache.cxf.binding.soap.addNamespaceContext", "true");
    server.getEndpoint().getBinding().getInInterceptors().add(new ConfigureDocLitWrapperInterceptor(true));
    if (server.getEndpoint().getBinding() instanceof SoapBinding) {
        server.getEndpoint().getBinding().getOutInterceptors().add(new SetSoapVersionInterceptor());
    }
    // Need to remove some interceptors that are incompatible
    // See above.
    removeInterceptor(server.getEndpoint().getInInterceptors(), 
                      HolderInInterceptor.class);
    removeInterceptor(server.getEndpoint().getOutInterceptors(), 
                      HolderOutInterceptor.class);
    removeInterceptor(server.getEndpoint().getBinding().getInInterceptors(), 
                      SoapHeaderInterceptor.class);
    resetPartTypes(server.getEndpoint().getBinding());

    LOG.info("Initialized CXF Server: {} in Payload mode with allow streaming: {}", server, allowStreaming);
}
 
Example 8
Project: kc-rice   File: AbstractWebServiceExporter.java   View source code 6 votes vote down vote up
/** 
 * This determines if the service has already been published on the CXF bus.
 * 
 * @return true if cxf server exists for this service.
 */
protected boolean isServicePublished(String serviceAddress) {
	
	ServerRegistry serverRegistry = getCXFServerRegistry();
	List<Server> servers = serverRegistry.getServers();
	
	for (Server server:servers){		
		String endpointAddress = server.getEndpoint().getEndpointInfo().getAddress();
		if (endpointAddress.contains(serviceAddress)){
			LOG.info("Service already published on CXF, not republishing: " + serviceAddress);
			return true;
		}
	}
	
	return false;
}
 
Example 9
Project: camelinaction2   File: RestOrderServer.java   View source code 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    // create dummy backend
    DummyOrderService dummy = new DummyOrderService();
    dummy.setupDummyOrders();

    // create CXF REST service and inject the dummy backend
    RestOrderService rest = new RestOrderService();
    rest.setOrderService(dummy);

    // setup Apache CXF REST server on port 9000
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(RestOrderService.class);
    sf.setResourceProvider(RestOrderService.class, new SingletonResourceProvider(rest));
    sf.setAddress("http://localhost:9000/");

    // create and start the CXF server (non blocking)
    Server server = sf.create();
    server.start();

    // keep the JVM running
    Console console = System.console();
    System.out.println("Server started on http://localhost:9000/");
    System.out.println("");

    // If you run the main class from IDEA/Eclipse then you may not have a console, which is null)
    if (console != null) {
        System.out.println("  Press ENTER to stop server");
        console.readLine();
    } else {
        System.out.println("  Stopping after 5 minutes or press ctrl + C to stop");
        Thread.sleep(5 * 60 * 1000);
    }

    // stop CXF server
    server.stop();
    System.exit(0);
}
 
Example 10
Project: metasfresh   File: JaxRsSpringEndpointTests.java   View source code 6 votes vote down vote up
private void performJmsTransportTest(final String springBeanXml) throws IOException, URISyntaxException, Exception
{
	final BrokerService broker = setupJmsBroker();

	//
	// now we get the jax-rs endpoint from the xml config
	try (ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { springBeanXml }))
	{
		final JAXRSServerFactoryBean sfb = (JAXRSServerFactoryBean)ctx.getBean("jaxrs:server:jms");

		final Server server = sfb.getServer();
		assertThat(server, notNullValue()); // it's important that we can obtain the server bean
		assertThat(server.isStarted(), is(true)); // for all we care, we could also start the server, but we need to know if we have to or not

		runJmsClient();

		server.destroy();
		assertThat(server.isStarted(), is(false));
	}
	finally
	{
		broker.stop();
	}
}
 
Example 11
Project: metasfresh   File: JaxRsProgramaticTests.java   View source code 6 votes vote down vote up
@Test
public void testServerWithJmsTransport() throws Exception
{
	final BrokerService jmsBroker = setupJmsBroker();
	try
	{
		final List<Class<?>> providers = Arrays.asList(TestService.class, TestService2.class);

		final Server server = createServer(providers);

		assertThat(server, notNullValue()); // it's important that we can obtain the server bean
		assertThat(server.isStarted(), is(true)); // for all we care, we could also start the server, but we need to know if we have to or not

		runJmsClient();

		server.destroy();
		assertThat(server.isStarted(), is(false));
	}
	finally
	{
		jmsBroker.stop();
	}
}
 
Example 12
Project: cxf-plus   File: CXFTestBase.java   View source code 6 votes vote down vote up
/**
 * 使用客户端代理调用
 * @param bean
 * @param intf
 * @param method
 * @param params
 * @return
 * @throws Exception
 */
protected Object invokeJaxWsMethod(Object bean, Class<?> intf, String method,Object... params) throws Exception {
	Assert.isTrue(Boolean.valueOf(intf.isInterface()), "The input class " + intf.getClass() + " is not an interface!");
	List<Class<?>> list = new ArrayList<Class<?>>();
	for (Object pobj : params) {
		list.add(pobj==null?null:pobj.getClass());
	}
	MethodEx me = BeanUtils.getCompatibleMethod(intf,method, list.toArray(new Class[list.size()]));
	Assert.notNull(me,"The Method "+method+" with "+params.length+" params was not found");
	//开始发布
	Server server = createLocalJaxWsService(intf, bean);
	//创建客户端并运行
	try{
		String url = "local://" + intf.getName();
		Object client=jaxwsPlus.createProxy(url, intf);
		Object result=me.invoke(client, params);
		return result;
	}finally{
		server.destroy();
	}
}
 
Example 13
Project: cxf-plus   File: CXFTestBase.java   View source code 6 votes vote down vote up
/**
 * 使用客户端代理调用
 * @param bean
 * @param intf
 * @param method
 * @param params
 * @return
 * @throws Exception
 */
protected  Object[]  invokeRpcMethod(Object bean, Class<?> intf, String method,Object... params) throws Exception {
	Assert.isTrue(Boolean.valueOf(intf.isInterface()), "The input class " + intf.getClass() + " is not an interface!");
	List<Class<?>> list = new ArrayList<Class<?>>();
	for (Object pobj : params) {
		list.add(pobj==null?null:pobj.getClass());
	}
	//开始发布
	Server server = createLocalService(intf, bean);
	//创建客户端并运行
	try{
		String url = "local://" + intf.getName();
		Client client=rpcPlus.createClient(url, intf);
		 Object[]  result=client.invoke(method, params);
		return result;
	}finally{
		server.destroy();
	}
}
 
Example 14
Project: cxf-plus   File: CXFTestBase.java   View source code 6 votes vote down vote up
/**
	 * 构造服务,注意要自己释放
	 * @param intf
	 * @param bean
	 * @return
	 */
	private Server createLocalJaxWsService(Class<?> intf, Object bean) {
		String url = "local://" + intf.getName();
		ServiceDefinition ws = getFactory().processServiceDef(new ServiceDefinition(intf.getSimpleName(),intf,bean));
		if (ws == null)
			return null;
		JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean(new CXFPlusServiceFactoryBean());
		sf.setAddress(url);
		sf.setServiceBean(ws.getServiceBean());
		sf.setServiceClass(ws.getServiceClass());
		if (printTrace()){
			sf.getInInterceptors().add(new LoggingInInterceptor());
			sf.getOutInterceptors().add(new LoggingOutInterceptor());
//			sf.getHandlers().add(TraceHandler.getSingleton());
		}
		Server server = sf.create();
		return server;
	}
 
Example 15
Project: cxf-plus   File: CXFTestBase.java   View source code 6 votes vote down vote up
/**
 * 构造服务,注意要自己释放
 * @param intf
 * @param bean
 * @return
 */
private Server createLocalService(Class<?> intf, Object bean) {
	String url = "local://" + intf.getName();
	ServiceDefinition ws = getFactory().processServiceDef(new ServiceDefinition(intf.getSimpleName(), intf, bean));
	if (ws == null)
		return null;
	ServerFactoryBean sf = new ServerFactoryBean(new CXFPlusServiceBean());
	sf.setAddress(url);
	sf.setServiceBean(ws.getServiceBean());
	sf.setServiceClass(ws.getServiceClass());
	if (printTrace()){
		sf.getInInterceptors().add(new LoggingInInterceptor());
		sf.getOutInterceptors().add(new LoggingOutInterceptor());
	}
	Server server = sf.create();
	return server;
}
 
Example 16
Project: mqnaas   File: RESTAPIProvider.java   View source code 6 votes vote down vote up
@Override
public boolean unpublish(ICapability capability, Class<? extends ICapability> interfaceToUnPublish) {
	Pair<ICapability, Class<? extends ICapability>> key = new ImmutablePair<ICapability, Class<? extends ICapability>>(capability,
			interfaceToUnPublish);
	Server server = servers.get(key);

	boolean unpublished = false;

	if (server != null) {
		String addr = server.getEndpoint().getEndpointInfo().getAddress();
		server.destroy();
		servers.remove(key);

		unpublished = true;

		// System.out.println("Unpublished from " + addr);
		log.debug("Unpublished {} at {}", interfaceToUnPublish, addr);
	}

	return unpublished;
}
 
Example 17
Project: rice   File: AbstractWebServiceExporter.java   View source code 6 votes vote down vote up
/** 
 * This determines if the service has already been published on the CXF bus.
 * 
 * @return true if cxf server exists for this service.
 */
protected boolean isServicePublished(String serviceAddress) {
	
	ServerRegistry serverRegistry = getCXFServerRegistry();
	List<Server> servers = serverRegistry.getServers();
	
	for (Server server:servers){		
		String endpointAddress = server.getEndpoint().getEndpointInfo().getAddress();
		if (endpointAddress.contains(serviceAddress)){
			LOG.info("Service already published on CXF, not republishing: " + serviceAddress);
			return true;
		}
	}
	
	return false;
}
 
Example 18
Project: cxf-rt-transports-zeromq   File: ZMQConduitTest.java   View source code 6 votes vote down vote up
@Test
public void testDecoupledEndpoint() throws Exception {

    JaxWsServerFactoryBean serverFactory = new JaxWsServerFactoryBean();
    serverFactory.setAddress("zmq:(tcp://*:" + ZMQ_TEST_PORT + "?socketOperation=bind&socketType=pull)");
    serverFactory.setServiceClass(HelloWorldImpl.class);
    Server server = serverFactory.create();

    JaxWsProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean();
    clientFactory.setServiceClass(HelloWorldPortType.class);
    clientFactory.setAddress("zmq:(tcp://localhost:" + ZMQ_TEST_PORT + "?socketOperation=connect&socketType=push)");
    clientFactory.getFeatures().add(new WSAddressingFeature());

    HelloWorldPortType client = (HelloWorldPortType) clientFactory.create();

    ClientProxy.getClient(client).getEndpoint()
                                 .getEndpointInfo()
                                 .setProperty("org.apache.cxf.ws.addressing.replyto",
                                              "zmq:(tcp://127.0.0.1:5555?socketOperation=connect&socketType=push)");

    String reply = client.sayHello("Claude");

    server.stop();

    assertEquals("Hello Claude", reply);
}
 
Example 19
Project: cxf-rt-transports-zeromq   File: ZMQDestinationTest.java   View source code 6 votes vote down vote up
@Test
public void testConfigurationFromAPI() throws Exception {

    JaxWsServerFactoryBean bean = new JaxWsServerFactoryBean();
    bean.setAddress("zmq:(tcp://*:" + ZMQ_TEST_PORT + "?socketOperation=bind&socketType=rep)");
    bean.setServiceClass(HelloWorldImpl.class);
    Server server = bean.create();

    ZMQ.Socket zmqSocket = zmqContext.socket(ZMQ.REQ);
    zmqSocket.connect("tcp://localhost:" + ZMQ_TEST_PORT);
    zmqSocket.send(FileUtils.readFileToString(new File(getClass().getResource("/samples/soap-request.xml").toURI())).getBytes(), 0);
    byte[] reply = zmqSocket.recv(0);
    zmqSocket.close();

    server.stop();

    XMLAssert.assertXMLEqual(FileUtils.readFileToString(new File(getClass().getResource("/samples/soap-reply.xml").toURI())), new String(reply));
}
 
Example 20
Project: cxf-rt-transports-zeromq   File: ZMQDestinationTest.java   View source code 6 votes vote down vote up
@Test
public void testConfigurationFromWSDL() throws Exception {
    JaxWsServerFactoryBean bean = new JaxWsServerFactoryBean();
    bean.setWsdlLocation("/wsdl/zmq_test.wsdl");
    bean.setServiceClass(HelloWorldImpl.class);
    Server server = bean.create();

    ZMQ.Socket zmqSocket = zmqContext.socket(ZMQ.REQ);
    zmqSocket.connect("tcp://localhost:" + ZMQ_TEST_PORT);
    zmqSocket.send(FileUtils.readFileToString(new File(getClass().getResource("/samples/soap-request.xml").toURI())).getBytes(), 0);
    byte[] reply = zmqSocket.recv(0);
    zmqSocket.close();

    server.stop();

    XMLAssert.assertXMLEqual(FileUtils.readFileToString(new File(getClass().getResource("/samples/soap-reply.xml").toURI())), new String(reply));
}
 
Example 21
Project: kuali_rice   File: AbstractWebServiceExporter.java   View source code 6 votes vote down vote up
/** 
 * This determines if the service has already been published on the CXF bus.
 * 
 * @return true if cxf server exists for this service.
 */
protected boolean isServicePublished(String serviceAddress) {
	
	ServerRegistry serverRegistry = getCXFServerRegistry();
	List<Server> servers = serverRegistry.getServers();
	
	for (Server server:servers){		
		String endpointAddress = server.getEndpoint().getEndpointInfo().getAddress();
		if (endpointAddress.contains(serviceAddress)){
			LOG.info("Service already published on CXF, not republishing: " + serviceAddress);
			return true;
		}
	}
	
	return false;
}
 
Example 22
Project: dropwizard-jaxws   File: JAXWSEnvironmentTest.java   View source code 6 votes vote down vote up
@Test
public void publishEndpointWithPublishedUrlPrefix() throws WSDLException {

    jaxwsEnvironment.setPublishedEndpointUrlPrefix("http://external/prefix");

    jaxwsEnvironment.publishEndpoint(
            new EndpointBuilder("/path", service)
    );

    verify(mockInvokerBuilder).create(any(), any(Invoker.class));
    verifyZeroInteractions(mockUnitOfWorkInvokerBuilder);

    Server server = testutils.getServerForAddress("/path");
    AbstractDestination destination = (AbstractDestination) server.getDestination();
    String publishedEndpointUrl = destination.getEndpointInfo().getProperty(WSDLGetUtils.PUBLISHED_ENDPOINT_URL, String.class);

    assertThat(publishedEndpointUrl, equalTo("http://external/prefix/path"));
}
 
Example 23
Project: fuchsia   File: ProtobufferExporter.java   View source code 6 votes vote down vote up
@Override
protected void denyExportDeclaration(ExportDeclaration exportDeclaration) throws BinderException {

    ProtobufferExportDeclarationWrapper pojo = ProtobufferExportDeclarationWrapper.create(exportDeclaration);

    Server server = serverPublished.get(pojo.getId());

    serverPublished.remove(pojo.getId());

    if (server != null) {
        LOG.info("Destroying endpoint:" + server.getEndpoint().getEndpointInfo().getAddress());
        server.destroy();
    } else {
        LOG.warn("no endpoint to destroy");
    }

}
 
Example 24
Project: steve   File: MediatorInInterceptor.java   View source code 6 votes vote down vote up
/**
 * Iterate over all available servers registered on the bus and build a map
 * consisting of (namespace, server) pairs for later lookup, so we can
 * redirect to the version-specific implementation according to the namespace
 * of the incoming message.
 */
private void initServerLookupMap(SoapMessage message) {
    Bus bus = message.getExchange().getBus();

    ServerRegistry serverRegistry = bus.getExtension(ServerRegistry.class);
    if (serverRegistry == null) {
        return;
    }

    List<Server> temp = serverRegistry.getServers();
    for (Server server : temp) {
        EndpointInfo info = server.getEndpoint().getEndpointInfo();
        String address = info.getAddress();

        // exclude the 'dummy' routing server
        if (CONFIG.getRouterEndpointPath().equals(address)) {
            continue;
        }

        String serverNamespace = info.getName().getNamespaceURI();
        actualServers.put(serverNamespace, server);
    }
}
 
Example 25
Project: dss-demonstrations   File: CXFConfig.java   View source code 5 votes vote down vote up
@Bean
public Server createServerValidationRestService() {
	JAXRSServerFactoryBean sfb = new JAXRSServerFactoryBean();
	sfb.setServiceBean(restValidationService());
	sfb.setAddress(REST_VALIDATION);
	sfb.setProvider(jacksonJsonProvider());
	return sfb.create();
}
 
Example 26
Project: dss-demonstrations   File: CXFConfig.java   View source code 5 votes vote down vote up
@Bean
public Server createServerSigningRestService() {
	JAXRSServerFactoryBean sfb = new JAXRSServerFactoryBean();
	sfb.setServiceBean(restServerSigningService());
	sfb.setAddress(REST_SERVER_SIGNING);
	sfb.setProvider(jacksonJsonProvider());
	return sfb.create();
}
 
Example 27
Project: dss-demonstrations   File: CXFConfig.java   View source code 5 votes vote down vote up
@Bean
public Server createOneDocumentSignatureRestService() {
	JAXRSServerFactoryBean sfb = new JAXRSServerFactoryBean();
	sfb.setServiceBean(restSignatureService());
	sfb.setAddress(REST_SIGNATURE_ONE_DOCUMENT);
	sfb.setProvider(jacksonJsonProvider());
	return sfb.create();
}
 
Example 28
Project: dss-demonstrations   File: CXFConfig.java   View source code 5 votes vote down vote up
@Bean
public Server createMultipleDocumentRestService() {
	JAXRSServerFactoryBean sfb = new JAXRSServerFactoryBean();
	sfb.setServiceBean(restMultipleDocumentsSignatureService());
	sfb.setAddress(REST_SIGNATURE_MULTIPLE_DOCUMENTS);
	sfb.setProvider(jacksonJsonProvider());
	return sfb.create();
}
 
Example 29
Project: jwala   File: AemWebServiceConfiguration.java   View source code 5 votes vote down vote up
@Bean
public Server getV1JaxResServer() {
    final JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
    factory.setAddress("/v1.0");
    factory.setServiceBeans(getV1ServiceBeans());
    factory.setProviders(getV1Providers());
    return factory.create();
}
 
Example 30
Project: microservices-transactions-tcc   File: WebServicesConfiguration.java   View source code 5 votes vote down vote up
@Bean
public Server rsServer() {
    JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
    endpoint.setBus(bus);
    endpoint.setAddress("/");
    endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new ExceptionRestHandler()));
    
    Map<Object, Object> mappings = new HashMap<Object, Object>();
    mappings.put("json", "application/json");
    endpoint.setExtensionMappings(mappings);
    
    Swagger2Feature swagger2Feature = new Swagger2Feature();
    swagger2Feature.setTitle(title);
    swagger2Feature.setDescription(description);
    swagger2Feature.setVersion(version);
    swagger2Feature.setContact(contact);
    swagger2Feature.setSchemes(schemes.split(","));
    swagger2Feature.setBasePath(basePath);
    swagger2Feature.setResourcePackage(resourcePackage);
    swagger2Feature.setPrettyPrint(prettyPrint);
    swagger2Feature.setScan(scan);
    
    endpoint.setFeatures(Arrays.asList(new LoggingFeature(), swagger2Feature));
    endpoint.setServiceBeans(Arrays.asList(tccCoordinatorService, compositeController));
    
    return endpoint.create();
}
 
Example 31
Project: spring-boot-cxf-jaxrs   File: SampleRestApplication.java   View source code 5 votes vote down vote up
@Bean
public Server rsServer() {
    // setup CXF-RS
    JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
    endpoint.setBus(bus);
    endpoint.setServiceBeans(Arrays.<Object>asList(new HelloServiceImpl()));
    endpoint.setAddress("/");
    endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));
    return endpoint.create();
}
 
Example 32
Project: restful-api-cxf-spring-java   File: CxfTestConfig.java   View source code 5 votes vote down vote up
@Bean
  @DependsOn("cxf")
  public Server jaxRsServer() {
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
// sf.setResourceClasses( MyJaxrsResource.class );

List<Object> providers = new ArrayList<Object>();
// add custom providers if any
sf.setProviders(providers);

// factory.setServiceBean(new DenialCategoryRest());

// get all the class annotated with @JaxrsService
List<Object> beans = configUtil.findBeans(JaxrsService.class);
// List<Class> beansClasses = configUtil.findClasses( JaxrsService.class
// );

if (beans.size() > 0) {

	// add all the CXF service classes into the CXF stack
	//sf.setResourceClasses(UserRestImpl.class);
	sf.setServiceBeans(beans);
	sf.setAddress("http://localhost:8080/api");
	sf.setBus(springBus);
	sf.setStart(true);

	// set JSON as the response serializer
	JacksonJsonProvider provider = new JacksonJsonProvider();
	sf.setProvider(provider);

}

return sf.create();
  }
 
Example 33
Project: product-ei   File: AppConfig.java   View source code 5 votes vote down vote up
@Bean
public Server jaxRsServer() {
    JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint( jaxRsApiApplication(), JAXRSServerFactoryBean.class );
    factory.setServiceBeans( Arrays.< Object >asList( peopleRestService() ) );
    factory.setAddress( "/" + factory.getAddress() );
    factory.setProviders( Arrays.< Object >asList( jsonProvider() ) );
    return factory.create();
}
 
Example 34
Project: product-ei   File: MusicConfig.java   View source code 5 votes vote down vote up
@Bean
public Server jaxRsServer() {
    JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint( jaxRsApiApplication(), JAXRSServerFactoryBean.class );
    factory.setServiceBeans( Arrays.< Object >asList(musicRestService()) );
    factory.setAddress( "/" + factory.getAddress() );
    factory.setProviders( Arrays.< Object >asList( jsonProvider() ) );
    return factory.create();
}
 
Example 35
Project: aries-jax-rs-whiteboard   File: CXFJaxRsServiceRegistrator.java   View source code 5 votes vote down vote up
public <T> T createEndpoint(Application app, Class<T> endpointType) {
    JAXRSServerFactoryBean bean =
        RuntimeDelegate.getInstance().createEndpoint(
            app, JAXRSServerFactoryBean.class);

    if (JAXRSServerFactoryBean.class.isAssignableFrom(endpointType)) {
        return endpointType.cast(bean);
    }
    bean.setStart(false);
    Server server = bean.create();
    return endpointType.cast(server);
}
 
Example 36
Project: Camel   File: RAWDataFormatFeature.java   View source code 5 votes vote down vote up
@Override
public void initialize(Server server, Bus bus) {
    // currently we do not filter the bus
    // remove the interceptors

    removeInterceptorWhichIsOutThePhases(server.getEndpoint().getService().getInInterceptors(), REMAINING_IN_PHASES, getInInterceptorNames());
    removeInterceptorWhichIsOutThePhases(server.getEndpoint().getInInterceptors(), REMAINING_IN_PHASES, getInInterceptorNames());

    
    //we need to keep the LoggingOutputInterceptor
    getOutInterceptorNames().add(LoggingOutInterceptor.class.getName());
    
    // Do not using the binding interceptor any more
    server.getEndpoint().getBinding().getInInterceptors().clear();

    removeInterceptorWhichIsOutThePhases(server.getEndpoint().getService().getOutInterceptors(), REMAINING_OUT_PHASES, getOutInterceptorNames());
    removeInterceptorWhichIsOutThePhases(server.getEndpoint().getOutInterceptors(), REMAINING_OUT_PHASES, getOutInterceptorNames());

    // Do not use the binding interceptor any more
    server.getEndpoint().getBinding().getOutInterceptors().clear();
    server.getEndpoint().getOutInterceptors().add(new RawMessageContentRedirectInterceptor());

    // setup the RawMessageWSDLGetInterceptor
    server.getEndpoint().getInInterceptors().add(RawMessageWSDLGetInterceptor.INSTANCE);
    // Oneway with RAW message
    if (isOneway()) {
        Interceptor<? extends Message> toRemove = null;
        for (Interceptor<? extends Message> i : server.getEndpoint().getService().getInInterceptors()) {
            if (i.getClass().getName().equals("org.apache.cxf.interceptor.OutgoingChainInterceptor")) {
                toRemove = i;
            }
        }
        server.getEndpoint().getService().getInInterceptors().remove(toRemove);
        server.getEndpoint().getInInterceptors().add(new OneWayOutgoingChainInterceptor());
        server.getEndpoint().getInInterceptors().add(new OneWayProcessorInterceptor());
    }
}
 
Example 37
Project: Camel   File: CxfEndpointTest.java   View source code 5 votes vote down vote up
@Test
public void testCxfEndpointConfigurer() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    CxfEndpointConfigurer configurer = EasyMock.createMock(CxfEndpointConfigurer.class);
    Processor processor = EasyMock.createMock(Processor.class);
    registry.put("myConfigurer", configurer);
    CamelContext camelContext = new DefaultCamelContext(registry);
    CxfComponent cxfComponent = new CxfComponent(camelContext);
    CxfEndpoint endpoint = (CxfEndpoint)cxfComponent.createEndpoint(routerEndpointURI + "&cxfEndpointConfigurer=#myConfigurer");

    configurer.configure(EasyMock.isA(AbstractWSDLBasedEndpointFactory.class));
    EasyMock.expectLastCall();
    configurer.configureServer(EasyMock.isA(Server.class));
    EasyMock.expectLastCall();
    EasyMock.replay(configurer);
    endpoint.createConsumer(processor);
    EasyMock.verify(configurer);

    EasyMock.reset(configurer);
    configurer.configure(EasyMock.isA(AbstractWSDLBasedEndpointFactory.class));
    EasyMock.expectLastCall();
    configurer.configureClient(EasyMock.isA(Client.class));
    EasyMock.expectLastCall();
    EasyMock.replay(configurer);
    Producer producer = endpoint.createProducer();
    producer.start();
    EasyMock.verify(configurer);

}
 
Example 38
Project: Camel   File: CxfPayLoadMessageXmlBindingRouterTest.java   View source code 5 votes vote down vote up
@BeforeClass
public static void startService() {       
    //start a service
    ServerFactoryBean svrBean = new ServerFactoryBean();

    svrBean.setAddress(SERVICE_ADDRESS);
    svrBean.setServiceClass(HelloService.class);
    svrBean.setServiceBean(new HelloServiceImpl());
    svrBean.setBindingId(getBindingId());

    Server server = svrBean.create();
    server.start();
}
 
Example 39
Project: myjavacode   File: WebServiceTaskTest.java   View source code 5 votes vote down vote up
/**
 * 独立启动WebService服务
 */
public static void main(String[] args) {
	Counter counter = new CounterImpl();
	JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
	svrFactory.setServiceClass(Counter.class);
	svrFactory.setAddress("http://localhost:12345/counter");
	svrFactory.setServiceBean(counter);
	svrFactory.getInInterceptors().add(new LoggingInInterceptor());
	svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
	Server server = svrFactory.create();
	server.start();
}
 
Example 40
Project: camelinaction2   File: RestOrderServer.java   View source code 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // create dummy backend
    DummyOrderService dummy = new DummyOrderService();
    dummy.setupDummyOrders();

    // create a Camel route that routes the REST services
    OrderRoute route = new OrderRoute();
    route.setOrderService(dummy);

    // create CamelContext and add the route
    CamelContext camel = new DefaultCamelContext();
    camel.addRoutes(route);

    // create a ProducerTemplate that the CXF REST service will use to integrate with Camel
    ProducerTemplate producer = camel.createProducerTemplate();

    // create CXF REST service and inject the Camel ProducerTemplate
    // which we use to call the Camel route
    RestOrderService rest = new RestOrderService();
    rest.setProducerTemplate(producer);

    // setup Apache CXF REST server on port 9000
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(RestOrderService.class);
    sf.setResourceProvider(RestOrderService.class, new SingletonResourceProvider(rest));
    // to use jackson for json
    sf.setProvider(JacksonJsonProvider.class);
    sf.setAddress("http://localhost:9000/");

    // create the CXF server
    Server server = sf.create();

    // start Camel and CXF (non blocking)
    camel.start();
    server.start();

    // keep the JVM running
    Console console = System.console();
    System.out.println("Server started on http://localhost:9000/");
    System.out.println("");

    // If you run the main class from IDEA/Eclipse then you may not have a console, which is null)
    if (console != null) {
        System.out.println("  Press ENTER to stop server");
        console.readLine();
    } else {
        System.out.println("  Stopping after 5 minutes or press ctrl + C to stop");
        Thread.sleep(5 * 60 * 1000);
    }

    // stop Camel and CXF server
    camel.stop();
    server.stop();
    System.exit(0);
}