Package org.restlet.data

Examples of org.restlet.data.MediaType


                        }
                        log.info("Entry: "+entryId);
                        String src = null;
                        Element content = entryDoc.getDocumentElement().getFirstElementNamed(AtomResource.CONTENT_NAME);
                        URI baseURI = null;
                        MediaType contentType = null;
                        if (content!=null) {
                           src = content.getAttributeValue("src");
                           String type = content.getAttributeValue("type");
                           if (type!=null) {
                              contentType = MediaType.valueOf(type);
View Full Code Here


         throw new IOException("Exception while getting feed path: "+ex.getMessage());
      }
   }
  
   public Representation post(Representation entity) {
      MediaType postType = entity.getMediaType();
      if (postType.getName().equals(MediaType.APPLICATION_ATOM.getName())) {
         String charset = postType.getParameters().getValues("charset");
         if (charset==null) {
            charset = "UTF-8";
         }
         // Should be an entry
         Document doc = null;
         if (entity instanceof InfosetRepresentation) {
            doc = ((InfosetRepresentation)entity).getDocument();
         } else {
            DocumentLoader loader = new SAXDocumentLoader();
            try {
               Reader r = new InputStreamReader(entity.getStream(),charset);
               doc = loader.load(r);
               r.close();
            } catch (IOException ex) {
               getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
               return new StringRepresentation("I/O error while parsing document: "+ex.getMessage());
            } catch (XMLException ex) {
               getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
               return new StringRepresentation("XML error while parsing document: "+ex.getMessage());
            }
         }
        
         User user = (User)getRequest().getAttributes().get(App.USER_ATTR);
         try {
            Entry entry = app.createEntry(user,feed,doc);
           
            getResponse().setStatus(Status.SUCCESS_CREATED);
            Form headers = new Form();
            getResponse().getAttributes().put("org.restlet.http.headers",headers);
            Reference ref = new Reference(myself+"_/"+entry.getUUID().toString());
            getResponse().setLocationRef(ref);
            Representation rep = new InfosetRepresentation(MediaType.APPLICATION_ATOM,doc);
            rep.setCharacterSet(CharacterSet.UTF_8);
            rep.setTag(new Tag(Long.toString(entry.getEdited().getTime()),false));
            MediaType entryType = new MediaType(rep.getMediaType().getName(),rep.getMediaType().getParameters().createSeries(EntryResource.entryParameters));
            rep.setMediaType(entryType);
            return rep;
           
         } catch (AppException ex) {
            getContext().getLogger().log(Level.SEVERE,ex.getMessage(),ex.getCause());
View Full Code Here

                  }
               }
               Term match = entry.getTerm(T_LAYOUT_MATCH);
               Term mediaTypeT = entry.getTerm(T_LAYOUT_MEDIA_TYPE);
               Term priorityT = entry.getTerm(T_LAYOUT_PRIORITY);
               MediaType mediaType = mediaTypeT==null ? MediaType.APPLICATION_XHTML_XML : MediaType.valueOf(mediaTypeT.getFirstValue());
               String matchValue = match==null ? null : match.getFirstValue();
               if (matchValue==null && match!=null) {
                  // set the value to the empty string
                  matchValue = "";
               }
View Full Code Here

                     URI location = text.getElement().getBaseURI().resolve(text.getSourceLink());
                  }
               } else {
                  query = queryT.getFirstValue();
               }
               MediaType mediaType = mediaTypeT==null ? null : MediaType.valueOf(mediaTypeT.getFirstValue());
               if (info!=null) {
                  getLogger().info("Reloading resource entry "+id+" named "+name);
                  resourceManager.reload(id,entry.getEdited(),name,pathT==null ? null : pathT.getFirstValue(),relationT==null ? null : relationT.getFirstValue(),mediaType,query);
               } else {
                  getLogger().info("Configuring resource entry "+id+" named "+name);
View Full Code Here

      URI resource = (URI)request.getAttributes().get(RESOURCE_ATTR);
      int extPos = path.lastIndexOf('.');
      Application app = this.getApplication();
      Properties resourceProperties = resourceConfig.match(path);
      String stype = resourceProperties.getProperty("content-type");
      MediaType type = stype==null ? null : MediaType.valueOf(stype);
      String defaultExtension = resourceProperties.getProperty("extension");
      if (defaultExtension==null) {
         defaultExtension = ".ats";
      }
      String agentsValue = resourceProperties.getProperty("agents");
     
      String resourceTemplate = resourceProperties.getProperty("resource");
      getLogger().info("resource template: "+resourceTemplate);
      if (resource==null && resourceTemplate!=null) {
         String href = null;
         String uri = null;
         try {
            Template t = new Template(resourceTemplate);
            href = t.format(request.getAttributes());
            String baseURISpec = resourceProperties.getProperty("base-uri");
            URI baseURI = null;
            if (baseURISpec!=null) {
               Template tbase = new Template(baseURISpec);
               uri = tbase.format(request.getAttributes());
               baseURI = new URI(uri);
            }

            resource = baseURI==null ? new URI(href) : baseURI.resolve(href);
         } catch (URISyntaxException ex) {
            getLogger().log(Level.SEVERE,"Cannot construct resource URI, href="+href+", base="+uri,ex);
            return null;
         }
      }
     
      String [] agents = null;
      if (agentsValue!=null) {
         agents = agentsValue.split(",");
      }
     
      MediaType forceType = null;

      if (type==null && extPos>=0) {
         String ext = path.substring(extPos+1);
         Metadata mdata = this.getApplication().getMetadataService().getMetadata(ext);
         if (mdata!=null) {
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.getOut();
        }

        // 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) {
                exchange.getOut().setHeader(Exchange.CONTENT_TYPE, mediaType.toString());
            }

            // 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("Value {} cannot be converted as a MediaType. The value will be ignored.", 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;
        }
       
        if (LOG.isDebugEnabled()) {
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.