Examples of ContentType


Examples of org.apache.http.entity.ContentType

        if (answer == null) {
            try {
                Object data = in.getBody();
                if (data != null) {
                    String contentTypeString = ExchangeHelper.getContentType(exchange);
                    ContentType contentType = null;
                    if (contentTypeString != null) {
                        contentType = ContentType.parse(contentTypeString);
                    }
                    if (contentTypeString != null && HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT.equals(contentTypeString)) {
                        // serialized java object
                        Serializable obj = in.getMandatoryBody(Serializable.class);
                        // write object to output stream
                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        HttpHelper.writeObjectToStream(bos, obj);
                        ByteArrayEntity entity = new ByteArrayEntity(bos.toByteArray());
                        entity.setContentType(HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT);
                        IOHelper.close(bos);
                        answer = entity;
                    } else if (data instanceof File || data instanceof GenericFile) {
                        // file based (could potentially also be a FTP file etc)
                        File file = in.getBody(File.class);
                        if (file != null) {
                            if (contentType != null) {
                                answer = new FileEntity(file, contentType);
                            } else {
                                answer = new FileEntity(file);
                            }
                        }
                    } else if (data instanceof String) {
                        // be a bit careful with String as any type can most likely be converted to String
                        // so we only do an instanceof check and accept String if the body is really a String
                        // do not fallback to use the default charset as it can influence the request
                        // (for example application/x-www-form-urlencoded forms being sent)
                        String charset = IOHelper.getCharsetName(exchange, false);
                        if (charset == null && contentType != null) {
                            // okay try to get the charset from the content-type
                            Charset cs = contentType.getCharset();
                            if (cs != null) {
                                charset = cs.name();
                            }
                        }
                        StringEntity entity = new StringEntity((String) data, charset);
                        if (contentType != null) {
                            entity.setContentType(contentType.toString());
                        }
                        answer = entity;
                    }

                    // fallback as input stream
                    if (answer == null) {
                        // force the body as an input stream since this is the fallback
                        InputStream is = in.getMandatoryBody(InputStream.class);
                        InputStreamEntity entity = new InputStreamEntity(is, -1);
                        if (contentType != null) {
                            entity.setContentType(contentType.toString());
                        }
                        answer = entity;
                    }
                }
            } catch (UnsupportedEncodingException e) {
View Full Code Here

Examples of org.apache.http.entity.ContentType

        if (answer == null) {
            try {
                Object data = in.getBody();
                if (data != null) {
                    String contentTypeString = ExchangeHelper.getContentType(exchange);
                    ContentType contentType = null;
                   
                    //Check the contentType is valid or not, If not it throws an exception.
                    //When ContentType.parse parse method parse "multipart/form-data;boundary=---------------------------j2radvtrk",
                    //it removes "boundary" from Content-Type; I have to use contentType.create method.
                    if (contentTypeString != null) {
                        contentType = ContentType.create(contentTypeString);
                    }
                                       
                    if (contentTypeString != null && HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT.equals(contentTypeString)) {
                        // serialized java object
                        Serializable obj = in.getMandatoryBody(Serializable.class);
                        // write object to output stream
                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        HttpHelper.writeObjectToStream(bos, obj);
                        ByteArrayEntity entity = new ByteArrayEntity(bos.toByteArray());
                        entity.setContentType(HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT);
                        IOHelper.close(bos);
                        answer = entity;
                    } else if (data instanceof File || data instanceof GenericFile) {
                        // file based (could potentially also be a FTP file etc)
                        File file = in.getBody(File.class);
                        if (file != null) {
                            if (contentType != null) {
                                answer = new FileEntity(file, contentType);
                            } else {
                                answer = new FileEntity(file);
                            }
                        }
                    } else if (data instanceof String) {
                        // be a bit careful with String as any type can most likely be converted to String
                        // so we only do an instanceof check and accept String if the body is really a String
                        // do not fallback to use the default charset as it can influence the request
                        // (for example application/x-www-form-urlencoded forms being sent)
                        String charset = IOHelper.getCharsetName(exchange, false);
                        if (charset == null && contentType != null) {
                            // okay try to get the charset from the content-type
                            Charset cs = contentType.getCharset();
                            if (cs != null) {
                                charset = cs.name();
                            }
                        }
                        StringEntity entity = new StringEntity((String) data, charset);
                        if (contentType != null) {
                            entity.setContentType(contentType.toString());
                        }
                        answer = entity;
                    }

                    // fallback as input stream
                    if (answer == null) {
                        // force the body as an input stream since this is the fallback
                        InputStream is = in.getMandatoryBody(InputStream.class);
                        InputStreamEntity entity = new InputStreamEntity(is, -1);
                        if (contentType != null) {
                            entity.setContentType(contentType.toString());
                        }
                        answer = entity;
                    }
                }
            } catch (UnsupportedEncodingException e) {
View Full Code Here

Examples of org.apache.jena.atlas.web.ContentType

    // We could have had two step design - ReaderFactory-ReaderInstance
    // no - put the bruden on complicated readers, not everyone.
   
    private static void process(StreamRDF destination, TypedInputStream in, String baseUri, Lang hintLang, Context context)
    {
        ContentType ct = determineCT(baseUri, in.getContentType(), hintLang) ;
        if ( ct == null )
            throw new RiotException("Failed to determine the content type: (URI="+baseUri+" : stream="+in.getContentType()+" : hint="+hintLang+")") ;

        ReaderRIOT reader = getReader(ct) ;
        if ( reader == null )
            throw new RiotException("No parser registered for content type: "+ct.getContentType()) ;
        reader.read(in, baseUri, ct, destination, context) ;
    }
View Full Code Here

Examples of org.apache.lucene.gdata.search.config.IndexSchemaField.ContentType

     */
    public static ContentStrategy getFieldStrategy(IndexSchemaField fieldConfig) {
        if (fieldConfig == null)
            throw new IllegalArgumentException(
                    "field configuration must not be null");
        ContentType type = fieldConfig.getContentType();
        if (type == null)
            throw new IllegalArgumentException(
                    "ContentType in IndexSchemaField must not be null");
        fieldConfig.getAnalyzerClass();

View Full Code Here

Examples of org.apache.marmotta.commons.http.ContentType

    public FacebookGraphEndpoint() {

        super("Facebook Graph API Provider", FacebookGraphProvider.PROVIDER_NAME, "^http(s?)://([^.]+)\\.facebook\\.com/.*", null, 86400L);
        setPriority(PRIORITY_HIGH);
        addContentType(new ContentType("application", "json"));

    }
View Full Code Here

Examples of org.apache.myfaces.tobago.util.ContentType

        throw new ValidatorException(facesMessage);
      }
      // Check only a valid file
      if (file.getSize() > 0 && contentType != null
          && !ContentType.valueOf(contentType).match(ContentType.valueOf(file.getContentType()))) {
        ContentType expectedContentType = ContentType.valueOf(contentType);
        Object [] args = {expectedContentType, component.getId()};
        FacesMessage facesMessage = MessageFactory.createFacesMessage(context,
            CONTENT_TYPE_MESSAGE_ID, FacesMessage.SEVERITY_ERROR, args);
        throw new ValidatorException(facesMessage);
      }
View Full Code Here

Examples of org.apache.olingo.odata2.core.commons.ContentType

            });
    }

    private ContentType getResourceContentType(UriInfoImpl uriInfo) {
        ContentType resourceContentType;
        switch (uriInfo.getUriType()) {
        case URI0:
            // service document
            resourceContentType = SERVICE_DOCUMENT_CONTENT_TYPE;
            break;
View Full Code Here

Examples of org.apache.olingo.odata2.core.commons.ContentType

        }

        ByteArrayInputStream content = null;
        try {
            if (response.getBody() != null) {
                final ContentType partContentType = ContentType.create(
                    headers.get(HttpHeaders.CONTENT_TYPE)).receiveWithCharsetParameter(ContentType.CHARSET_UTF_8);
                final String charset = partContentType.getParameters().get(ContentType.PARAMETER_CHARSET);

                final String body = response.getBody();
                content = body != null ? new ByteArrayInputStream(body.getBytes(charset)) : null;

                httpResponse.setEntity(new StringEntity(body, charset));
View Full Code Here

Examples of org.apache.pluto.om.portlet.ContentType

        PortletEntity entity = portletWindow.getPortletEntity();
        PortletDefinition def = entity.getPortletDefinition();
        ContentTypeSet contentTypes = def.getContentTypeSet();
        Iterator it = contentTypes.iterator();
        while(it.hasNext()) {
            ContentType ct = (ContentType)it.next();
            String supportedType = ct.getContentType();
            if (supportedType.equals(type)) {
                return true;
            } else if (supportedType.indexOf("*") >= 0) {               
                // the supported type contains a wildcard
                int index = supportedType.indexOf("/");
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.internal.ContentType

    this.partMarshallers = new Hashtable<ContentType, PartMarshaller>(5);
    this.partUnmarshallers = new Hashtable<ContentType, PartUnmarshaller>(2);

    try {
      // Add 'default' unmarshaller
      this.partUnmarshallers.put(new ContentType(
          ContentTypes.CORE_PROPERTIES_PART),
          new PackagePropertiesUnmarshaller());

      // Add default marshaller
      this.defaultPartMarshaller = new DefaultMarshaller();
      // TODO Delocalize specialized marshallers
      this.partMarshallers.put(new ContentType(
          ContentTypes.CORE_PROPERTIES_PART),
          new ZipPackagePropertiesMarshaller());
    } catch (InvalidFormatException e) {
      // Should never happen
      throw new OpenXML4JRuntimeException(
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.