java类javax.ws.rs.ext.RuntimeDelegate的实例源码

JaxRsResolverTest.java 文件源码 项目:geeMVC-Java-MVC-Framework 阅读 19 收藏 0 点赞 0 评论 0
@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());
}
CxfConfig.java 文件源码 项目:restful-api-cxf-spring-java 阅读 20 收藏 0 点赞 0 评论 0
@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();
  }
Main.java 文件源码 项目:http-server-benchmarks 阅读 29 收藏 0 点赞 0 评论 0
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.java 文件源码 项目:swiftproxy 阅读 22 收藏 0 点赞 0 评论 0
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()));
}
HeaderFlushedOutputStream.java 文件源码 项目:blaze-storage 阅读 24 收藏 0 点赞 0 评论 0
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());

}
DefaultRequestRunner.java 文件源码 项目:geeMVC-Java-MVC-Framework 阅读 24 收藏 0 点赞 0 评论 0
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.");
    }
}
JaxRsResolverTest.java 文件源码 项目:geeMVC-Java-MVC-Framework 阅读 24 收藏 0 点赞 0 评论 0
@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());
}
JaxRsResolverTest.java 文件源码 项目:geeMVC-Java-MVC-Framework 阅读 22 收藏 0 点赞 0 评论 0
@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());
}
JaxRsResolverTest.java 文件源码 项目:geeMVC-Java-MVC-Framework 阅读 24 收藏 0 点赞 0 评论 0
@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());
}
CoffeeConfig.java 文件源码 项目:product-ei 阅读 23 收藏 0 点赞 0 评论 0
@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();
 }
AppConfig.java 文件源码 项目:product-ei 阅读 23 收藏 0 点赞 0 评论 0
@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();
}
MusicConfig.java 文件源码 项目:product-ei 阅读 21 收藏 0 点赞 0 评论 0
@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();
}
CustomerConfig.java 文件源码 项目:product-ei 阅读 22 收藏 0 点赞 0 评论 0
@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();
}
EntityBuilderTest.java 文件源码 项目:siren4javaee 阅读 25 收藏 0 点赞 0 评论 0
@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));
}
TestUtils.java 文件源码 项目:siren4javaee 阅读 28 收藏 0 点赞 0 评论 0
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);
    }
}
CXFJaxRsServiceRegistrator.java 文件源码 项目:aries-jax-rs-whiteboard 阅读 19 收藏 0 点赞 0 评论 0
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);
}
LoginFilterTest.java 文件源码 项目:codenvy 阅读 17 收藏 0 点赞 0 评论 0
@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();
}
SiestaServlet.java 文件源码 项目:nexus-public 阅读 18 收藏 0 点赞 0 评论 0
@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");
}
Main.java 文件源码 项目:emfjson-samples 阅读 20 收藏 0 点赞 0 评论 0
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;
}
ODataJerseyServer.java 文件源码 项目:oreva 阅读 61 收藏 0 点赞 0 评论 0
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());
}
JerseyClientUtil.java 文件源码 项目:oreva 阅读 20 收藏 0 点赞 0 评论 0
@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);
  }
}
ODataJerseyConsumer.java 文件源码 项目:oreva 阅读 21 收藏 0 点赞 0 评论 0
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);
}
ODataCxfServer.java 文件源码 项目:oreva 阅读 17 收藏 0 点赞 0 评论 0
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());
}
ODataCxfConsumer.java 文件源码 项目:oreva 阅读 16 收藏 0 点赞 0 评论 0
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);
}
MockTaxiiService.java 文件源码 项目:metron 阅读 23 收藏 0 点赞 0 评论 0
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();
}
MockDGAModel.java 文件源码 项目:metron 阅读 19 收藏 0 点赞 0 评论 0
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();
}
JerseyResponseSupport.java 文件源码 项目:tinytypes 阅读 26 收藏 0 点赞 0 评论 0
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);
    }
}
AppConfig.java 文件源码 项目:rest-api-template 阅读 24 收藏 0 点赞 0 评论 0
@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();
}
ControlCenterServer.java 文件源码 项目:activemq-samples 阅读 63 收藏 0 点赞 0 评论 0
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();
}
WebServiceBase.java 文件源码 项目:contrib-jenkins-qubell-plugin 阅读 23 收藏 0 点赞 0 评论 0
private void setRuntimeDelegate() {
    try {
        RuntimeDelegate.getInstance();
    } catch (Exception e) {
        RuntimeDelegate.setInstance(new RuntimeDelegateImpl());
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号