Java 类javax.ws.rs.ext.RuntimeDelegate 实例源码

项目:geeMVC-Java-MVC-Framework    文件:JaxRsResolverTest.java   
@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());
}
项目:restful-api-cxf-spring-java    文件:CxfConfig.java   
@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();
  }
项目:http-server-benchmarks    文件:Main.java   
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;
}
项目:swiftproxy    文件:SwiftProxy.java   
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()));
}
项目:blaze-storage    文件:HeaderFlushedOutputStream.java   
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());

}
项目:geeMVC-Java-MVC-Framework    文件:DefaultRequestRunner.java   
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.");
    }
}
项目:geeMVC-Java-MVC-Framework    文件:JaxRsResolverTest.java   
@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());
}
项目:geeMVC-Java-MVC-Framework    文件:JaxRsResolverTest.java   
@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());
}
项目:geeMVC-Java-MVC-Framework    文件:JaxRsResolverTest.java   
@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());
}
项目:product-ei    文件:CoffeeConfig.java   
@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();
 }
项目:product-ei    文件:AppConfig.java   
@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();
}
项目:product-ei    文件:MusicConfig.java   
@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();
}
项目:product-ei    文件:CustomerConfig.java   
@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();
}
项目:siren4javaee    文件:EntityBuilderTest.java   
@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));
}
项目:siren4javaee    文件:TestUtils.java   
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);
    }
}
项目:aries-jax-rs-whiteboard    文件:CXFJaxRsServiceRegistrator.java   
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);
}
项目:codenvy    文件:LoginFilterTest.java   
@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();
}
项目:nexus-public    文件:SiestaServlet.java   
@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");
}
项目:emfjson-samples    文件:Main.java   
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;
}
项目:oreva    文件:ODataJerseyServer.java   
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());
}
项目:oreva    文件:JerseyClientUtil.java   
@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);
  }
}
项目:oreva    文件:ODataJerseyConsumer.java   
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);
}
项目:oreva    文件:ODataCxfServer.java   
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());
}
项目:oreva    文件:ODataCxfConsumer.java   
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);
}
项目:metron    文件:MockTaxiiService.java   
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();
}
项目:metron    文件:MockDGAModel.java   
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();
}
项目:tinytypes    文件:JerseyResponseSupport.java   
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);
    }
}
项目:rest-api-template    文件:AppConfig.java   
@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();
}
项目:activemq-samples    文件:ControlCenterServer.java   
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();
}
项目:contrib-jenkins-qubell-plugin    文件:WebServiceBase.java   
private void setRuntimeDelegate() {
    try {
        RuntimeDelegate.getInstance();
    } catch (Exception e) {
        RuntimeDelegate.setInstance(new RuntimeDelegateImpl());
    }
}
项目:geosummly    文件:Server.java   
/**
 * 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;
}
项目:java2typescript    文件:AppConfig.java   
@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();
}
项目:java2typescript    文件:AppConfig.java   
@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();
}
项目:incubator-batchee    文件:ClientTestBase.java   
@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
}
项目:minijax    文件:RuntimeDelegateTest.java   
@Test
public void testCreateResponseBuilder() {
    final ResponseBuilder rb = RuntimeDelegate.getInstance().createResponseBuilder();
    assertNotNull(rb);
}
项目:minijax    文件:RuntimeDelegateTest.java   
@Test
public void testCreateMediaTypeDelegate() {
    final HeaderDelegate<MediaType> d = RuntimeDelegate.getInstance().createHeaderDelegate(MediaType.class);
    assertNotNull(d);
    assertTrue(d instanceof MinijaxMediaTypeDelegate);
}
项目:minijax    文件:RuntimeDelegateTest.java   
@Test
public void testCreateCookieDelegate() {
    final HeaderDelegate<Cookie> d = RuntimeDelegate.getInstance().createHeaderDelegate(Cookie.class);
    assertNotNull(d);
    assertTrue(d instanceof MinijaxCookieDelegate);
}
项目:minijax    文件:RuntimeDelegateTest.java   
@Test
public void testCreateNewCookieDelegate() {
    final HeaderDelegate<NewCookie> d = RuntimeDelegate.getInstance().createHeaderDelegate(NewCookie.class);
    assertNotNull(d);
    assertTrue(d instanceof MinijaxNewCookieDelegate);
}