@Test public void testLocateMostRelevantConstructor() { ReflectionProvider rp = instance(ReflectionProvider.class); Providers providers = instance(Providers.class); ProviderFilter providerFilter = instance(ProviderFilter.class); Field f = rp.getField(JaxRsResolverTest.class, "genericField3"); RuntimeDelegate.setInstance(new DefaultRuntimeDelegate()); MessageBodyReader messageBodyReader = providers.getMessageBodyReader(f.getType(), f.getGenericType(), f.getAnnotations(), MediaType.APPLICATION_XML_TYPE); assertNotNull(messageBodyReader); assertEquals(PersonMessageBodyReader.class, messageBodyReader.getClass()); Constructor<?> c = providerFilter.mostRelevantConstructor(messageBodyReader.getClass()); assertEquals(4, c.getParameterCount()); assertEquals("public com.geemvc.jaxrs.PersonMessageBodyReader(javax.ws.rs.core.Application,javax.ws.rs.core.UriInfo,javax.ws.rs.core.HttpHeaders,javax.ws.rs.ext.Providers)", c.toString()); }
@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(); }
public static HttpServer startServer() { HttpServer server = new HttpServer(); server.addListener(new NetworkListener("grizzly", "0.0.0.0", 8080)); final TCPNIOTransportBuilder transportBuilder = TCPNIOTransportBuilder.newInstance(); //transportBuilder.setIOStrategy(WorkerThreadIOStrategy.getInstance()); transportBuilder.setIOStrategy(SameThreadIOStrategy.getInstance()); server.getListener("grizzly").setTransport(transportBuilder.build()); final ResourceConfig rc = new ResourceConfig().packages("xyz.muetsch.jersey"); rc.register(JacksonFeature.class); final ServerConfiguration config = server.getServerConfiguration(); config.addHttpHandler(RuntimeDelegate.getInstance().createEndpoint(rc, GrizzlyHttpContainer.class), "/rest/todo/"); try { server.start(); } catch (IOException e) { e.printStackTrace(); } return server; }
public SwiftProxy(Properties properties, BlobStoreLocator locator, URI endpoint) { this.endpoint = requireNonNull(endpoint); rc = new BounceResourceConfig(properties, locator); if (logger.isDebugEnabled()) { rc.register(new LoggingFilter(java.util.logging.Logger.getGlobal(), false)); } server = GrizzlyHttpServerFactory.createHttpServer(endpoint, rc, false); server.getListeners().forEach(listener -> { listener.registerAddOn(new ContentLengthAddOn()); }); // allow HTTP DELETE to have payload for multi-object delete server.getServerConfiguration().setAllowPayloadForUndefinedHttpMethods(true); RuntimeDelegate.setInstance(new RuntimeDelegateImpl(RuntimeDelegate.getInstance())); }
protected void flushHeaders() throws IOException { if (headersFlushed) return; headersFlushed = true; RuntimeDelegate delegate = RuntimeDelegate.getInstance(); for (String key : headers.keySet()) { List<Object> objs = headers.get(key); for (Object obj : objs) { String value; RuntimeDelegate.HeaderDelegate headerDelegate = delegate.createHeaderDelegate(obj.getClass()); if (headerDelegate != null) { value = headerDelegate.toString(obj); } else { value = obj.toString(); } stream.write(key.getBytes()); stream.write(": ".getBytes()); stream.write(value.getBytes()); stream.write("\r\n".getBytes()); } } stream.write("\r\n".getBytes()); }
protected void initJaxRsRuntime() { if (configuration.isJaxRsEnabled()) { // JAX-RS runtime delegate. log.debug("Initializging JAX-RS Runtime."); RuntimeDelegate.setInstance(injector.getInstance(RuntimeDelegate.class)); } else { log.debug("JAX-RS Runtime disabled by configuration."); } }
@Test public void testLocateGensonContextResolver() { Providers providers = instance(Providers.class); RuntimeDelegate.setInstance(new DefaultRuntimeDelegate()); ContextResolver contextResolver = providers.getContextResolver(Genson.class, MediaType.APPLICATION_JSON_TYPE); assertNotNull(contextResolver); assertEquals(TestGensonContextResolver3.class, contextResolver.getClass()); }
@Test public void testLocateObjectContextResolver() { Providers providers = instance(Providers.class); RuntimeDelegate.setInstance(new DefaultRuntimeDelegate()); ContextResolver contextResolver = providers.getContextResolver(Person.class, MediaType.APPLICATION_JSON_TYPE); assertNotNull(contextResolver); assertEquals(TestGensonContextResolver6.class, contextResolver.getClass()); }
@Test public void testLocateApplicationContextResolver() { Providers providers = instance(Providers.class); RuntimeDelegate.setInstance(new DefaultRuntimeDelegate()); ContextResolver contextResolver = providers.getContextResolver(Application.class, MediaType.APPLICATION_JSON_TYPE); assertNotNull(contextResolver); assertEquals(TestApplicationContextResolver.class, contextResolver.getClass()); }
@Bean public org.apache.cxf.endpoint.Server jaxRsServer() { JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint( jaxRsApiApplication(), JAXRSServerFactoryBean.class ); factory.setServiceBeans( Arrays.< Object >asList(starbucksOutletService()) ); factory.setAddress( "/" + factory.getAddress() ); List<Object> providers = new ArrayList<Object>(); providers.add(jsonProvider()); providers.add(new OrderReader()); factory.setProviders(providers); //factory.setProviders( Arrays.< Object >asList( jsonProvider() ) ); return factory.create(); }
@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(); }
@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(); }
@Bean public org.apache.cxf.endpoint.Server jaxRsServer() { JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint( jaxRsApiApplication(), JAXRSServerFactoryBean.class ); factory.setServiceBeans( Arrays.< Object >asList(customerService()) ); factory.setAddress( "/" + factory.getAddress() ); factory.setProviders( Arrays.< Object >asList( jsonProvider() ) ); return factory.create(); }
@Test public void testJAXRSTypes() { // MediaType#toString and Link.Builder call RuntimeDelegate final RuntimeDelegate delegateMock = mock(RuntimeDelegate.class); final RuntimeDelegate.HeaderDelegate<MediaType> headerDelegateMock = mock(RuntimeDelegate.HeaderDelegate.class); when(delegateMock.createHeaderDelegate(MediaType.class)).thenReturn(headerDelegateMock); final Link.Builder linkBuilderMock = mock(Link.Builder.class); when(delegateMock.createLinkBuilder()).thenReturn(linkBuilderMock); when(headerDelegateMock.toString(any())).thenReturn("application/json"); when(linkBuilderMock.uri(anyString())).thenReturn(linkBuilderMock); when(linkBuilderMock.rel(anyString())).thenReturn(linkBuilderMock); when(linkBuilderMock.build()).thenReturn(new DummyLink("https://api.example.com/books/1", "self"), new DummyLink("https://api.example.com/books/123", "one", "two")); injectRuntimeDelegate(delegateMock); final String actual = Siren.createEntityBuilder() .setSubEntityType(MediaType.APPLICATION_JSON_TYPE) .setSubEntityHref(URI.create("https://api.example.com/books/1")) .addLink(Link.fromUri("https://api.example.com/books/1").rel("self").build()) .addLink(Link.fromUri("https://api.example.com/books/123").rel("one two").build()) .build().toString(); final String expected = "{" + "\"type\":\"application/json\"," + "\"href\":\"https://api.example.com/books/1\"," + "\"links\":[{" + "\"rel\":[\"self\"]," + "\"href\":\"https://api.example.com/books/1\"" + "},{" + "\"rel\":[\"one\",\"two\"]," + "\"href\":\"https://api.example.com/books/123\"}]" + "}"; assertThat(actual, is(expected)); }
public static void injectRuntimeDelegate(final RuntimeDelegate runtimeDelegate) { try { final Field delegateField = RuntimeDelegate.class.getDeclaredField("cachedDelegate"); delegateField.setAccessible(true); delegateField.set(null, runtimeDelegate); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); } }
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); }
@BeforeMethod public void prepare() throws ServletException { RuntimeDelegate.setInstance(new RuntimeDelegateImpl()); when(filterConfig.getServletContext()).thenReturn(servletContext); setFieldValue(filter, "apiEndpoint", "http://localhost:8080/api"); setFieldValue(filter, "loginPageUrl", "/site/login"); setFieldValue(filter, "cookiesDisabledErrorPageUrl", "/site/cookiesDisabledErrorPageUrl"); setFieldValue(filter, "allowAnonymous", false); // setFieldValue(filter, "attemptToGetNewTokenIfNotExist", false); // setFieldValue(filter, "attemptToGetNewTokenIfInvalid", false); // EnvironmentContext.reset(); }
@Override public void init(final ServletConfig config) throws ServletException { super.init(config); // TODO: Figure out what version of RESTEasy is used and log it // Initialize container componentContainer.init(config); log.info("JAX-RS RuntimeDelegate: {}", RuntimeDelegate.getInstance()); // Watch for components beanLocator.watch(Key.get(Component.class), new ComponentMediator(), componentContainer); log.info("Initialized"); }
public static HttpServer getServer() throws IOException { HttpServer server = HttpServer.create(new InetSocketAddress(uri.getPort()), 0); HttpHandler handler = RuntimeDelegate .getInstance() .createEndpoint(new SampleApplication(), HttpHandler.class); server.createContext(uri.getPath(), handler); return server; }
public ODataJerseyServer(String appBaseUri) { this.appBaseUri = appBaseUri; // ensure that the correct JAX-RS implementation (Jersey, server) is loaded if (!(RuntimeDelegate.getInstance() instanceof com.sun.jersey.server.impl.provider.RuntimeDelegateImpl)) RuntimeDelegate.setInstance(new com.sun.jersey.server.impl.provider.RuntimeDelegateImpl()); }
@SuppressWarnings("unchecked") private static void androidJerseyClientHack() { try { RuntimeDelegate rd = RuntimeDelegate.getInstance(); Field f = AbstractRuntimeDelegate.class.getDeclaredField("hps"); f.setAccessible(true); Set<HeaderDelegateProvider<?>> hps = (Set<HeaderDelegateProvider<?>>) f.get(rd); hps.clear(); hps.add(new MediaTypeProvider()); } catch (Exception e) { throw Throwables.propagate(e); } }
private ODataJerseyConsumer(FormatType type, String serviceRootUri, JerseyClientFactory clientFactory, OClientBehavior... behaviors) { super(serviceRootUri); // ensure that a correct JAX-RS implementation (Jersey, server or default) is loaded if (!(RuntimeDelegate.getInstance() instanceof com.sun.jersey.core.spi.factory.AbstractRuntimeDelegate)) RuntimeDelegate.setInstance(new com.sun.ws.rs.ext.RuntimeDelegateImpl()); this.client = new ODataJerseyClient(type, clientFactory, behaviors); }
public ODataCxfServer(String appBaseUri) { this.appBaseUri = appBaseUri; // ensure that the correct JAX-RS implementation (CXF) is loaded if (!(RuntimeDelegate.getInstance() instanceof org.apache.cxf.jaxrs.impl.RuntimeDelegateImpl)) RuntimeDelegate.setInstance(new org.apache.cxf.jaxrs.impl.RuntimeDelegateImpl()); }
private ODataCxfConsumer(FormatType type, String serviceRootUri, OClientBehavior... behaviors) { super(serviceRootUri); // ensure that the correct JAX-RS implementation (CXF) is loaded if (!(RuntimeDelegate.getInstance() instanceof org.apache.cxf.jaxrs.impl.RuntimeDelegateImpl)) RuntimeDelegate.setInstance(new org.apache.cxf.jaxrs.impl.RuntimeDelegateImpl()); this.client = new ODataCxfClient(type, behaviors); }
public static void start(int port) throws IOException { // Create an HTTP server listening at port 8282 URI uri = UriBuilder.fromUri("http://localhost/").port(port).build(); server = HttpServer.create(new InetSocketAddress(uri.getPort()), 0); HttpHandler handler = RuntimeDelegate.getInstance().createEndpoint(new ApplicationConfig(), HttpHandler.class); server.createContext(uri.getPath(), handler); discoveryMsg = discoveryMsg.replaceAll("PORT", "" + uri.getPort()); server.start(); }
public static void start(int port) throws IOException { // Create an HTTP server listening at port URI uri = UriBuilder.fromUri("http://localhost/").port(port).build(); server = HttpServer.create(new InetSocketAddress(uri.getPort()), 0); HttpHandler handler = RuntimeDelegate.getInstance().createEndpoint(new ApplicationConfig(), HttpHandler.class); server.createContext(uri.getPath(), handler); server.start(); }
private static Set<HeaderDelegateProvider> stealAcquireRefToHeaderDelegateProviders() { try { final RuntimeDelegate instance = RuntimeDelegate.getInstance(); final RuntimeDelegateImpl s = (RuntimeDelegateImpl) instance; final Field declaredField; declaredField = AbstractRuntimeDelegate.class.getDeclaredField("hps"); declaredField.setAccessible(true); final Set<HeaderDelegateProvider> get = (Set<HeaderDelegateProvider>) declaredField.get(s); return get; } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ex) { throw new RuntimeException(ex); } }
@Bean @DependsOn("cxf") public Server jaxRsServer(ApplicationContext appContext) { JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint(jaxRsApiApplication(), JAXRSServerFactoryBean.class); factory.setServiceBeanObjects(foobarResource()); factory.setAddress("/" + factory.getAddress()); factory.setProvider(gsonProvider()); return factory.create(); }
protected ControlCenterServer() throws Exception { ControlCenterApp application = new ControlCenterApp(); RuntimeDelegate delegate = RuntimeDelegate.getInstance(); Map<Object, Object> mappings = new HashMap<Object, Object>(); mappings.put("json", "application/json"); mappings.put("xml", "application/xml"); JAXRSServerFactoryBean bean = delegate.createEndpoint(application, JAXRSServerFactoryBean.class); bean.setAddress("http://localhost:9000/services" + bean.getAddress()); bean.setExtensionMappings(mappings); server = bean.create(); server.start(); }
private void setRuntimeDelegate() { try { RuntimeDelegate.getInstance(); } catch (Exception e) { RuntimeDelegate.setInstance(new RuntimeDelegateImpl()); } }
/** * Starts Grizzly HTTP server exposing static content, JAX-RS resources * and web sockets defined in this application. * * @param webRootPath static content root path. * @return Grizzly HTTP server. */ public static HttpServer startServer(String webRootPath) { final HttpServer server = new HttpServer(); final NetworkListener listener = new NetworkListener("grizzly", BASE_URI, PORT); server.addListener(listener); final ServerConfiguration config = server.getServerConfiguration(); // add handler for serving static content config.addHttpHandler(new StaticContentHandler(webRootPath), APP_PATH); // add handler for serving JAX-RS resources config.addHttpHandler( RuntimeDelegate .getInstance() .createEndpoint(new ResourceConfig().packages("it.unito.geosummly.api"), GrizzlyHttpContainer.class), API_PATH ); try { // Start the server. server.start(); } catch (Exception ex) { throw new ProcessingException("Exception thrown when trying to start grizzly server", ex); } return server; }
@Bean @DependsOn( "cxf" ) 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(); }
@BeforeClass public static void startServer() throws IOException { mockServer = new FeaturedHttpServerBuilder().port(-1).observer(new RequestObserver() { @Override public void onRequest(final FullHttpRequest request) { if (request.getUri().endsWith("start/simple")) { final String actual = new String(request.content().array()); assertEquals(actual, "{\"entries\":[{\"key\":\"a\",\"value\":\"b\"}]}"); } } }).build().start(); port = mockServer.getPort(); RuntimeDelegate.setInstance(null); // reset }
@Test public void testCreateResponseBuilder() { final ResponseBuilder rb = RuntimeDelegate.getInstance().createResponseBuilder(); assertNotNull(rb); }
@Test public void testCreateMediaTypeDelegate() { final HeaderDelegate<MediaType> d = RuntimeDelegate.getInstance().createHeaderDelegate(MediaType.class); assertNotNull(d); assertTrue(d instanceof MinijaxMediaTypeDelegate); }
@Test public void testCreateCookieDelegate() { final HeaderDelegate<Cookie> d = RuntimeDelegate.getInstance().createHeaderDelegate(Cookie.class); assertNotNull(d); assertTrue(d instanceof MinijaxCookieDelegate); }
@Test public void testCreateNewCookieDelegate() { final HeaderDelegate<NewCookie> d = RuntimeDelegate.getInstance().createHeaderDelegate(NewCookie.class); assertNotNull(d); assertTrue(d instanceof MinijaxNewCookieDelegate); }