org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet Java Examples
The following examples show how to use
org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Launcher.java From lucene-geo-gazetteer with Apache License 2.0 | 6 votes |
public static void launchService(int port, String indexPath) throws IOException, LifecycleException { Tomcat server = new Tomcat(); Context context = server.addContext("/", new File(".").getAbsolutePath()); System.setProperty(INDEX_PATH_PROP, indexPath); Wrapper servlet = context.createWrapper(); servlet.setName("CXFNonSpringJaxrs"); servlet.setServletClass(CXFNonSpringJaxrsServlet.class.getName()); servlet.addInitParameter("jaxrs.serviceClasses", SearchResource.class.getName() + " " + HealthCheckAPI.class.getName()); servlet.setLoadOnStartup(1); context.addChild(servlet); context.addServletMapping("/api/*", "CXFNonSpringJaxrs"); System.out.println("Starting Embedded Tomcat on port : " + port ); server.setPort(port); server.start(); server.getServer().await(); }
Example #2
Source File: NonSpringJaxrsServletBookServer2.java From cxf with Apache License 2.0 | 6 votes |
protected void run() { server = new org.eclipse.jetty.server.Server(Integer.parseInt(PORT)); final ServletHolder servletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet(new BookApplicationNonSpring())); final ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); context.addServlet(servletHolder, "/*"); //servletHolder.setInitParameter("jaxrs.serviceClasses", BookStore.class.getName()); server.setHandler(context); try { server.start(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Example #3
Source File: NonSpringJaxrsServletBookServer.java From cxf with Apache License 2.0 | 6 votes |
protected void run() { server = new org.eclipse.jetty.server.Server(Integer.parseInt(PORT)); final ServletHolder servletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet(new BookStoreOpenAPI())); final ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); context.addServlet(servletHolder, "/*"); //servletHolder.setInitParameter("jaxrs.serviceClasses", BookStore.class.getName()); servletHolder.setInitParameter("jaxrs.outInterceptors", LoggingOutInterceptor.class.getName()); servletHolder.setInitParameter("jaxrs.inInterceptors", LoggingInInterceptor.class.getName()); server.setHandler(context); try { server.start(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Example #4
Source File: RestApiSetup.java From brooklyn-server with Apache License 2.0 | 6 votes |
public static void installRest(ServletContextHandler context, Object... providers) { initSwagger(); BrooklynRestApp app = new BrooklynRestApp(); for (Object o : providers) { app.singleton(o); } CXFNonSpringJaxrsServlet servlet = new CXFNonSpringJaxrsServlet(app); servlet.setBus(BusFactory.newInstance().createBus()); servlet.getBus().getInInterceptors().add(new GZIPInInterceptor()); servlet.getBus().getInFaultInterceptors().add(new GZIPInInterceptor()); servlet.getBus().getOutInterceptors().add(new GZIPOutInterceptor()); final ServletHolder servletHolder = new ServletHolder(servlet); context.addServlet(servletHolder, "/v1/*"); }
Example #5
Source File: Server.java From cxf with Apache License 2.0 | 6 votes |
protected Server() throws Exception { org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(9000); final ServletHolder servletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet()); final ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); context.addServlet(servletHolder, "/*"); servletHolder.setInitParameter("jaxrs.serviceClasses", Sample.class.getName()); servletHolder.setInitParameter("jaxrs.features", OpenApiFeature.class.getName()); servletHolder.setInitParameter("jaxrs.providers", StringUtils.join( new String[] { MultipartProvider.class.getName(), JacksonJsonProvider.class.getName(), ApiOriginFilter.class.getName() }, ",") ); server.setHandler(context); server.start(); server.join(); }
Example #6
Source File: Server.java From cxf with Apache License 2.0 | 6 votes |
protected Server() throws Exception { org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(9000); // Register and map the dispatcher servlet final ServletHolder servletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet()); final ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); context.addServlet(servletHolder, "/*"); servletHolder.setInitParameter("javax.ws.rs.Application", CatalogApplication.class.getName()); server.setHandler(context); server.start(); server.join(); }
Example #7
Source File: Server.java From cxf with Apache License 2.0 | 6 votes |
protected Server() throws Exception { org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(9000); final ServletHolder servletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet()); final ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); context.addServlet(servletHolder, "/*"); servletHolder.setInitParameter("jaxrs.serviceClasses", Sample.class.getName()); servletHolder.setInitParameter("jaxrs.features", Swagger2Feature.class.getName()); servletHolder.setInitParameter("jaxrs.providers", StringUtils.join( new String[] { MultipartProvider.class.getName(), JacksonJsonProvider.class.getName(), ApiOriginFilter.class.getName() }, ",") ); server.setHandler(context); server.start(); server.join(); }
Example #8
Source File: ExplorerServer.java From Explorer with Apache License 2.0 | 5 votes |
private static ServletContextHandler setupRestApiContextHandler() { final ServletHolder cxfServletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet()); cxfServletHolder.setInitParameter("javax.ws.rs.Application", ExplorerServer.class.getName()); cxfServletHolder.setName("rest"); cxfServletHolder.setForcedPath("rest"); final ServletContextHandler cxfContext = new ServletContextHandler(); cxfContext.setSessionHandler(new SessionHandler()); cxfContext.setContextPath("/api"); cxfContext.addServlet(cxfServletHolder, "/*"); cxfContext.addFilter(new FilterHolder(CorsFilter.class), "/*", EnumSet.allOf(DispatcherType.class)); return cxfContext; }
Example #9
Source File: CxfServletRegister.java From lemonaid with MIT License | 5 votes |
@Bean public ServletRegistrationBean getODataServletRegistrationBean() { ServletRegistrationBean odataServletRegistrationBean = new ServletRegistrationBean(new CXFNonSpringJaxrsServlet(), "/odata.svc/*"); Map<String, String> initParameters = new HashMap<String, String>(); initParameters.put("javax.ws.rs.Application", "org.apache.olingo.odata2.core.rest.app.ODataApplication"); initParameters.put("org.apache.olingo.odata2.service.factory", "com.sap.mentors.lemonaid.odata.JPAServiceFactory"); odataServletRegistrationBean.setInitParameters(initParameters); return odataServletRegistrationBean; }
Example #10
Source File: CXFProvider.java From hammock with Apache License 2.0 | 5 votes |
@Produces @Dependent public ServletDescriptor cxfServlet(RestServerConfiguration restServerConfiguration) { String servletMapping = restServerConfiguration.getRestServletMapping(); List<WebInitParam> params = new ArrayList<>(); if(enableSseTransport) { params.add(new WebParam(CXFNonSpringJaxrsServlet.TRANSPORT_ID, SseHttpTransportFactory.TRANSPORT_ID)); } WebInitParam[] initParams = params.toArray(new WebInitParam[params.size()]); return new ServletDescriptor("CXF",null, new String[]{servletMapping},1, initParams,true,CXFCdiServlet.class); }
Example #11
Source File: AbstractUndertowServer.java From cxf with Apache License 2.0 | 5 votes |
protected void run() { try { final DeploymentInfo servletBuilder = deployment() .setClassLoader(AbstractUndertowServer.class.getClassLoader()) .setContextPath(contextPath) .setDeploymentName("sse-test") .addServlets( servlet("MessageServlet", CXFNonSpringJaxrsServlet.class) .addInitParam("jaxrs.providers", String.join(",", JacksonJsonProvider.class.getName(), BookStoreResponseFilter.class.getName())) .addInitParam("jaxrs.serviceClasses", BookStore.class.getName()) .setAsyncSupported(true) .setLoadOnStartup(1) .addMapping("/rest/*") ); final DeploymentManager manager = defaultContainer().addDeployment(servletBuilder); manager.deploy(); PathHandler path = Handlers .path(Handlers.redirect("/")) .addPrefixPath("/", manager.start()); server = Undertow.builder() .addHttpListener(port, "localhost") .setHandler(path) .build(); server.start(); } catch (final Exception ex) { ex.printStackTrace(); fail(ex.getMessage()); } }
Example #12
Source File: AbstractTomcatServer.java From cxf with Apache License 2.0 | 5 votes |
protected void run() { server = new Tomcat(); server.setPort(port); server.getConnector(); try { base = Files.createTempDirectory("tmp-"); server.setBaseDir(base.toString()); if (resourcePath == null) { final Context context = server.addContext("", base.toString()); final Wrapper cxfServlet = Tomcat.addServlet(context, "cxfServlet", new CXFNonSpringJaxrsServlet()); cxfServlet.addInitParameter("jaxrs.serviceClasses", BookStore.class.getName()); cxfServlet.addInitParameter("jaxrs.providers", String.join(",", JacksonJsonProvider.class.getName(), BookStoreResponseFilter.class.getName() )); cxfServlet.setAsyncSupported(true); context.addServletMappingDecoded("/rest/*", "cxfServlet"); } else { server.getHost().setAppBase(base.toString()); server.getHost().setAutoDeploy(true); server.getHost().setDeployOnStartup(true); server.addWebapp(contextPath, getClass().getResource(resourcePath).toURI().getPath().toString()); } server.start(); } catch (final Exception ex) { ex.printStackTrace(); fail(ex.getMessage()); } }
Example #13
Source File: StatsServer.java From cxf with Apache License 2.0 | 5 votes |
public static void main(final String[] args) throws Exception { final DeploymentInfo servletBuilder = deployment() .setClassLoader(StatsServer.class.getClassLoader()) .setContextPath("/") .setDeploymentName("sse-demo") .addServlets( servlet("MessageServlet", CXFNonSpringJaxrsServlet.class) .addInitParam("jaxrs.providers", JacksonJsonProvider.class.getName()) .addInitParam("jaxrs.serviceClasses", StatsRestServiceImpl.class.getName()) .setAsyncSupported(true) .setLoadOnStartup(1) .addMapping("/rest/*") ); final DeploymentManager manager = defaultContainer().addDeployment(servletBuilder); manager.deploy(); final PathHandler path = Handlers .path(Handlers.redirect("/")) .addPrefixPath("/", manager.start()); final Undertow server = Undertow.builder() .addHttpListener(8686, "localhost") .setHandler(path) .build(); server.start(); }
Example #14
Source File: Server.java From cxf with Apache License 2.0 | 5 votes |
protected Server() throws Exception { org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(9000); // Register and map the dispatcher servlet final ServletHolder servletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet()); final ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); context.addServlet(servletHolder, "/*"); servletHolder.setInitParameter("javax.ws.rs.Application", CatalogApplication.class.getName()); final Tracer tracer = new Configuration("tracer-server") .withSampler(new SamplerConfiguration().withType(ConstSampler.TYPE).withParam(1)) .withReporter(new ReporterConfiguration().withSender( new SenderConfiguration() { @Override public Sender getSender() { return new Slf4jLogSender(); } } )) .getTracer(); GlobalTracer.registerIfAbsent(tracer); server.setHandler(context); server.start(); server.join(); }
Example #15
Source File: Server.java From cxf with Apache License 2.0 | 5 votes |
protected Server() throws Exception { org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(9000); // Configuring all static web resource final ServletHolder staticHolder = new ServletHolder(new DefaultServlet()); // Register and map the dispatcher servlet final ServletHolder servletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet()); final ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); context.addServlet(staticHolder, "/static/*"); context.addServlet(servletHolder, "/*"); context.setResourceBase(getClass().getResource("/browser").toURI().toString()); servletHolder.setInitParameter("redirects-list", "/ /index.html /js/fileinput.min.js /css/fileinput.min.css"); servletHolder.setInitParameter("redirect-servlet-name", staticHolder.getName()); servletHolder.setInitParameter("redirect-attributes", "javax.servlet.include.request_uri"); servletHolder.setInitParameter("jaxrs.serviceClasses", Catalog.class.getName()); servletHolder.setInitParameter("jaxrs.properties", StringUtils.join( new String[] { "search.query.parameter.name=$filter", SearchUtils.DATE_FORMAT_PROPERTY + "=yyyy/MM/dd" }, " ") ); servletHolder.setInitParameter("jaxrs.providers", StringUtils.join( new String[] { MultipartProvider.class.getName(), SearchContextProvider.class.getName(), JsrJsonpProvider.class.getName(), CrossOriginResourceSharingFilter.class.getName() }, ",") ); server.setHandler(context); server.start(); server.join(); }
Example #16
Source File: ODataApplicationTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
private ServletContextHandler createContextHandler() { final CXFNonSpringJaxrsServlet odataServlet = new CXFNonSpringJaxrsServlet(); final ServletHolder odataServletHolder = new ServletHolder(odataServlet); odataServletHolder.setInitParameter("javax.ws.rs.Application", ODataApplication_.class.getName()); final ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS); contextHandler.addServlet(odataServletHolder, endpoint.getPath() + "/*"); return contextHandler; }
Example #17
Source File: VarOneServer.java From varOne with MIT License | 5 votes |
private static ServletContextHandler setupResourcesContextHandler( VarOneConfiguration conf) { final ServletHolder cxfServletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet()); cxfServletHolder.setInitParameter("javax.ws.rs.Application", VarOneServer.class.getName()); cxfServletHolder.setName("rest"); cxfServletHolder.setForcedPath("rest"); final ServletContextHandler cxfContext = new ServletContextHandler(); cxfContext.setSessionHandler(new SessionHandler()); cxfContext.setContextPath(conf.getServerContextPath()); cxfContext.addServlet(cxfServletHolder, "/rest/*"); return cxfContext; }
Example #18
Source File: CxfServletRegister.java From odata-boilerplate with MIT License | 5 votes |
@Bean public ServletRegistrationBean getODataServletRegistrationBean() { ServletRegistrationBean odataServletRegistrationBean = new ServletRegistrationBean(new CXFNonSpringJaxrsServlet(), "/odata.svc/*"); Map<String, String> initParameters = new HashMap<String, String>(); initParameters.put("javax.ws.rs.Application", "org.apache.olingo.odata2.core.rest.app.ODataApplication"); initParameters.put("org.apache.olingo.odata2.service.factory", "com.penninkhof.odata.utils.JPAServiceFactory"); odataServletRegistrationBean.setInitParameters(initParameters); return odataServletRegistrationBean; }
Example #19
Source File: RestOrderServer.java From camelinaction2 with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { // create dummy backend DummyOrderService dummy = new DummyOrderService(); dummy.setupDummyOrders(); // create rider order service with dummy backend RestOrderService orderService = new RestOrderService(); orderService.setOrderService(dummy); // create JAX-RS application with our rider order serivce RestOrderApplication app = new RestOrderApplication(orderService); // setup servlet holder with a CXF jax-rs servlet to handle the app Servlet servlet = new CXFNonSpringJaxrsServlet(app); ServletHolder holder = new ServletHolder(servlet); holder.setName("rider"); holder.setForcedPath("/"); ServletContextHandler context = new ServletContextHandler(); context.addServlet(holder, "/*"); // create and start the jetty server (non blocking) Server server = new Server(9000); server.setHandler(context); 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 jetty server server.stop(); System.exit(0); }
Example #20
Source File: RestApiSetup.java From brooklyn-server with Apache License 2.0 | 3 votes |
public static void install(ServletContextHandler context) { ScannerFactory.setScanner(new RestApiResourceScanner()); CampRestApp app = new CampRestApp(); CXFNonSpringJaxrsServlet servlet = new CXFNonSpringJaxrsServlet(app); final ServletHolder servletHolder = new ServletHolder(servlet); context.addServlet(servletHolder, "/*"); }