Package javax.ws.rs.core

Examples of javax.ws.rs.core.MediaType


   public void testMatching2()
   {
      ResteasyProviderFactory factory = new ResteasyProviderFactory();
      RegisterBuiltin.register(factory);

      MessageBodyWriter<Integer> writer = factory.getMessageBodyWriter(Integer.class, null, null, new MediaType("text", "plain"));
      Assert.assertNotNull(writer);
      Assert.assertEquals(writer.getClass(), DefaultTextPlain.class);
   }
View Full Code Here


      negotiation.setAcceptHeaders(Arrays.asList("text/plain"));
      negotiation.setAcceptCharsetHeaders(Arrays.asList("UTF-8"));
      negotiation.setAcceptEncodingHeaders(Arrays.asList("gzip"));
      negotiation.setAcceptLanguageHeaders(Arrays.asList("en-gb"));

      MediaType mediaTypeWithCharset = MediaType.valueOf("text/plain; charset=UTF-8");
      MediaType mediaType = MediaType.valueOf("text/plain");
      String encoding = "gzip";
      Locale locale = Locale.UK;

      List<Variant> available = new ArrayList<Variant>();
      available.add(new Variant(mediaTypeWithCharset, null, null));
View Full Code Here

      AcceptParameterHttpPreprocessor processor = new AcceptParameterHttpPreprocessor(acceptParamName);

      String type = MediaType.TEXT_XML;
      HttpRequest request = MockHttpRequest.get("foo?" + acceptParamName + "=" + type);

      MediaType mediaType = MediaType.valueOf(type);

      processor.preProcess(request);

      List<MediaType> list = request.getHttpHeaders().getAcceptableMediaTypes();
View Full Code Here

   public ServerResponse preProcess(HttpRequest request, ResourceMethod method) throws Failure, WebApplicationException
   {
      if (!request.getHttpMethod().equalsIgnoreCase("GET")) return null;

      String key = request.getUri().getRequestUri().toString();
      MediaType chosenType = method.resolveContentType(request, null);
      ServerCache.Entry entry = cache.get(key, chosenType);
      if (entry != null)
      {
         if (entry.isExpired())
         {
View Full Code Here

      output
              .addPart(
                      "<m:data xmlns:m='http://example.org/stuff'>"
                              + "<m:photo><xop:Include xmlns:xop='http://www.w3.org/2004/08/xop/include' href='cid:http://example.org/me.png'/></m:photo>"
                              + "<m:sig><xop:Include xmlns:xop='http://www.w3.org/2004/08/xop/include' href='cid:http://example.org/my.hsh'/></m:sig>"
                              + "</m:data>", new MediaType("application",
                              "xop+xml", mediaTypeParameters),
                      "<mymessage.xml@example.org>", "8bit");
      output.addPart("// binary octets for png",
              new MediaType("image", "png"), "<http://example.org/me.png>",
              "binary");
      output.addPart("// binary octets for signature", new MediaType(
              "application", "pkcs7-signature"),
              "<http://example.org/me.hsh>", "binary");
      client.putRelated(output);
   }
View Full Code Here

                logger.debug("Retrieving HttpServletRequest {} with ContainerResponse {}", res, cr);
                logger.error("Unexpected state. ContainerResponse cannot be null. The connection hasn't been suspended yet");
                return;
            }

            MediaType m = (MediaType) cr.getHttpHeaders().getFirst(HttpHeaders.CONTENT_TYPE);
            if (e.getMessage() instanceof Response) {
                cr.setResponse((Response) e.getMessage());
                cr.getHttpHeaders().add(HttpHeaders.CONTENT_TYPE, m);
                cr.write();
            } else if (e.getMessage() instanceof List) {
View Full Code Here

                servletReq.setAttribute(AtmosphereServlet.RESUME_ON_BROADCAST, new Boolean(true));
            }

            // Set the content-type based on the returned entity.
            try {
                MediaType contentType = response.getMediaType();
                if (contentType == null && response.getEntity() != null) {
                    LinkedList<MediaType> l = new LinkedList<MediaType>();
                    // Will retrun the first
                    l.add(request.getAcceptableMediaType(new LinkedList<MediaType>()));
                    contentType = response.getMessageBodyWorkers().getMessageBodyWriterMediaType(
                            response.getEntity().getClass(),
                            response.getEntityType(),
                            response.getAnnotations(),
                            l);

                    if (contentType == null ||
                            contentType.isWildcardType() || contentType.isWildcardSubtype())
                        contentType = MediaType.APPLICATION_OCTET_STREAM_TYPE;
                }

                r.getResponse().setContentType(contentType != null ?
                        contentType.toString() : "text/html;charset=ISO-8859-1");

                r.suspend(timeout, comments && !resumeOnBroadcast);
                if (response.getEntity() != null) {
                    response.write();
                }
View Full Code Here

        String address = "http://localhost:" + PORT + "/bookstore/mapperonbus";
        WebClient wc = WebClient.create(address);
        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L);
        Response r = wc.post(null);
        assertEquals(500, r.getStatus());
        MediaType mt = r.getMediaType();
        assertEquals("text/plain;charset=utf-8", mt.toString().toLowerCase());
        assertEquals("the-mapper", r.getHeaderString("BusMapper"));
        assertEquals("BusMapperException", r.readEntity(String.class));
    }
View Full Code Here

            }
        };
    }

    public static Matcher<? super MediaType> hasMediaTypeProfile(final String expectedMediaTypeAndProfileStr) {
        final MediaType expectedMediaType = Header.CONTENT_TYPE.parse(expectedMediaTypeAndProfileStr);
        final String expectedProfileIfAny = expectedMediaType.getParameters().get("profile");
        return new TypeSafeMatcher<MediaType>() {

            @Override
            public void describeTo(Description description) {
                description.appendText("is a media type 'application/json' with a profile parameter of '" +  expectedMediaTypeAndProfileStr + '"');
View Full Code Here

                    }
                    if (mediaType != null && !mediaType.isCompatible(mediaType)) {
                        return false;
                    }
                    if (typeParameterName != null) {
                        final MediaType mediaType = link.getType();
                        final String parameterValue = mediaType.getParameters().get(typeParameterName);
                        if (!typeParameterValue.equals(parameterValue)) {
                            return false;
                        }
                    }
                    if (novalue != null && novalue && link.getValue() != null) {
View Full Code Here

TOP

Related Classes of javax.ws.rs.core.MediaType

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.