当前位置: 首页>>代码示例>>Java>>正文


Java RequestEntity类代码示例

本文整理汇总了Java中org.apache.commons.httpclient.methods.RequestEntity的典型用法代码示例。如果您正苦于以下问题:Java RequestEntity类的具体用法?Java RequestEntity怎么用?Java RequestEntity使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RequestEntity类属于org.apache.commons.httpclient.methods包,在下文中一共展示了RequestEntity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loginToOntarioMD

import org.apache.commons.httpclient.methods.RequestEntity; //导入依赖的package包/类
public Hashtable loginToOntarioMD(String username,String password,String incomingRequestor) throws Exception{
    //public ArrayList soapHttpCall(int siteCode, String userId, String passwd,		String xml) throws Exception
    Hashtable h  = null;
    PostMethod post = new PostMethod("https://www.ontariomd.ca/services/OMDAutomatedAuthentication");
    post.setRequestHeader("SOAPAction", "");
    post.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

    String soapMsg = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><ns1:getSession xmlns:ns1=\"urn:OMDAutomatedAuthentication\"><username>"+username+"</username><password>"+password+"</password><incomingRequestor>"+incomingRequestor+"</incomingRequestor></ns1:getSession></soap:Body></soap:Envelope> ";

    RequestEntity re = new StringRequestEntity(soapMsg, "text/xml", "utf-8");

    post.setRequestEntity(re);

    HttpClient httpclient = new HttpClient();
    // Execute request
    try{
            httpclient.executeMethod(post);
            h = parseReturn(post.getResponseBodyAsStream());
    }catch(Exception e ){
        MiscUtils.getLogger().error("Error", e);
    } finally{
            // Release current connection to the connection pool
            post.releaseConnection();
    }
    return h;
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:27,代码来源:OntarioMD.java

示例2: createMultiPartRequestContentWithDataTest

import org.apache.commons.httpclient.methods.RequestEntity; //导入依赖的package包/类
/**
 * Test 
 * 
 * @throws  Exception
 *          Any exception
 */
@Test
public void createMultiPartRequestContentWithDataTest() throws Exception
{
    String string="FILE_DATA";
    File file=File.createTempFile("temp_",".txt");
    file.deleteOnExit();
    byte[] input=string.getBytes(IOHelper.getDefaultEncoding());
    IOHelper.writeFile(input,file);

    HTTPRequest httpRequest=new HTTPRequest();
    ContentPart<?>[] parts=new ContentPart[5];  //make array bigger to simulate null parts
    parts[0]=new ContentPart<String>("string_part","TEST_DATA",ContentPartType.STRING);
    parts[1]=new ContentPart<String>("string_part2","TEST_DATA2",ContentPartType.STRING);
    parts[2]=new ContentPart<File>("file_part",file,ContentPartType.FILE);
    httpRequest.setContent(parts);
    HttpMethodBase method=this.client.createMethod("http://fax4j.org",HTTPMethod.POST);
    RequestEntity output=this.client.createMultiPartRequestContent(httpRequest,method);
    
    file.delete();

    Assert.assertNotNull(output);
    Assert.assertEquals(MultipartRequestEntity.class,output.getClass());
}
 
开发者ID:sagiegurari,项目名称:fax4j,代码行数:30,代码来源:ApacheHTTPClientTest.java

示例3: createRequestEntity

import org.apache.commons.httpclient.methods.RequestEntity; //导入依赖的package包/类
/**
 * Creates the request entity that makes up the POST message body.
 * 
 * @param message message to be sent
 * @param charset character set used for the message
 * 
 * @return request entity that makes up the POST message body
 * 
 * @throws SOAPClientException thrown if the message could not be marshalled
 */
protected RequestEntity createRequestEntity(Envelope message, Charset charset) throws SOAPClientException {
    try {
        Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(message);
        ByteArrayOutputStream arrayOut = new ByteArrayOutputStream();
        OutputStreamWriter writer = new OutputStreamWriter(arrayOut, charset);

        if (log.isDebugEnabled()) {
            log.debug("Outbound SOAP message is:\n" + XMLHelper.prettyPrintXML(marshaller.marshall(message)));
        }
        XMLHelper.writeNode(marshaller.marshall(message), writer);
        return new ByteArrayRequestEntity(arrayOut.toByteArray(), "text/xml");
    } catch (MarshallingException e) {
        throw new SOAPClientException("Unable to marshall SOAP envelope", e);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:HttpSOAPClient.java

示例4: testEnclosedEntityAutoLength

import org.apache.commons.httpclient.methods.RequestEntity; //导入依赖的package包/类
public void testEnclosedEntityAutoLength() throws Exception {
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, InputStreamRequestEntity.CONTENT_LENGTH_AUTO); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        assertEquals(200, method.getStatusCode());
        String body = method.getResponseBodyAsString();
        assertEquals(inputstr, body);
        assertNull(method.getRequestHeader("Transfer-Encoding"));
        assertNotNull(method.getRequestHeader("Content-Length"));
        assertEquals(input.length, Integer.parseInt(
                method.getRequestHeader("Content-Length").getValue()));
    } finally {
        method.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:24,代码来源:TestEntityEnclosingMethod.java

示例5: testEnclosedEntityExplicitLength

import org.apache.commons.httpclient.methods.RequestEntity; //导入依赖的package包/类
public void testEnclosedEntityExplicitLength() throws Exception {
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, 14); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        assertEquals(200, method.getStatusCode());
        String body = method.getResponseBodyAsString();
        assertEquals("This is a test", body);
        assertNull(method.getRequestHeader("Transfer-Encoding"));
        assertNotNull(method.getRequestHeader("Content-Length"));
        assertEquals(14, Integer.parseInt(
                method.getRequestHeader("Content-Length").getValue()));
    } finally {
        method.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:24,代码来源:TestEntityEnclosingMethod.java

示例6: testEnclosedEntityChunked

import org.apache.commons.httpclient.methods.RequestEntity; //导入依赖的package包/类
public void testEnclosedEntityChunked() throws Exception {
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, InputStreamRequestEntity.CONTENT_LENGTH_AUTO); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    method.setContentChunked(true);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        assertEquals(200, method.getStatusCode());
        String body = method.getResponseBodyAsString();
        assertEquals(inputstr, body);
        assertNotNull(method.getRequestHeader("Transfer-Encoding"));
        assertNull(method.getRequestHeader("Content-Length"));
    } finally {
        method.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:23,代码来源:TestEntityEnclosingMethod.java

示例7: testEnclosedEntityChunkedHTTP1_0

import org.apache.commons.httpclient.methods.RequestEntity; //导入依赖的package包/类
public void testEnclosedEntityChunkedHTTP1_0() throws Exception {
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, InputStreamRequestEntity.CONTENT_LENGTH_AUTO); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    method.setContentChunked(true);
    method.getParams().setVersion(HttpVersion.HTTP_1_0);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        fail("ProtocolException should have been thrown");
    } catch (ProtocolException ex) {
        // expected
    } finally {
        method.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:22,代码来源:TestEntityEnclosingMethod.java

示例8: testEnclosedEntityNegativeLength

import org.apache.commons.httpclient.methods.RequestEntity; //导入依赖的package包/类
public void testEnclosedEntityNegativeLength() throws Exception {
    
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, -14); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    method.setContentChunked(false);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        assertEquals(200, method.getStatusCode());
        String body = method.getResponseBodyAsString();
        assertEquals(inputstr, body);
        assertNotNull(method.getRequestHeader("Transfer-Encoding"));
        assertNull(method.getRequestHeader("Content-Length"));
    } finally {
        method.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:24,代码来源:TestEntityEnclosingMethod.java

示例9: testEnclosedEntityNegativeLengthHTTP1_0

import org.apache.commons.httpclient.methods.RequestEntity; //导入依赖的package包/类
public void testEnclosedEntityNegativeLengthHTTP1_0() throws Exception {
    
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, -14); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    method.setContentChunked(false);
    method.getParams().setVersion(HttpVersion.HTTP_1_0);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        fail("ProtocolException should have been thrown");
    } catch (ProtocolException ex) {
        // expected
    } finally {
        method.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:23,代码来源:TestEntityEnclosingMethod.java

示例10: verifyEncoding

import org.apache.commons.httpclient.methods.RequestEntity; //导入依赖的package包/类
private void verifyEncoding(RequestEntity entity, int[] sample)
 throws IOException  {
    
    assertNotNull("Request body", entity);

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    entity.writeRequest(bos);
    
    InputStream instream = new ByteArrayInputStream(bos.toByteArray());
    for (int i = 0; i < sample.length; i++) {
        int b = instream.read();
        assertTrue("Unexpected end of stream", b != -1);
        if (sample[i] != b) {
            fail("Invalid request body encoding");
        }
    }
    assertTrue("End of stream expected", instream.read() == -1);
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:19,代码来源:TestMethodCharEncoding.java

示例11: getPostResponseHeader

import org.apache.commons.httpclient.methods.RequestEntity; //导入依赖的package包/类
public static String getPostResponseHeader(String url,String argJson,List<UHeader> headerList,String headerName){
  	String info = "";
  	try {
   	HttpClient client = new HttpClient();
	PostMethod method = new PostMethod(url);
	client.getParams().setContentCharset("UTF-8");
	if(headerList.size()>0){
		for(int i = 0;i<headerList.size();i++){
			UHeader header = headerList.get(i);
			method.setRequestHeader(header.getHeaderTitle(),header.getHeaderValue());
		}
	}
	method.getParams().setParameter(
			HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
	if(argJson != null && !argJson.trim().equals("")) {
		RequestEntity requestEntity = new StringRequestEntity(argJson,"application/json","UTF-8");
		method.setRequestEntity(requestEntity);
	}
	method.releaseConnection();
	Header h =  method.getResponseHeader(headerName);
	info = h.getValue();
} catch (IOException e) {
	e.printStackTrace();
}
  	return info;
  }
 
开发者ID:noseparte,项目名称:Spring-Boot-Server,代码行数:27,代码来源:HttpUtils.java

示例12: createUser

import org.apache.commons.httpclient.methods.RequestEntity; //导入依赖的package包/类
/**
 * creates a user in Zendesk. UserXml is passed as request body.
 * 
 * @param httpClient
 * @param userXml
 * @return
 * @throws HttpException
 * @throws IOException
 */
private int createUser(HttpClient httpClient, String userXml) throws Exception {

  PostMethod post = new PostMethod(cadURL + "/object/user?_type=xml");
  post.addRequestHeader("Content-Type", "application/xml");
  RequestEntity entity = new StringRequestEntity(userXml, "application/xml", "ISO-8859-1");
  post.setRequestEntity(entity);
  int result = 0;
  try {
    System.out.println("URI: " + post.getURI());
    result = httpClient.executeMethod(post);
    System.out.println("Response status code: " + result);
    System.out.println("Response body: " + post.getResponseBodyAsString());

  } catch (final Exception e) {
    throw e;
  } finally {
    if (post != null) {
      post.releaseConnection();
    }
  }
  return result;
}
 
开发者ID:inbravo,项目名称:scribe,代码行数:32,代码来源:ZenDeskTest.java

示例13: createLead

import org.apache.commons.httpclient.methods.RequestEntity; //导入依赖的package包/类
/**
 * creates a Lead in MS. Lead Xml is passed as request body.
 * 
 * @param httpClient
 * @param leadXml
 * @return
 * @throws HttpException
 * @throws IOException
 */
private final int createLead(final HttpClient httpClient, final String leadXml) throws Exception {

  final PostMethod post = new PostMethod(cadURL + "/object/lead?_type=xml");
  post.addRequestHeader("Content-Type", "application/xml");
  RequestEntity entity = new StringRequestEntity(leadXml, "application/xml", "ISO-8859-1");
  post.setRequestEntity(entity);
  int result = 0;
  try {
    result = httpClient.executeMethod(post);
  } catch (final Exception e) {
    throw e;
  } finally {
    if (post != null) {
      post.releaseConnection();
    }
  }
  return result;
}
 
开发者ID:inbravo,项目名称:scribe,代码行数:28,代码来源:MicroSoftLeadTest.java

示例14: createOpportunity

import org.apache.commons.httpclient.methods.RequestEntity; //导入依赖的package包/类
/**
 * creates an opportunity in MS. opportunity Xml is passed as request body.
 * 
 * @param httpClient
 * @param opportunityXml
 * @return
 * @throws HttpException
 * @throws IOException
 */
private final int createOpportunity(final HttpClient httpClient, final String opportunityXml) throws Exception {

  final PostMethod post = new PostMethod(cadURL + "/object/opportunity?_type=xml");
  post.addRequestHeader("Content-Type", "application/xml");
  final RequestEntity entity = new StringRequestEntity(opportunityXml, "application/xml", "ISO-8859-1");
  post.setRequestEntity(entity);
  int result = 0;
  try {
    result = httpClient.executeMethod(post);
  } catch (final Exception e) {
    throw e;
  } finally {
    if (post != null) {
      post.releaseConnection();
    }
  }
  return result;
}
 
开发者ID:inbravo,项目名称:scribe,代码行数:28,代码来源:MicroSoftOpportunityTest.java

示例15: createTask

import org.apache.commons.httpclient.methods.RequestEntity; //导入依赖的package包/类
/**
 * creates a task in MS. task Xml is passed as request body.
 * 
 * @param httpClient
 * @param taskXml
 * @return
 * @throws HttpException
 * @throws IOException
 */
private final int createTask(final HttpClient httpClient, final String taskXml) throws Exception {

  final PostMethod post = new PostMethod(cadURL + "/object/task?_type=xml");
  post.addRequestHeader("Content-Type", "application/xml");
  final RequestEntity entity = new StringRequestEntity(taskXml, "application/xml", "ISO-8859-1");
  post.setRequestEntity(entity);
  int result = 0;
  try {
    result = httpClient.executeMethod(post);
  } catch (final Exception e) {
    throw e;
  } finally {
    if (post != null) {
      post.releaseConnection();
    }
  }
  return result;
}
 
开发者ID:inbravo,项目名称:scribe,代码行数:28,代码来源:MicroSoftTaskTest.java


注:本文中的org.apache.commons.httpclient.methods.RequestEntity类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。