當前位置: 首頁>>代碼示例>>Java>>正文


Java StringPart類代碼示例

本文整理匯總了Java中org.apache.commons.httpclient.methods.multipart.StringPart的典型用法代碼示例。如果您正苦於以下問題:Java StringPart類的具體用法?Java StringPart怎麽用?Java StringPart使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


StringPart類屬於org.apache.commons.httpclient.methods.multipart包,在下文中一共展示了StringPart類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildParts

import org.apache.commons.httpclient.methods.multipart.StringPart; //導入依賴的package包/類
private List<Part> buildParts(BaseRequest request) {
    List<Part> parts = new ArrayList<Part>();
    for (PartHolder h : TankHttpUtil.getPartsFromBody(request)) {
        if (h.getFileName() == null) {
            StringPart stringPart = new StringPart(h.getPartName(), new String(h.getBodyAsString()));
            if (h.isContentTypeSet()) {
                stringPart.setContentType(h.getContentType());
            }
            parts.add(stringPart);
        } else {
            PartSource partSource = new ByteArrayPartSource(h.getFileName(), h.getBody());
            FilePart p = new FilePart(h.getPartName(), partSource);
            if (h.isContentTypeSet()) {
                p.setContentType(h.getContentType());
            }
            parts.add(p);
        }
    }
    return parts;
}
 
開發者ID:intuit,項目名稱:Tank,代碼行數:21,代碼來源:TankHttpClient3.java

示例2: addFormDataPart

import org.apache.commons.httpclient.methods.multipart.StringPart; //導入依賴的package包/類
private void addFormDataPart(List<Part> parts, RequestableHttpVariable httpVariable, Object httpVariableValue) throws FileNotFoundException {
	String stringValue = ParameterUtils.toString(httpVariableValue);
	if (httpVariable.getDoFileUploadMode() == DoFileUploadMode.multipartFormData) {
		String filepath = Engine.theApp.filePropertyManager.getFilepathFromProperty(stringValue, getProject().getName());
		File file = new File(filepath);
		if (file.exists()) {
			String charset = httpVariable.getDoFileUploadCharset();
			String type = httpVariable.getDoFileUploadContentType();
			if (org.apache.commons.lang3.StringUtils.isBlank(type)) {
				type = Engine.getServletContext().getMimeType(file.getName());
			}
			parts.add(new FilePart(httpVariable.getHttpName(), file.getName(), file, type, charset));
		} else {
			throw new FileNotFoundException(filepath);
		}
	} else {
		parts.add(new StringPart(httpVariable.getHttpName(), stringValue));
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:20,代碼來源:HttpConnector.java

示例3: buildMultipartPostRequest

import org.apache.commons.httpclient.methods.multipart.StringPart; //導入依賴的package包/類
public PostRequest buildMultipartPostRequest(File file, String filename, String siteId, String containerId) throws IOException
{
    Part[] parts = 
        { 
            new FilePart("filedata", file.getName(), file, "text/plain", null), 
            new StringPart("filename", filename),
            new StringPart("description", "description"), 
            new StringPart("siteid", siteId), 
            new StringPart("containerid", containerId) 
        };

    MultipartRequestEntity multipartRequestEntity = new MultipartRequestEntity(parts, new HttpMethodParams());

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    multipartRequestEntity.writeRequest(os);

    PostRequest postReq = new PostRequest(UPLOAD_URL, os.toByteArray(), multipartRequestEntity.getContentType());
    return postReq;
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:20,代碼來源:UploadWebScriptTest.java

示例4: testPostStringPart

import org.apache.commons.httpclient.methods.multipart.StringPart; //導入依賴的package包/類
/**
 * Test that the body consisting of a string part can be posted.
 */
public void testPostStringPart() throws Exception {
    
    this.server.setHttpService(new EchoService());
    
    PostMethod method = new PostMethod();
    MultipartRequestEntity entity = new MultipartRequestEntity(
        new Part[] { new StringPart("param", "Hello", "ISO-8859-1") },
        method.getParams());
    method.setRequestEntity(entity);
    client.executeMethod(method);

    assertEquals(200,method.getStatusCode());
    String body = method.getResponseBodyAsString();
    assertTrue(body.indexOf("Content-Disposition: form-data; name=\"param\"") >= 0);
    assertTrue(body.indexOf("Content-Type: text/plain; charset=ISO-8859-1") >= 0);
    assertTrue(body.indexOf("Content-Transfer-Encoding: 8bit") >= 0);
    assertTrue(body.indexOf("Hello") >= 0);
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:22,代碼來源:TestMultipartPost.java

示例5: putAsciiFile

import org.apache.commons.httpclient.methods.multipart.StringPart; //導入依賴的package包/類
/**
	*Procedure parameters: Filename which is a string representing a file on the local system
	*Parameters to TeleplanBroker are
	*ExternalAction = "AputAscii"
	*This is a RFC1867 Multi-part post
	*Results from TeleplanBroker are:
	*                                "SUCCESS" 
	*                                "FAILURE"
	*/
	public TeleplanResponse putAsciiFile(File f) throws FileNotFoundException{
            
            Part[] parts = { new StringPart("ExternalAction", "AputAscii"), new FilePart("submitASCII", f) }; 
            return processRequest(CONTACT_URL,parts);

//    my ($filename) = @_;
//    my $request = POST $WEBBASE, Content_type => 'form-data',
//                                 Content      => ['submitASCII'    => [ $filename ], 
//                                                  'ExternalAction' => 'AputAscii'
//                                                 ];
//    my $retVal = processRequest($request);	
//    if ($retVal == $SUCCESS)
//    {#valid response
//       if ($Result ne "SUCCESS")
//       {
//           $retVal = $VALID;
//       }
//    }
//    else
//    {
//       $retVal = $ERROR;
//    }
//    return $retVal;
            
    }
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:35,代碼來源:TeleplanAPI.java

示例6: putMSPFile

import org.apache.commons.httpclient.methods.multipart.StringPart; //導入依賴的package包/類
/**
    *Procedure parameters: Filename which is a string representing a file on the local system
    *Parameters to TeleplanBroker are
    *ExternalAction = "AputRemit"
    *This is a RFC1867 Multi-part post
    *Results from TeleplanBroker are:
    *                                "SUCCESS"
    *                                "FAILURE"
    */
    public TeleplanResponse putMSPFile(File f) throws FileNotFoundException {
        Part[] parts = { new StringPart("ExternalAction", "AputRemit"), new FilePart("submitFile", f) }; 
            return processRequest(CONTACT_URL,parts);
//
//    my ($filename) = @_;
//    my $request = POST $WEBBASE, Content_Type => 'form-data',
//                                 Content      => ['submitFile'    => [ $filename ], 
//                                                  'ExternalAction' => 'AputRemit'
//                                                 ];
//    my $retVal = processRequest($request);	
//    if ($retVal == $SUCCESS)
//    {#valid response
//       if ($Result ne "SUCCESS")
//       {
//           $retVal = $VALID;
//       }
//    }
//    else
//    {
//       $retVal = $ERROR;
//    }
//    return $retVal;
//            return null;
    }
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:34,代碼來源:TeleplanAPI.java

示例7: testSendWithMultipart

import org.apache.commons.httpclient.methods.multipart.StringPart; //導入依賴的package包/類
/** Test whether the HTTP sender able to send the HTTP header with multi-part to our monitor successfully. */
public void testSendWithMultipart() throws Exception 
{
	this.target = new HttpSender(this.testClassLogger, new KVPairData(0)){

		public HttpMethod onCreateRequest() throws Exception 
		{
			PostMethod method = new PostMethod("http://localhost:1999");
			Part[] parts = {
				new StringPart("testparamName", "testparamValue")
			};
			method.setRequestEntity(
				new MultipartRequestEntity(parts, method.getParams())
			);
			return method;
		}		
	};
	this.assertSend();		
}
 
開發者ID:cecid,項目名稱:hermes,代碼行數:20,代碼來源:HttpSenderUnitTest.java

示例8: testSendMultiPartForm

import org.apache.commons.httpclient.methods.multipart.StringPart; //導入依賴的package包/類
@Test
public void testSendMultiPartForm() throws Exception {
    HttpClient httpclient = new HttpClient();
    File file = new File("src/main/resources/META-INF/NOTICE.txt");
    PostMethod httppost = new PostMethod("http://localhost:" + getPort() + "/test");
    Part[] parts = {
        new StringPart("comment", "A binary file of some kind"),
        new FilePart(file.getName(), file)
    };

    MultipartRequestEntity reqEntity = new MultipartRequestEntity(parts, httppost.getParams());
    httppost.setRequestEntity(reqEntity);

    int status = httpclient.executeMethod(httppost);

    assertEquals("Get a wrong response status", 200, status);

    String result = httppost.getResponseBodyAsString();
    assertEquals("Get a wrong result", "A binary file of some kind", result);
    assertNotNull("Did not use custom multipart filter", httppost.getResponseHeader("MyMultipartFilter"));
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:22,代碼來源:MultiPartFormWithCustomFilterTest.java

示例9: testSendMultiPartFormOverrideEnableMultpartFilterFalse

import org.apache.commons.httpclient.methods.multipart.StringPart; //導入依賴的package包/類
@Test
public void testSendMultiPartFormOverrideEnableMultpartFilterFalse() throws Exception {
    HttpClient httpclient = new HttpClient();

    File file = new File("src/main/resources/META-INF/NOTICE.txt");

    PostMethod httppost = new PostMethod("http://localhost:" + getPort() + "/test2");
    Part[] parts = {
        new StringPart("comment", "A binary file of some kind"),
        new FilePart(file.getName(), file)
    };

    MultipartRequestEntity reqEntity = new MultipartRequestEntity(parts, httppost.getParams());
    httppost.setRequestEntity(reqEntity);

    int status = httpclient.executeMethod(httppost);

    assertEquals("Get a wrong response status", 200, status);
    assertNotNull("Did not use custom multipart filter", httppost.getResponseHeader("MyMultipartFilter"));
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:21,代碼來源:MultiPartFormWithCustomFilterTest.java

示例10: testHttpClient

import org.apache.commons.httpclient.methods.multipart.StringPart; //導入依賴的package包/類
@Test
public void testHttpClient() throws Exception {
    File jpg = new File("src/test/resources/java.jpg");
    String body = "TEST";
    Part[] parts = new Part[] {new StringPart("body", body), new FilePart(jpg.getName(), jpg)};
    
    PostMethod method = new PostMethod("http://localhost:" + port2 + "/test/hello");
    MultipartRequestEntity requestEntity = new MultipartRequestEntity(parts, method.getParams());
    method.setRequestEntity(requestEntity);
    
    HttpClient client = new HttpClient();
    client.executeMethod(method);
    
    String responseBody = method.getResponseBodyAsString();
    assertEquals(body, responseBody);
    
    String numAttachments = method.getResponseHeader("numAttachments").getValue();
    assertEquals(numAttachments, "2");
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:20,代碼來源:HttpBridgeMultipartRouteTest.java

示例11: testUploadFile

import org.apache.commons.httpclient.methods.multipart.StringPart; //導入依賴的package包/類
@Test
public void testUploadFile() throws IOException, URISyntaxException {
    final HttpClient c = loginWithCookie("administrator", "olat");

    final URI uri = UriBuilder.fromUri(getNodeURI()).path("files").build();

    // create single page
    final URL fileUrl = RepositoryEntriesITCase.class.getResource("singlepage.html");
    assertNotNull(fileUrl);
    final File file = new File(fileUrl.toURI());

    final PutMethod method = createPut(uri, MediaType.APPLICATION_JSON, true);
    method.addRequestHeader("Content-Type", MediaType.MULTIPART_FORM_DATA);
    final Part[] parts = { new FilePart("file", file), new StringPart("filename", file.getName()) };
    method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams()));
    final int code = c.executeMethod(method);
    assertEquals(code, 200);

    final OlatNamedContainerImpl folder = BCCourseNode.getNodeFolderContainer((BCCourseNode) bcNode, course1.getCourseEnvironment());
    final VFSItem item = folder.resolve(file.getName());
    assertNotNull(item);
}
 
開發者ID:huihoo,項目名稱:olat,代碼行數:23,代碼來源:CoursesFoldersITCase.java

示例12: getExtractivProcessString

import org.apache.commons.httpclient.methods.multipart.StringPart; //導入依賴的package包/類
private static PostMethod getExtractivProcessString(
                            final URI extractivURI, 
                            final String content,
                            final String serviceKey) throws FileNotFoundException 
{

    final PartBase filePart = new StringPart("content", content, null);

    // bytes to upload
    final ArrayList<Part> message = new ArrayList<Part>();
    message.add(filePart);
    message.add(new StringPart("formids", "content"));
    message.add(new StringPart("output_format", "JSON"));
    message.add(new StringPart("api_key", serviceKey));
   
    final Part[] messageArray = message.toArray(new Part[0]);

    // Use a Post for the file upload
    final PostMethod postMethod = new PostMethod(extractivURI.toString());
    postMethod.setRequestEntity(new MultipartRequestEntity(messageArray, postMethod.getParams()));
    postMethod.addRequestHeader("Accept-Encoding", "gzip"); // Request the response be compressed (this is highly recommended)

    return postMethod;
}
 
開發者ID:NERD-project,項目名稱:nerd-api,代碼行數:25,代碼來源:ExtractivClient.java

示例13: getJsonPostForMultipartRequestEntity

import org.apache.commons.httpclient.methods.multipart.StringPart; //導入依賴的package包/類
/**
 * <p>This creates a HttpMethod with the message as its payload and image attachment. The message should be a properly formatted JSON
 * String (No validation is done on this).</p>
 *
 * <p>The message can be easily created using the {@link #getJsonPayload(Message)} method.</p>
 *
 * @param uri The full URI which we will post to
 * @param message A properly formatted JSON message. UTF-8 is expected
 * @param image A complete instance of ImageAttachment object
 * @throws IOException
 */
public HttpMethod getJsonPostForMultipartRequestEntity(String uri, String message, ImageAttachment image) throws IOException {
    PostMethod post = new PostMethod(uri);

    StringPart bodyPart = new StringPart("json", message);
    bodyPart.setContentType("application/json");

    FilePart filePart= new FilePart("feedItemFileUpload", image.retrieveObjectFile());
    filePart.setContentType(image.retrieveContentType());

    Part[] parts = {
            bodyPart,
            filePart,
    };

    post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));

    return post;
}
 
開發者ID:forcedotcom,項目名稱:JavaChatterRESTApi,代碼行數:30,代碼來源:ChatterCommands.java

示例14: addVariableToQuery

import org.apache.commons.httpclient.methods.multipart.StringPart; //導入依賴的package包/類
@Override
protected String addVariableToQuery(String methodToAnalyse, String httpVariable, String httpVariableValue, String query, String urlEncodingCharset, boolean firstParam) throws UnsupportedEncodingException {
	if (methodToAnalyse.equalsIgnoreCase("POST")) {
		parts.add(new StringPart(httpVariable, httpVariableValue));
		return "";
	} else {
		return super.addVariableToQuery(methodToAnalyse, httpVariable, httpVariableValue, query, urlEncodingCharset, firstParam);
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:10,代碼來源:HTTPUploadStatement.java

示例15: getPostMultiPartWithFiles

import org.apache.commons.httpclient.methods.multipart.StringPart; //導入依賴的package包/類
private PostMethod getPostMultiPartWithFiles(PostMethod method, KalturaParams kparams, KalturaFiles kfiles) {

   	String boundary = "---------------------------" + System.currentTimeMillis();
   	List <Part> parts = new ArrayList<Part>();
   	parts.add(new StringPart (HttpMethodParams.MULTIPART_BOUNDARY, boundary));

   	for(Entry<String, String> itr : kparams.entrySet()) {
   		parts.add(new StringPart (itr.getKey(), itr.getValue()));       
   	}
   	
   	for (String key : kfiles.keySet()) {
   	    final KalturaFile kFile = kfiles.get(key);
   	    parts.add(new StringPart (key, "filename="+kFile.getName()));
   	    if (kFile.getFile() != null) {
   	        // use the file
   	        File file = kFile.getFile();
   	        try {
   	            parts.add(new FilePart(key, file));
   	        } catch (FileNotFoundException e) {
   	            // TODO this sort of leaves the submission in a weird state... -AZ
   	            logger.error("Exception while iterating over kfiles", e);          
   	        }
   	    } else {
   	        // use the input stream
   	        PartSource fisPS = new PartSource() {
   	            public long getLength() {
   	                return kFile.getSize();
   	            }
   	            public String getFileName() {
   	                return kFile.getName();
   	            }
   	            public InputStream createInputStream() throws IOException {
   	                return kFile.getInputStream();
   	            }
   	        };
   	        parts.add(new FilePart(key, fisPS));
   	    }
   	}
    
   	Part allParts[] = new Part[parts.size()];
   	allParts = parts.toArray(allParts);
    
   	method.setRequestEntity(new MultipartRequestEntity(allParts, method.getParams()));

   	return method;
   }
 
開發者ID:ITYug,項目名稱:kaltura-ce-sakai-extension,代碼行數:47,代碼來源:KalturaClientBase.java


注:本文中的org.apache.commons.httpclient.methods.multipart.StringPart類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。