Package org.restlet.data

Examples of org.restlet.data.MediaType


    // Add available file formats
    List<MediaType> mediaTypes = new ArrayList<MediaType>();

    for (FileFormat format : registry.getKeys()) {
      for (String mimeType : format.getMIMETypes()) {
        mediaTypes.add(new MediaType(mimeType));
      }
    }

    addCacheableMediaTypes(mediaTypes);
  }
View Full Code Here


  protected final Representation get(Variant variant)
    throws ResourceException
  {
    getResponse().setDimensions(ServerUtil.VARY_ACCEPT);

    MediaType mediaType = variant.getMediaType();

    FF format = registry.getFileFormatForMIMEType(mediaType.getName());

    if (format == null) {
      throw new ResourceException(CLIENT_ERROR_NOT_ACCEPTABLE, "No acceptable file format found.");
    }
View Full Code Here

    if (Method.GET.equals(reqMethod) || Method.HEAD.equals(reqMethod)) {
      return request.getResourceRef().getQueryAsForm();
    }
    else if (Method.POST.equals(reqMethod)) {
      MediaType mediaType = request.getEntity().getMediaType();

      if (MediaType.APPLICATION_WWW_FORM.equals(mediaType, true)) {
        return request.getEntityAsForm();
      }
      else {
View Full Code Here

    throws ResourceException
  {
    vf = valueFactory;
    params = req.getResourceRef().getQueryAsForm();

    MediaType mediaType = req.getEntity().getMediaType();

    if (MediaType.APPLICATION_WWW_FORM.equals(mediaType, true)) {
      // Include parameters from request's body
      params = new Form(params);
      params.addAll(req.getEntityAsForm());
    }
    else if (mediaType != null) {
      throw new ResourceException(CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE, "Unsupported MIME type: "
          + mediaType.getName());
    }
  }
View Full Code Here

        String body = exchange.getIn().getBody(String.class);
        Form form = new Form();
        // add the body as the key in the form with null value
        form.add(body, null);

        MediaType mediaType = exchange.getIn().getHeader(Exchange.CONTENT_TYPE, MediaType.class);
        if (mediaType == null) {
            mediaType = MediaType.APPLICATION_WWW_FORM;
        }

        LOG.debug("Populate Restlet request from exchange body: {} using media type {}", body, mediaType);

        // login and password are filtered by header filter strategy
        String login = exchange.getIn().getHeader(RestletConstants.RESTLET_LOGIN, String.class);
        String password = exchange.getIn().getHeader(RestletConstants.RESTLET_PASSWORD, String.class);

        if (login != null && password != null) {
            ChallengeResponse authentication = new ChallengeResponse(ChallengeScheme.HTTP_BASIC, login, password);
            request.setChallengeResponse(authentication);
            LOG.debug("Basic HTTP Authentication has been applied");
        }

        for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();
            if (!headerFilterStrategy.applyFilterToCamelHeaders(key, value, exchange)) {
                // Use forms only for GET and POST/x-www-form-urlencoded
                if (request.getMethod() == Method.GET || (request.getMethod() == Method.POST && mediaType == MediaType.APPLICATION_WWW_FORM)) {
                    if (key.startsWith("org.restlet.")) {
                        // put the org.restlet headers in attributes
                        request.getAttributes().put(key, value);
                    } else {
                        // put the user stuff in the form
                        form.add(key, value.toString());
                    }
                } else {
                    // For non-form post put all the headers in attributes
                    request.getAttributes().put(key, value);
                }
                LOG.debug("Populate Restlet request from exchange header: {} value: {}", key, value);
            }
        }

        LOG.debug("Using Content Type: {} for POST data: {}", mediaType, body);

        // Only URL Encode for GET and form POST
        if (request.getMethod() == Method.GET || (request.getMethod() == Method.POST && mediaType == MediaType.APPLICATION_WWW_FORM)) {
            request.setEntity(form.getWebRepresentation());
        } else {
            if (body == null) {
                request.setEntity(null);
            } else {
                request.setEntity(body, mediaType);
            }
        }

        MediaType acceptedMediaType = exchange.getIn().getHeader(Exchange.ACCEPT_CONTENT_TYPE, MediaType.class);
        if (acceptedMediaType != null) {
            request.getClientInfo().getAcceptedMediaTypes().add(new Preference<MediaType>(acceptedMediaType));
        }

    }
View Full Code Here

        } else {
            out = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
        }

        // get content type
        MediaType mediaType = out.getHeader(Exchange.CONTENT_TYPE, MediaType.class);
        if (mediaType == null) {
            Object body = out.getBody();
            mediaType = MediaType.TEXT_PLAIN;
            if (body instanceof String) {
                mediaType = MediaType.TEXT_PLAIN;
View Full Code Here

        // set restlet response as header so end user have access to it if needed
        exchange.getOut().setHeader(RestletConstants.RESTLET_RESPONSE, response);

        if (response.getEntity() != null) {
            // get content type
            MediaType mediaType = response.getEntity().getMediaType();
            if (mediaType != null) {
                LOG.debug("Setting the Content-Type to be {}",  mediaType.toString());
                exchange.getOut().setHeader(Exchange.CONTENT_TYPE, mediaType.toString());
            }
            if (mediaType != null && mediaType.equals(MediaType.APPLICATION_OCTET_STREAM)) {
                exchange.getOut().setBody(response.getEntity().getStream());
            } else {
                // get content text
                String text = response.getEntity().getText();
                LOG.debug("Populate exchange from Restlet response: {}", text);
View Full Code Here

            if (header.equalsIgnoreCase(HeaderConstants.HEADER_CONTENT_TYPE)) {
                if (value instanceof MediaType) {
                    message.getEntity().setMediaType((MediaType) value);
                } else {
                    String type = value.toString();
                    MediaType media = MediaType.valueOf(type);
                    if (media != null) {
                        message.getEntity().setMediaType(media);
                    } else {
                        LOG.debug("Header {} with value {} cannot be converted as a MediaType. The value will be ignored.", HeaderConstants.HEADER_CONTENT_TYPE, value);
                    }
View Full Code Here

        String body = exchange.getIn().getBody(String.class);
        Form form = new Form();
        // add the body as the key in the form with null value
        form.add(body, null);

        MediaType mediaType = exchange.getIn().getHeader(Exchange.CONTENT_TYPE, MediaType.class);
        if (mediaType == null) {
            mediaType = MediaType.APPLICATION_WWW_FORM;
        }

        LOG.debug("Populate Restlet request from exchange body: {} using media type {}", body, mediaType);

        // login and password are filtered by header filter strategy
        String login = exchange.getIn().getHeader(RestletConstants.RESTLET_LOGIN, String.class);
        String password = exchange.getIn().getHeader(RestletConstants.RESTLET_PASSWORD, String.class);

        if (login != null && password != null) {
            ChallengeResponse authentication = new ChallengeResponse(ChallengeScheme.HTTP_BASIC, login, password);
            request.setChallengeResponse(authentication);
            LOG.debug("Basic HTTP Authentication has been applied");
        }

        for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();
            if (!headerFilterStrategy.applyFilterToCamelHeaders(key, value, exchange)) {
                // Use forms only for GET and POST/x-www-form-urlencoded
                if (request.getMethod() == Method.GET || (request.getMethod() == Method.POST && mediaType == MediaType.APPLICATION_WWW_FORM)) {
                    if (key.startsWith("org.restlet.")) {
                        // put the org.restlet headers in attributes
                        request.getAttributes().put(key, value);
                    } else {
                        // put the user stuff in the form
                        form.add(key, value.toString());
                    }
                } else {
                    // For non-form post put all the headers in attributes
                    request.getAttributes().put(key, value);
                }
                LOG.debug("Populate Restlet request from exchange header: {} value: {}", key, value);
            }
        }

        LOG.debug("Using Content Type: {} for POST data: {}", mediaType, body);

        // Only URL Encode for GET and form POST
        if (request.getMethod() == Method.GET || (request.getMethod() == Method.POST && mediaType == MediaType.APPLICATION_WWW_FORM)) {
            request.setEntity(form.getWebRepresentation());
        } else {
            request.setEntity(body, mediaType);
        }

        MediaType acceptedMediaType = exchange.getIn().getHeader(Exchange.ACCEPT_CONTENT_TYPE, MediaType.class);
        if (acceptedMediaType != null) {
            request.getClientInfo().getAcceptedMediaTypes().add(new Preference<MediaType>(acceptedMediaType));
        }

    }
View Full Code Here

        } else {
            out = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
        }

        // get content type
        MediaType mediaType = out.getHeader(Exchange.CONTENT_TYPE, MediaType.class);
        if (mediaType == null) {
            Object body = out.getBody();
            mediaType = MediaType.TEXT_PLAIN;
            if (body instanceof String) {
                mediaType = MediaType.TEXT_PLAIN;
View Full Code Here

TOP

Related Classes of org.restlet.data.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.