Package javax.ws.rs.ext

Examples of javax.ws.rs.ext.Providers


            }

            Class<?> paramType = getType();

            // check if there is a provider that can handle this parameter
            Providers providers = runtimeContext.getProviders();
            if (providers != null) {
                MediaType mediaType = runtimeContext.getHttpHeaders().getMediaType();
                if (mediaType == null) {
                    mediaType = MediaType.APPLICATION_OCTET_STREAM_TYPE;
                }
                MessageBodyReader mbr =
                    providers.getMessageBodyReader(paramType,
                                                   getGenericType(),
                                                   getAnnotations(),
                                                   mediaType);

                if (mbr != null) {
View Full Code Here


        if (responseMediaType != null) {
            httpResponse.setContentType(responseMediaType.toString());
        }

        // get the provider to write the entity
        Providers providers = context.getProviders();
        MessageBodyWriter<Object> messageBodyWriter =
            (MessageBodyWriter<Object>)providers.getMessageBodyWriter(rawType,
                                                                      genericType,
                                                                      declaredAnnotations,
                                                                      responseMediaType);

        // use the provider to write the entity
View Full Code Here

     */
    public <T> T getContextFromResolver(Class<T> contextClass, RuntimeContext runtimeContext) {
        if (runtimeContext == null) {
            return null;
        }
        Providers providers = runtimeContext.getProviders();
        if (providers != null) {
            MediaType mediaType = runtimeContext.getHttpHeaders().getMediaType();
            if (mediaType == null) {
                mediaType = MediaType.WILDCARD_TYPE;
            }
            ContextResolver<T> contextResolver =
                providers.getContextResolver(contextClass, mediaType);
            if (contextResolver != null) {
                T context = contextResolver.getContext(contextClass);
                if (context != null) {
                    return context;
                }
View Full Code Here

        } else {
            type = MediaType.valueOf(contentType);
        }

        RuntimeContext runtimeContext = RuntimeContextTLS.getRuntimeContext();
        Providers providers = runtimeContext.getProviders();
        Class<? extends Object> cls = xmlWrapper.getValue().getClass();

        // this code ignores possible generic types
        // if in the future we would like to support the generic types
        // should check here if cls is GenericEntity and handle it

        MessageBodyWriter<Object> writer =
            (MessageBodyWriter<Object>)providers.getMessageBodyWriter(cls, cls, null, type);

        if (writer == null) {
            logger.error(Messages.getMessage("noWriterFound"), cls.getName(), type.toString());
            throw new WebApplicationException(500);
        }
View Full Code Here

            }

            Class<?> paramType = getType();

            // check if there is a provider that can handle this parameter
            Providers providers = runtimeContext.getProviders();
            if (providers != null) {
                MediaType mediaType = runtimeContext.getHttpHeaders().getMediaType();
                if (mediaType == null) {
                    mediaType = MediaType.APPLICATION_OCTET_STREAM_TYPE;
                }
                MessageBodyReader mbr =
                    providers.getMessageBodyReader(paramType,
                                                   getGenericType(),
                                                   getAnnotations(),
                                                   mediaType);

                if (mbr != null) {
View Full Code Here

            logger.debug("Set response Content-Type to: {} ", responseMediaType);
            httpResponse.setContentType(responseMediaType.toString());
        }

        // get the provider to write the entity
        Providers providers = context.getProviders();
        MessageBodyWriter<Object> messageBodyWriter =
            (MessageBodyWriter<Object>)providers.getMessageBodyWriter(rawType,
                                                                      genericType,
                                                                      declaredAnnotations,
                                                                      responseMediaType);

        // use the provider to write the entity
View Full Code Here

        }
        return out.toString();
    }

    private Providers getProviders() {
        return new Providers() {

            public <T> ContextResolver<T> getContextResolver(Class<T> contextType,
                                                             MediaType mediaType) {
                return null;
            }
View Full Code Here

  @Test
  public void testCanonicalRepresentation_Client_AllFields_Get() throws Exception {

    // Not required for GET but introduced for consistent style
    Providers providers = null;

    OutBoundHeaders headers = new OutBoundHeaders();
    headers.add(HttpHeaders.DATE, "Sat, 01 Jan 2000 12:34:56 GMT");
    headers.add(HttpHeaders.HOST, "www.example.org");
    headers.add(HttpHeaders.USER_AGENT, "curl/7.20.0 (x86_64-pc-linux-gnu) libcurl/7.20.0 OpenSSL/1.0.0a zlib/1.2.3");
View Full Code Here

  public void testCanonicalRepresentation_Client_AllFields_Post() throws Exception {

    MessageBodyWriter<String> messageBodyWriter = new StringProvider();

    // Mock Providers
    Providers providers = mock(Providers.class);
    when(providers.getMessageBodyWriter(String.class, String.class,
      new Annotation[0], MediaType.APPLICATION_JSON_TYPE)).thenReturn(messageBodyWriter);

    OutBoundHeaders headers = new OutBoundHeaders();
    headers.add(HttpHeaders.DATE, "Sat, 01 Jan 2000 12:34:56 GMT");
    headers.add(HttpHeaders.HOST, "www.example.org");
View Full Code Here

        } else {
            type = MediaType.valueOf(contentType);
        }

        RuntimeContext runtimeContext = RuntimeContextTLS.getRuntimeContext();
        Providers providers = runtimeContext.getProviders();
        Class<? extends Object> cls = xmlWrapper.getValue().getClass();

        // this code ignores possible generic types
        // if in the future we would like to support the generic types
        // should check here if cls is GenericEntity and handle it

        MessageBodyWriter<Object> writer =
            (MessageBodyWriter<Object>)providers.getMessageBodyWriter(cls, cls, null, type);

        if (writer == null) {
            logger.error(Messages.getMessage("noWriterFound", cls.getName(), type.toString())); //$NON-NLS-1$
            throw new WebApplicationException(500);
        }
View Full Code Here

TOP

Related Classes of javax.ws.rs.ext.Providers

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.