當前位置: 首頁>>代碼示例>>Java>>正文


Java MessageBodyReader類代碼示例

本文整理匯總了Java中javax.ws.rs.ext.MessageBodyReader的典型用法代碼示例。如果您正苦於以下問題:Java MessageBodyReader類的具體用法?Java MessageBodyReader怎麽用?Java MessageBodyReader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MessageBodyReader類屬於javax.ws.rs.ext包,在下文中一共展示了MessageBodyReader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: JerseyApplication

import javax.ws.rs.ext.MessageBodyReader; //導入依賴的package包/類
@Inject
public JerseyApplication(ServiceLocator serviceLocator) {
	GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator);
	GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class);
    guiceBridge.bridgeGuiceInjector(AppLoader.injector);
    
    String disableMoxy = PropertiesHelper.getPropertyNameForRuntime(
    		CommonProperties.MOXY_JSON_FEATURE_DISABLE,
               getConfiguration().getRuntimeType());
       property(disableMoxy, true);
       property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);

       // add the default Jackson exception mappers
       register(JsonParseExceptionMapper.class);
       register(JsonMappingExceptionMapper.class);
       register(JacksonJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
       
       packages(JerseyApplication.class.getPackage().getName());
       
    for (JerseyConfigurator configurator: AppLoader.getExtensions(JerseyConfigurator.class)) {
    	configurator.configure(this);
    }
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:24,代碼來源:JerseyApplication.java

示例2: shouldRegisterAMultiTypedProviderInstanceWithPriorities

import javax.ws.rs.ext.MessageBodyReader; //導入依賴的package包/類
@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());
    }
}
 
開發者ID:eclipse,項目名稱:microprofile-rest-client,代碼行數:25,代碼來源:AdditionalRegistrationTest.java

示例3: configure

import javax.ws.rs.ext.MessageBodyReader; //導入依賴的package包/類
@Override
  public boolean configure(final FeatureContext context) {
      
  	PluginLoader.INSTANCE.plugins.get().stream()
.filter(module -> module.jacksonFeatureProperties()!=null)
.map(Plugin::jacksonFeatureProperties)
.map(fn->fn.apply(context))
.forEach(map -> {
	addAll(map,context);
});
     
      
      JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
   		provider.setMapper(JacksonUtil.getMapper());
          context.register(provider, new Class[]{MessageBodyReader.class, MessageBodyWriter.class});
   
      return true;
  }
 
開發者ID:aol,項目名稱:micro-server,代碼行數:19,代碼來源:JacksonFeature.java

示例4: configure

import javax.ws.rs.ext.MessageBodyReader; //導入依賴的package包/類
public boolean configure(final FeatureContext context) {
    final Configuration config = context.getConfiguration();
    final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(), InternalProperties.JSON_FEATURE, JSON_FEATURE,
            String.class);
    // Other JSON providers registered.
    if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) {
        return false;
    }
    // Disable other JSON providers.
    context.property(PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType()), JSON_FEATURE);
    // Register FastJson.
    if (!config.isRegistered(FastJsonProvider.class)) {
        //DisableCircularReferenceDetect
        FastJsonProvider fastJsonProvider = new FastJsonProvider();
        FastJsonConfig fastJsonConfig = new FastJsonConfig();
        //fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.BrowserSecure);

        fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect);

        fastJsonProvider.setFastJsonConfig(fastJsonConfig);

        context.register(fastJsonProvider, MessageBodyReader.class, MessageBodyWriter.class);
    }
    return true;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:Issue1341.java

示例5: getImpl

import javax.ws.rs.ext.MessageBodyReader; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private T getImpl(final MinijaxRequestContext context, final InputStream entityStream) throws IOException {
    if (entityClass == String.class) {
        return (T) IOUtils.toString(entityStream, StandardCharsets.UTF_8);
    }

    if (entityClass == MultivaluedMap.class) {
        return (T) context.getForm().asForm().asMap();
    }

    final MediaType mediaType = consumesTypes != null && !consumesTypes.isEmpty() ? consumesTypes.get(0) : null;
    final MessageBodyReader<T> reader = context.getApplication().getProviders().getMessageBodyReader(entityClass, genericType, annotations, mediaType);
    if (reader != null) {
        final MultivaluedMap<String, String> httpHeaders = context.getHeaders();
        return reader.readFrom(entityClass, genericType, annotations, mediaType, httpHeaders, entityStream);
    }

    throw new InjectException("Unknown entity type (" + entityClass + ")");
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:20,代碼來源:EntityProvider.java

示例6: register

import javax.ws.rs.ext.MessageBodyReader; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public void register(final Class<?> c) {
    if (MessageBodyReader.class.isAssignableFrom(c)) {
        readers.add((Class<MessageBodyReader<?>>) c, MediaTypeUtils.parseMediaTypes(c.getAnnotation(Consumes.class)));
    }

    if (MessageBodyWriter.class.isAssignableFrom(c)) {
        writers.add((Class<MessageBodyWriter<?>>) c, MediaTypeUtils.parseMediaTypes(c.getAnnotation(Produces.class)));
    }

    if (ExceptionMapper.class.isAssignableFrom(c)) {
        exceptionMappers.add((Class<ExceptionMapper<?>>) c, MediaTypeUtils.parseMediaTypes(c.getAnnotation(Produces.class)));
    }

    if (ParamConverterProvider.class.isAssignableFrom(c)) {
        paramConverterProviders.add((ParamConverterProvider) application.get(c));
    }
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:19,代碼來源:MinijaxProviders.java

示例7: getMessageBodyReader

import javax.ws.rs.ext.MessageBodyReader; //導入依賴的package包/類
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public <T> MessageBodyReader<T> getMessageBodyReader(
        final Class<T> type,
        final Type genericType,
        final Annotation[] annotations,
        final MediaType mediaType) {

    for (final Class<? extends MessageBodyReader<?>> readerClass : readers.get(mediaType)) {
        final MessageBodyReader reader = application.get(readerClass);
        if (reader.isReadable(type, genericType, annotations, mediaType)) {
            return reader;
        }
    }
    return null;
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:17,代碼來源:MinijaxProviders.java

示例8: shouldRegisterAMultiTypedProviderClassWithPriorities

import javax.ws.rs.ext.MessageBodyReader; //導入依賴的package包/類
@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());
    }
}
 
開發者ID:eclipse,項目名稱:microprofile-rest-client,代碼行數:23,代碼來源:AdditionalRegistrationTest.java

示例9: configure

import javax.ws.rs.ext.MessageBodyReader; //導入依賴的package包/類
public boolean configure(final FeatureContext context) {
	final Configuration config = context.getConfiguration();
	final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(), InternalProperties.JSON_FEATURE, JSON_FEATURE,
			String.class);
	// Other JSON providers registered.
	if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) {
		return false;
	}
	// Disable other JSON providers.
	context.property(PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType()), JSON_FEATURE);
	// Register FastJson.
	if (!config.isRegistered(FastJsonProvider.class)) {
		context.register(FastJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
	}
	return true;
}
 
開發者ID:ChineseLincoln,項目名稱:JerseyRestful,代碼行數:17,代碼來源:FastJsonFeature.java

示例10: testLocateMostRelevantConstructor

import javax.ws.rs.ext.MessageBodyReader; //導入依賴的package包/類
@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());
}
 
開發者ID:geetools,項目名稱:geeMVC-Java-MVC-Framework,代碼行數:21,代碼來源:JaxRsResolverTest.java

示例11: getClasses

import javax.ws.rs.ext.MessageBodyReader; //導入依賴的package包/類
@Override
public Set<Class<?>> getClasses() {
	Set<Class<?>> s = new HashSet<Class<?>>();
	
	// rest Resources
	Set<Class<? extends RESTResource>> restResourceTypes = this.getRESTResourceTypes();
	if (CollectionUtils.hasData(restResourceTypes)) s.addAll(restResourceTypes);
	
	// Request received objects mappers: transforms Java->XML for REST methods param types
	Set<Class<? extends MessageBodyReader<?>>> reqReceivedTypesMappers = this.getRequestReceivedTypesMappers();
	if (CollectionUtils.hasData(reqReceivedTypesMappers)) s.addAll(reqReceivedTypesMappers);
	
	// Response sent objects mappers: transforms Java->XML for REST methods return types
	Set<Class<? extends MessageBodyWriter<?>>> respSentTypesMappers = this.getResponseSentTypesMappers();
	if (CollectionUtils.hasData(respSentTypesMappers)) s.addAll(respSentTypesMappers);
	
	// Exception Mappers
	Set<Class<? extends ExceptionMapper<?>>> expsMappers = this.getExceptionsMappers();
	if (CollectionUtils.hasData(expsMappers)) s.addAll(expsMappers);		
	
	return s;
}
 
開發者ID:opendata-euskadi,項目名稱:r01fb,代碼行數:23,代碼來源:RESTAppBase.java

示例12: readFrom

import javax.ws.rs.ext.MessageBodyReader; //導入依賴的package包/類
@Override
public JsonWebKeySet readFrom(final Class<JsonWebKeySet> type,
        final Type genericType,
        final Annotation[] annotations,
        final MediaType mediaType,
        final MultivaluedMap<String, String> httpHeaders,
        final InputStream inputStream) throws IOException,
        WebApplicationException {

    final JsonArray keysArray = Json.createReader(inputStream)
            .readObject()
            .getJsonArray("keys");

    final JsonWebKeySet keySet = new JsonWebKeySet();
    final MessageBodyReader<JsonWebKey> reader = providers.getMessageBodyReader(JsonWebKey.class, JsonWebKey.class, annotations, mediaType);
    for (final JsonValue key : keysArray) {
        final InputStream keyStream = new ByteArrayInputStream(key.toString()
                .getBytes(CharSets.UTF8));
        final JsonWebKey jsonWebKey = reader.readFrom(JsonWebKey.class, null, annotations, mediaType, null, keyStream);
        keySet.add(jsonWebKey);
    }

    return keySet;
}
 
開發者ID:trajano,項目名稱:openid-connect,代碼行數:25,代碼來源:JsonWebKeySetProvider.java

示例13: shouldGetContentAsList

import javax.ws.rs.ext.MessageBodyReader; //導入依賴的package包/類
@Test
public void shouldGetContentAsList() throws Exception {
	List<String> list = Lists.newArrayList("test1", "test2", "test3");
	byte[] bytes = new byte[10];
	MediaType mediaType = mock(MediaType.class);
	HttpHeaders httpHeaders = mock(HttpHeaders.class);
	when(httpHeaders.getMediaType()).thenReturn(mediaType);
	MessageBodyReader reader = mock(MessageBodyReader.class);
	when(reader.readFrom(eq(String.class), eq(String.class), eq(new Annotation[]{}), eq(mediaType), isNull(MultivaluedMap.class), any(InputStream.class))).thenThrow(IOException.class);
	when(reader.readFrom(eq(List.class), any(Type.class), eq(new Annotation[]{}), eq(mediaType), isNull(MultivaluedMap.class), any(InputStream.class))).thenReturn(list);
	Providers providers = mock(Providers.class);
	when(providers.getMessageBodyReader(String.class, String.class, new Annotation[]{}, mediaType)).thenReturn(reader);
	when(providers.getMessageBodyReader(List.class, ResourceUtil.listType(String.class).getType(), new Annotation[]{}, mediaType)).thenReturn(reader);
	Object content = ResourceUtil.getContent(bytes, providers, httpHeaders, String.class);
	assertTrue(content instanceof List);
	assertEquals(content, list);
}
 
開發者ID:minnal,項目名稱:minnal,代碼行數:18,代碼來源:ResourceUtilTest.java

示例14: shouldGetContentAsMap

import javax.ws.rs.ext.MessageBodyReader; //導入依賴的package包/類
@Test
public void shouldGetContentAsMap() throws Exception {
	Map<String, Object> map = new HashMap<String, Object>();
	map.put("key1", "value1");
	byte[] bytes = new byte[10];
	MediaType mediaType = mock(MediaType.class);
	HttpHeaders httpHeaders = mock(HttpHeaders.class);
	when(httpHeaders.getMediaType()).thenReturn(mediaType);
	MessageBodyReader reader = mock(MessageBodyReader.class);
	when(reader.readFrom(eq(Map.class), eq(Map.class), eq(new Annotation[]{}), eq(mediaType), isNull(MultivaluedMap.class), any(InputStream.class))).thenReturn(map);
	Providers providers = mock(Providers.class);
	when(providers.getMessageBodyReader(Map.class, Map.class, new Annotation[]{}, mediaType)).thenReturn(reader);
	Object content = ResourceUtil.getContent(bytes, providers, httpHeaders, Map.class);
	assertTrue(content instanceof Map);
	assertEquals(content, map);
}
 
開發者ID:minnal,項目名稱:minnal,代碼行數:17,代碼來源:ResourceUtilTest.java

示例15: shouldInvokeMethodWithArguments

import javax.ws.rs.ext.MessageBodyReader; //導入依賴的package包/類
@Test
public void shouldInvokeMethodWithArguments() throws Throwable {
	Map<String, Object> content = new HashMap<String, Object>();
	content.put("value", "test123");
	content.put("someNumber", 1L);
	Map<String, Object> values = new HashMap<String, Object>();
	DummyModel model = new DummyModel();
	
	byte[] bytes = new byte[10];
	MediaType mediaType = mock(MediaType.class);
	HttpHeaders httpHeaders = mock(HttpHeaders.class);
	when(httpHeaders.getMediaType()).thenReturn(mediaType);
	MessageBodyReader reader = mock(MessageBodyReader.class);
	when(reader.readFrom(eq(Map.class), eq(Map.class), isNull(Annotation[].class), eq(mediaType), isNull(MultivaluedMap.class), any(InputStream.class))).thenReturn(content);
	Providers providers = mock(Providers.class);
	when(providers.getMessageBodyReader(Map.class, Map.class, null, mediaType)).thenReturn(reader);

	assertEquals(ResourceUtil.invokeAction(model, "dummyActionWithArguments", Lists.newArrayList(new ParameterMetaData("value", "value", String.class), 
			new ParameterMetaData("someNumber", "someNumber", Long.class)), bytes, providers, httpHeaders, values), "dummyActionWithArguments");
}
 
開發者ID:minnal,項目名稱:minnal,代碼行數:21,代碼來源:ResourceUtilTest.java


注:本文中的javax.ws.rs.ext.MessageBodyReader類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。