Package org.apache.http.entity.mime.content

Examples of org.apache.http.entity.mime.content.StringBody


        String rdfContent = getDummyRdfMetadata(contentItemId, rdfContentType);
        MultipartEntity contentItem = new MultipartEntity(null, null ,UTF8);
        //first the content -> illegal
        contentItem.addPart(
            "content", //the name MUST BE "content"
            new StringBody(HTML_CONTENT,"text/html",UTF8));
        //after that the metadata
        contentItem.addPart(
            "metadata", //the name MUST BE "metadata"
            new StringBody(rdfContent,rdfContentType,UTF8));

        String receivedContent = executor.execute(
            builder.buildPostRequest(getEndpoint())
            .withHeader("Accept","text/rdf+nt")
            .withEntity(contentItem)
View Full Code Here


        String rdfContent = getDummyRdfMetadata(contentItemId, rdfContentType);
        MultipartEntity contentItem = new MultipartEntity(null, null ,UTF8);
        //after that the metadata
        contentItem.addPart(
            "metadata", //the name MUST BE "metadata"
            new StringBody(rdfContent,rdfContentType,UTF8));

        String receivedContent = executor.execute(
            builder.buildPostRequest(getEndpoint())
            .withHeader("Accept","text/rdf+nt")
            .withEntity(contentItem)
View Full Code Here

         *       the Stanbol Enhancer is the same of as the URI used in the
         *       Metadata!
         */
        contentItem.addPart(
            "metadata", //the name MUST BE "metadata"
            new StringBody(rdfContent,SupportedFormat.RDF_XML,UTF8){
                @Override
                public String getFilename() { //The filename MUST BE the
                    return contentItemId.getUnicodeString(); //uri of the ContentItem
                }
            });
        //Add the Content
        /*
         * NOTE: If we only parse a single content than we can also directly
         *       add it with the name "content". This means that the useage of
         *       a "multipart/alternate" container is in such cases optional.
         */
        contentItem.addPart(
            "content", //the name MUST BE "content"
            new StringBody(HTML_CONTENT,"text/html",UTF8));
       
        //send the request
        String receivedContent = executor.execute(
            builder.buildPostRequest(getEndpoint())
            .withHeader("Accept","text/rdf+nt")
View Full Code Here

  public static String createDocument(String token, String path, String url, File file) throws IOException {
    log.info("createDocument(" + token + ", " + path + ", " + url + ", " + file + ")");
    HttpClient client = new DefaultHttpClient();
    MultipartEntity form = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null, Charset.forName("UTF-8"));
    form.addPart("file", new FileBody(file));
    form.addPart("path", new StringBody(path, Charset.forName("UTF-8")));
    form.addPart("action", new StringBody("0")); // FancyFileUpload.ACTION_INSERT
    HttpPost post = new HttpPost(url + "/frontend/FileUpload;jsessionid=" + token);
    post.setHeader("Cookie", "jsessionid=" + token);
    post.setEntity(form);
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String response = client.execute(post, responseHandler);
View Full Code Here

   */
  public static String createFolder(String token, String path, String url, File file) throws IOException {
    log.info("createFolder(" + token + ", " + path + ", " + url + ", " + file + ")");
    HttpClient client = new DefaultHttpClient();
    MultipartEntity form = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null, Charset.forName("UTF-8"));
    form.addPart("folder", new StringBody(file.getName(), Charset.forName("UTF-8")));
    form.addPart("path", new StringBody(path, Charset.forName("UTF-8")));
    form.addPart("action", new StringBody("2")); // FancyFileUpload.ACTION_FOLDER
    HttpPost post = new HttpPost(url + "/frontend/FileUpload;jsessionid=" + token);
    post.setHeader("Cookie", "jsessionid=" + token);
    post.setEntity(form);
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String response = client.execute(post, responseHandler);
View Full Code Here

      if (token != null) {
        // Send image
        HttpClient client = new DefaultHttpClient();
        MultipartEntity form = new MultipartEntity();
        form.addPart("file", new FileBody(tmpFile));
        form.addPart("path", new StringBody(path, Charset.forName("UTF-8")));
        form.addPart("action", new StringBody("0")); // FancyFileUpload.ACTION_INSERT
        HttpPost post = new HttpPost(url + "/frontend/FileUpload;jsessionid=" + token);
        post.setHeader("Cookie", "jsessionid=" + token);
        post.setEntity(form);
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        response = client.execute(post, responseHandler);
View Full Code Here

    public File upload() throws UploadFailureException {
        URI uploadUrl = Urls.uploadBase();
        HttpPost request = new HttpPost(uploadUrl);

        MultipartEntity entity = new MultipartEntity();
        StringBody pubKeyBody = StringBody.create(client.getPublicKey(), "text/plain", null);
        entity.addPart("UPLOADCARE_PUB_KEY", pubKeyBody);
        if (file != null) {
            entity.addPart("file", new FileBody(file));
        } else {
            entity.addPart("file", new ByteArrayBody(bytes, filename));
View Full Code Here

      for(String key: keyOrder) {
        Object value = parameters.get(key);
        if (value instanceof File) {
          builder.addPart(key, new FileBody((File) value));
        } else {
          builder.addPart(key, new StringBody(value.toString(), ContentType.create(ContentType.APPLICATION_FORM_URLENCODED.getMimeType(), Charset.forName(UTF_8))));
        }
      }
      return builder.build();
    } else {
      try {
View Full Code Here

  public void test_AnalyseMissingValueSubmission() throws URISyntaxException, ClientProtocolException, IOException {
    // Simulate multipart html FORM submission.
    MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
   
    // Add type parameter but not value.
    StringBody strBody = new StringBody("web_page");
    reqEntity.addPart("type", strBody);
   
    HttpResponse response = simulateMultiPartFormSubmission(reqEntity);
   
    // HTTP 400, invalid client request.
View Full Code Here

  public void test_AnalyseMissingTypeSubmission() throws URISyntaxException, ClientProtocolException, IOException {
    // Simulate multipart html FORM submission.
    MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
   
    // Add value parameter but not type.
    StringBody strBody = new StringBody("Some content goes here!");
    reqEntity.addPart("value", strBody);

    HttpResponse response = simulateMultiPartFormSubmission(reqEntity);
   
    // HTTP 400, invalid client request.
View Full Code Here

TOP

Related Classes of org.apache.http.entity.mime.content.StringBody

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.