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

AdditionalRegistrationTest.java 文件源码 项目:microprofile-rest-client 阅读 19 收藏 0 点赞 0 评论 0
@Test
public void shouldRegisterAMultiTypedProviderInstanceWithPriorities() {
    MultiTypedProvider provider = new MultiTypedProvider();
    Map<Class<?>, Integer> priorities = new HashMap<>();
    priorities.put(ClientRequestFilter.class, 500);
    priorities.put(ClientResponseFilter.class, 501);
    priorities.put(MessageBodyReader.class, 502);
    priorities.put(MessageBodyWriter.class, 503);
    priorities.put(ReaderInterceptor.class, 504);
    priorities.put(WriterInterceptor.class, 505);
    priorities.put(ResponseExceptionMapper.class, 506);
    priorities.put(ParamConverterProvider.class, 507);
    RestClientBuilder builder = RestClientBuilder.newBuilder().register(provider, priorities);
    Configuration configuration = builder.getConfiguration();
    assertTrue(configuration.isRegistered(MultiTypedProvider.class), MultiTypedProvider.class + " should be registered");
    assertTrue(configuration.isRegistered(provider), MultiTypedProvider.class + " should be registered");
    Map<Class<?>, Integer> contracts = configuration.getContracts(MultiTypedProvider.class);
    assertEquals(contracts.size(), priorities.size(),
        "There should be "+priorities.size()+" provider types registered");
    for(Map.Entry<Class<?>, Integer> priority : priorities.entrySet()) {
        Integer contractPriority = contracts.get(priority.getKey());
        assertEquals(contractPriority, priority.getValue(), "The priority for "+priority.getKey()+" should be "+priority.getValue());
    }
}
AdditionalRegistrationTest.java 文件源码 项目:microprofile-rest-client 阅读 25 收藏 0 点赞 0 评论 0
@Test
public void shouldRegisterAMultiTypedProviderClassWithPriorities() {
    Map<Class<?>, Integer> priorities = new HashMap<>();
    priorities.put(ClientRequestFilter.class, 500);
    priorities.put(ClientResponseFilter.class, 501);
    priorities.put(MessageBodyReader.class, 502);
    priorities.put(MessageBodyWriter.class, 503);
    priorities.put(ReaderInterceptor.class, 504);
    priorities.put(WriterInterceptor.class, 505);
    priorities.put(ResponseExceptionMapper.class, 506);
    priorities.put(ParamConverterProvider.class, 507);
    RestClientBuilder builder = RestClientBuilder.newBuilder().register(MultiTypedProvider.class, priorities);
    Configuration configuration = builder.getConfiguration();
    assertTrue(configuration.isRegistered(MultiTypedProvider.class), MultiTypedProvider.class + " should be registered");
    Map<Class<?>, Integer> contracts = configuration.getContracts(MultiTypedProvider.class);
    assertEquals(contracts.size(), priorities.size(),
        "There should be "+priorities.size()+" provider types registered");
    for(Map.Entry<Class<?>, Integer> priority : priorities.entrySet()) {
        Integer contractPriority = contracts.get(priority.getKey());
        assertEquals(contractPriority, priority.getValue(), "The priority for "+priority.getKey()+" should be "+priority.getValue());
    }
}
OkHttpClientEngineTest.java 文件源码 项目:jaxrs-utils 阅读 24 收藏 0 点赞 0 评论 0
@Test
public void simpleWriterInterceptors() {
  Response response =
      client
          .target(mockServer.url("/writerInterceptor").uri())
          .register(
              new WriterInterceptor() {
                @Override
                public void aroundWriteTo(WriterInterceptorContext context)
                    throws IOException, WebApplicationException {
                  context.getHeaders().putSingle(HEADER_NAME, HEADER_VALUE);
                  context.proceed();
                }
              })
          .request()
          .post(Entity.json(PAYLOAD));

  assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
  assertThat(response.readEntity(String.class)).isEqualTo(HEADER_VALUE);
}
OkHttpClientEngineTest.java 文件源码 项目:jaxrs-utils 阅读 21 收藏 0 点赞 0 评论 0
@Test
public void simpleWriterInterceptors() {
  Response response =
      client
          .target(mockServer.url("/writerInterceptor").uri())
          .register(
              new WriterInterceptor() {
                @Override
                public void aroundWriteTo(WriterInterceptorContext context)
                    throws IOException, WebApplicationException {
                  context.getHeaders().putSingle(HEADER_NAME, HEADER_VALUE);
                  context.proceed();
                }
              })
          .request()
          .post(Entity.json(PAYLOAD));

  assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
  assertThat(response.readEntity(String.class)).isEqualTo(HEADER_VALUE);
}
AdditionalRegistrationTest.java 文件源码 项目:microprofile-rest-client 阅读 23 收藏 0 点赞 0 评论 0
@Test
public void shouldRegisterAMultiTypedProviderInstance() {
    MultiTypedProvider provider = new MultiTypedProvider();
    Class[] providerTypes = {ClientRequestFilter.class, ClientResponseFilter.class,
        MessageBodyReader.class, MessageBodyWriter.class, ReaderInterceptor.class, WriterInterceptor.class,
        ResponseExceptionMapper.class, ParamConverterProvider.class};
    RestClientBuilder builder = RestClientBuilder.newBuilder().register(provider, providerTypes);
    Configuration configuration = builder.getConfiguration();
    assertTrue(configuration.isRegistered(MultiTypedProvider.class), MultiTypedProvider.class + " should be registered");
    assertTrue(configuration.isRegistered(provider), MultiTypedProvider.class + " should be registered");
    assertEquals(configuration.getContracts(MultiTypedProvider.class).size(), providerTypes.length,
        "There should be "+providerTypes.length+" provider types registered");
}
AdditionalRegistrationTest.java 文件源码 项目:microprofile-rest-client 阅读 24 收藏 0 点赞 0 评论 0
@Test
public void shouldRegisterAMultiTypedProviderClass() {
    Class[] providerTypes = {ClientRequestFilter.class, ClientResponseFilter.class,
        MessageBodyReader.class, MessageBodyWriter.class, ReaderInterceptor.class, WriterInterceptor.class,
        ResponseExceptionMapper.class, ParamConverterProvider.class};
    RestClientBuilder builder = RestClientBuilder.newBuilder().register(MultiTypedProvider.class, providerTypes);
    Configuration configuration = builder.getConfiguration();
    assertTrue(configuration.isRegistered(MultiTypedProvider.class), MultiTypedProvider.class + " should be registered");
    assertEquals(configuration.getContracts(MultiTypedProvider.class).size(), providerTypes.length,
        "There should be "+providerTypes.length+" provider types registered");
}
MvcBinder.java 文件源码 项目:ameba 阅读 21 收藏 0 点赞 0 评论 0
/**
 * {@inheritDoc}
 */
@Override
protected void configure() {
    bind(TemplateMethodInterceptor.class).to(WriterInterceptor.class).in(Singleton.class);
    //noinspection unchecked
    bind(ViewableMessageBodyWriter.class).to(MessageBodyWriter.class).in(Singleton.class);

    bind(TemplateModelProcessor.class).to(ModelProcessor.class).in(Singleton.class);
    bindAsContract(ResolvingViewableContext.class).in(Singleton.class);
    bind(ResolvingViewableContext.class).to(ViewableContext.class).in(Singleton.class).ranked(1);
}
RESTService.java 文件源码 项目:tomee 阅读 18 收藏 0 点赞 0 评论 0
private static <T> boolean isProvider(final Class<T> clazz) {
    return MessageBodyReader.class.isAssignableFrom(clazz) ||
            MessageBodyWriter.class.isAssignableFrom(clazz) ||
            ParamConverter.class.isAssignableFrom(clazz) ||
            ContainerRequestFilter.class.isAssignableFrom(clazz) ||
            ContainerResponseFilter.class.isAssignableFrom(clazz) ||
            ReaderInterceptor.class.isAssignableFrom(clazz) ||
            WriterInterceptor.class.isAssignableFrom(clazz) ||
            ParamConverterProvider.class.isAssignableFrom(clazz) ||
            ContextResolver.class.isAssignableFrom(clazz) ||
            new MetaAnnotatedClass<>(clazz).isAnnotationPresent(Provider.class);
}
VertxAsynchronousResponse.java 文件源码 项目:app-ms 阅读 21 收藏 0 点赞 0 评论 0
@Override
public WriterInterceptor[] getWriterInterceptors() {

    return writerInterceptors;
}
Server.java 文件源码 项目:splinter 阅读 30 收藏 0 点赞 0 评论 0
private void registerBinders(final Splinter application) {
    final Logger logger = new LoggerProvider().provide();
    logger.debug("Dependency injection start");

    SimpleContainer.setApplication(application);
    SimpleContainer.setLogger(logger);
    SimpleContainer.setSharedVariablesManager(new SharedVariablesManager());

    register(new AbstractBinder() {
        @Override
        protected void configure() {
            // Template method interceptor
            bind(UserDataInterceptor.class).to(WriterInterceptor.class).in(Singleton.class);
        }
    });
    register(new AbstractBinder() {
        @Override
        protected void configure() {
            bind(application.getConfiguration().getDatabaseConfiguration()).to(DatabaseConfiguration.class);
        }
    });
    register(new AbstractBinder() {
        @Override
        protected void configure() {
            bind(application).to(Splinter.class);
        }
    });
    register(new AbstractBinder() {
        @Override
        protected void configure() {
            bind(logger).to(Logger.class);
        }
    });
    register(new AbstractBinder() {
        @Override
        protected void configure() {
            bind(SimpleContainer.getSharedVariablesManager()).to(SharedVariablesManager.class);
        }
    });
    logger.debug("Finished dependency injection registration");
}
VertxAsynchronousResponse.java 文件源码 项目:app-ms 阅读 23 收藏 0 点赞 0 评论 0
@Override
public void setWriterInterceptors(final WriterInterceptor[] writerInterceptors) {

    this.writerInterceptors = writerInterceptors;

}


问题


面经


文章

微信
公众号

扫码关注公众号