List of usage examples for org.apache.http.entity ContentType create
public static ContentType create(String str, String str2) throws UnsupportedCharsetException
From source file:org.elasticsearch.client.RequestConverters.java
/** * Returns a {@link ContentType} from a given {@link XContentType}. * * @param xContentType the {@link XContentType} * @return the {@link ContentType}//ww w .j a v a 2 s. c o m */ @SuppressForbidden(reason = "Only allowed place to convert a XContentType to a ContentType") public static ContentType createContentType(final XContentType xContentType) { return ContentType.create(xContentType.mediaTypeWithoutParameters(), (Charset) null); }
From source file:edu.isi.karma.er.helper.TripleStoreUtil.java
/** * @param filePath// ww w . ja v a2 s. c o m * : the url of the file from where the RDF is read * @param tripleStoreURL * : the triple store URL * @param context * : The graph context for the RDF * @param replaceFlag * : Whether to replace the contents of the graph deleteSrcFile * default : false rdfType default: Turtle * @param baseUri * : The graph context for the RDF * * */ public boolean saveToStoreFromFile(String filePath, String tripleStoreURL, String context, boolean replaceFlag, String baseUri) throws KarmaException { File file = new File(filePath); FileEntity entity = new FileEntity(file, ContentType.create(mime_types.get(RDF_Types.Turtle.name()), "UTF-8")); return saveToStore(entity, tripleStoreURL, context, replaceFlag, RDF_Types.Turtle.name(), baseUri); }
From source file:com.adobe.aem.demo.communities.Loader.java
private static String doThumbnail(String hostname, String port, String adminPassword, String csvfile, String filename) {//from w w w .j av a2s.com String pathToFile = "/content/dam/communities/resource-thumbnails/" + filename; File attachment = new File(csvfile.substring(0, csvfile.indexOf(".csv")) + File.separator + filename); ContentType ct = ContentType.MULTIPART_FORM_DATA; if (filename.indexOf(".mp4") > 0) { ct = ContentType.create("video/mp4", MIME.UTF8_CHARSET); } else if (filename.indexOf(".jpg") > 0 || filename.indexOf(".jpeg") > 0) { ct = ContentType.create("image/jpeg", MIME.UTF8_CHARSET); } else if (filename.indexOf(".png") > 0) { ct = ContentType.create("image/png", MIME.UTF8_CHARSET); } MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setCharset(MIME.UTF8_CHARSET); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); builder.addBinaryBody("file", attachment, ct, attachment.getName()); builder.addTextBody("fileName", filename, ContentType.create("text/plain", MIME.UTF8_CHARSET)); logger.debug( "Adding file for thumbnails with name: " + attachment.getName() + " and type: " + ct.getMimeType()); Loader.doPost(hostname, port, pathToFile, "admin", adminPassword, builder.build(), null); logger.debug("Path to thumbnail: " + pathToFile); return pathToFile + "/file"; }
From source file:org.jets3t.service.CloudFrontService.java
/** * Update a streaming or non-streaming distribution. * * @param config Configuration properties to apply to the distribution. * @return Information about the updated distribution configuration. * @throws CloudFrontServiceException/* www.j av a 2 s . c om*/ */ protected DistributionConfig updateDistributionConfigImpl(String id, DistributionConfig config) throws CloudFrontServiceException { if (log.isDebugEnabled()) { log.debug("Updating configuration of " + (config.isStreamingDistributionConfig() ? "streaming" : "") + "distribution with id: " + id); } String etag = config.getEtag(); if (null == etag) { // Retrieve the old configuration. DistributionConfig oldConfig = (config.isStreamingDistributionConfig() ? getStreamingDistributionConfig(id) : getDistributionConfig(id)); etag = oldConfig.getEtag(); } HttpPut httpMethod = new HttpPut(ENDPOINT + VERSION + (config.isStreamingDistributionConfig() ? "/streaming-distribution/" : "/distribution/") + id + "/config"); try { String distributionConfigXml = buildDistributionConfigXmlDocument(config); httpMethod.setEntity(new StringEntity(distributionConfigXml, ContentType.create("text/xml", Constants.DEFAULT_ENCODING))); httpMethod.setHeader("If-Match", etag); HttpResponse response = performRestRequest(httpMethod, 200); DistributionConfigHandler handler = (new CloudFrontXmlResponsesSaxParser(this.jets3tProperties)) .parseDistributionConfigResponse(response.getEntity().getContent()); DistributionConfig resultConfig = handler.getDistributionConfig(); resultConfig.setEtag(response.getFirstHeader("ETag").getValue()); return resultConfig; } catch (CloudFrontServiceException e) { throw e; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new CloudFrontServiceException(e); } }
From source file:org.jets3t.service.CloudFrontService.java
/** * Create a new Origin Access Identity/*from w w w .ja v a 2 s . c o m*/ * * @param callerReference A user-set unique reference value that ensures the request can't be replayed * (max UTF-8 encoding size 128 bytes). This parameter may be null, in which * case your computer's local epoch time in milliseconds will be used. * @param comment An optional comment to describe the identity (max 128 characters). May be null. * @return The origin access identity's properties. * @throws CloudFrontServiceException */ public OriginAccessIdentity createOriginAccessIdentity(String callerReference, String comment) throws CloudFrontServiceException { if (log.isDebugEnabled()) { log.debug("Creating origin access identity"); } HttpPost httpMethod = new HttpPost(ENDPOINT + VERSION + ORIGIN_ACCESS_IDENTITY_URI_PATH); if (callerReference == null) { callerReference = String.valueOf(System.currentTimeMillis()); } try { XMLBuilder builder = XMLBuilder.create("CloudFrontOriginAccessIdentityConfig").a("xmlns", XML_NAMESPACE) .e("CallerReference").t(callerReference).up().e("Comment").t(comment); httpMethod.setEntity(new StringEntity(builder.asString(null), ContentType.create("text/xml", Constants.DEFAULT_ENCODING))); HttpResponse response = performRestRequest(httpMethod, 201); OriginAccessIdentityHandler handler = (new CloudFrontXmlResponsesSaxParser(this.jets3tProperties)) .parseOriginAccessIdentity(response.getEntity().getContent()); return handler.getOriginAccessIdentity(); } catch (CloudFrontServiceException e) { throw e; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new CloudFrontServiceException(e); } }
From source file:org.jets3t.service.CloudFrontService.java
/** * Update the properties of an Origin Access Identity. * * @param id The identifier of the Origin Access Identity. * @param comment A new comment to apply to the identity. * @return The origin access identity's configuration properties. * @throws CloudFrontServiceException//from w ww. j ava2 s .c om */ public OriginAccessIdentityConfig updateOriginAccessIdentityConfig(String id, String comment) throws CloudFrontServiceException { if (log.isDebugEnabled()) { log.debug("Updating configuration of origin access identity with id: " + id); } // Retrieve the old configuration. OriginAccessIdentityConfig oldConfig = getOriginAccessIdentityConfig(id); // Sanitize parameters. if (comment == null) { comment = oldConfig.getComment(); } HttpPut httpMethod = new HttpPut( ENDPOINT + VERSION + ORIGIN_ACCESS_IDENTITY_URI_PATH + "/" + id + "/config"); try { XMLBuilder builder = XMLBuilder.create("CloudFrontOriginAccessIdentityConfig").a("xmlns", XML_NAMESPACE) .e("CallerReference").t(oldConfig.getCallerReference()).up().e("Comment").t(comment); httpMethod.setEntity(new StringEntity(builder.asString(null), ContentType.create("text/xml", Constants.DEFAULT_ENCODING))); httpMethod.setHeader("If-Match", oldConfig.getEtag()); HttpResponse response = performRestRequest(httpMethod, 200); OriginAccessIdentityConfigHandler handler = (new CloudFrontXmlResponsesSaxParser(this.jets3tProperties)) .parseOriginAccessIdentityConfig(response.getEntity().getContent()); OriginAccessIdentityConfig config = handler.getOriginAccessIdentityConfig(); config.setEtag(response.getFirstHeader("ETag").getValue()); return config; } catch (CloudFrontServiceException e) { throw e; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new CloudFrontServiceException(e); } }
From source file:org.jets3t.service.CloudFrontService.java
/** * Remove distribution objects from a CloudFront edge server cache to force * a refresh of the object data from the S3 origin. * * @param distributionId The distribution's unique identifier. * @param objectKeys S3 object key names of object(s) to invalidate. * @param callerReference Unique description for this distribution config * @return invalidation object// w w w . j av a2 s. c o m * @throws CloudFrontServiceException exception */ public Invalidation invalidateObjects(String distributionId, String[] objectKeys, String callerReference) throws CloudFrontServiceException { HttpPost httpMethod = new HttpPost( ENDPOINT + VERSION + "/distribution/" + distributionId + "/invalidation"); try { XMLBuilder builder = XMLBuilder.create("InvalidationBatch"); XMLBuilder paths = builder.e("Paths"); paths.e("Quantity").t(String.valueOf(objectKeys.length)); XMLBuilder items = paths.e("Items"); for (String objectPath : objectKeys) { String encodedPath = RestUtils.encodeUrlPath(objectPath, "/"); if (!encodedPath.startsWith("/")) { encodedPath = "/" + encodedPath; } items.e("Path").t(encodedPath); } builder.e("CallerReference").t(callerReference); httpMethod.setEntity(new StringEntity(builder.asString(null), ContentType.create("text/xml", Constants.DEFAULT_ENCODING))); HttpResponse response = performRestRequest(httpMethod, 201); InvalidationHandler handler = (new CloudFrontXmlResponsesSaxParser(this.jets3tProperties)) .parseInvalidationResponse(response.getEntity().getContent()); return handler.getInvalidation(); } catch (CloudFrontServiceException e) { throw e; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new CloudFrontServiceException(e); } }
From source file:com.adobe.aem.demomachine.communities.Loader.java
private static String doThumbnail(ResourceResolver rr, LinkedList<InputStream> lIs, String hostname, String port, String adminPassword, String csvfile, String filename, String sitename, int maxretries) { if (filename == null || filename.equals("")) return null; String pathToFile = "/content/dam/resources/resource-thumbnails/" + sitename + "/" + filename; MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setCharset(MIME.UTF8_CHARSET); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); addBinaryBody(builder, lIs, rr, "file", csvfile, filename); builder.addTextBody("fileName", filename, ContentType.create("text/plain", MIME.UTF8_CHARSET)); logger.debug("Posting file for thumbnails with name: " + filename); Loader.doPost(hostname, port, pathToFile, "admin", adminPassword, builder.build(), null); doWaitWorkflows(hostname, port, adminPassword, "thumbnail", maxretries); return pathToFile + "/file"; }
From source file:com.adobe.aem.demomachine.communities.Loader.java
private static ContentType getContentType(String fileName) { ContentType ct = ContentType.MULTIPART_FORM_DATA; if (fileName.indexOf(".mp4") > 0) { ct = ContentType.create("video/mp4", MIME.UTF8_CHARSET); } else if (fileName.indexOf(".jpg") > 0 || fileName.indexOf(".jpeg") > 0) { ct = ContentType.create("image/jpeg", MIME.UTF8_CHARSET); } else if (fileName.indexOf(".png") > 0) { ct = ContentType.create("image/png", MIME.UTF8_CHARSET); } else if (fileName.indexOf(".pdf") > 0) { ct = ContentType.create("application/pdf", MIME.UTF8_CHARSET); } else if (fileName.indexOf(".css") > 0) { ct = ContentType.create("text/css", MIME.UTF8_CHARSET); } else if (fileName.indexOf(".zip") > 0) { ct = ContentType.create("application/zip", MIME.UTF8_CHARSET); }// w w w .j a va 2 s. co m return ct; }