Java 类org.apache.commons.httpclient.methods.RequestEntity 实例源码

项目:fax4j    文件:ApacheHTTPClientTest.java   
/**
 * 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());
}
项目:lams    文件:HttpSOAPClient.java   
/**
 * 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);
    }
}
项目:lib-commons-httpclient    文件:TestEntityEnclosingMethod.java   
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();
    }
}
项目:lib-commons-httpclient    文件:TestEntityEnclosingMethod.java   
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();
    }
}
项目:lib-commons-httpclient    文件:TestEntityEnclosingMethod.java   
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();
    }
}
项目:lib-commons-httpclient    文件:TestEntityEnclosingMethod.java   
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();
    }
}
项目:lib-commons-httpclient    文件:TestEntityEnclosingMethod.java   
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();
    }
}
项目:lib-commons-httpclient    文件:TestEntityEnclosingMethod.java   
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();
    }
}
项目:lib-commons-httpclient    文件:TestMethodCharEncoding.java   
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);
}
项目:Spring-Boot-Server    文件:HttpUtils.java   
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;
  }
项目:scribe    文件:ZenDeskTest.java   
/**
 * 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;
}
项目:scribe    文件:MicroSoftLeadTest.java   
/**
 * 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;
}
项目:scribe    文件:MicroSoftOpportunityTest.java   
/**
 * 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;
}
项目:scribe    文件:MicroSoftTaskTest.java   
/**
 * 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;
}
项目:scribe    文件:MicroSoftIncidentTest.java   
/**
 * creates an incident in MS. incident Xml is passed as request body.
 * 
 * @param httpClient
 * @param userXml
 * @return
 * @throws HttpException
 * @throws IOException
 */
private final int createIncident(final HttpClient httpClient, final String userXml) throws Exception {

  final PostMethod post = new PostMethod(cadURL + "/object/incident?_type=xml");
  post.addRequestHeader("Content-Type", "application/xml");
  final RequestEntity entity = new StringRequestEntity(userXml, "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;
}
项目:scribe    文件:MicroSoftContactTest.java   
/**
 * creates a Contact in MS. contact XML is passed as request body.
 * 
 * @param httpClient
 * @param contactXml
 * @return
 * @throws HttpException
 * @throws IOException
 */
private final int createContact(final HttpClient httpClient, final String contactXml) throws Exception {

  final PostMethod post = new PostMethod(cadURL + "/object/contact?_type=xml");
  post.addRequestHeader("Content-Type", "application/xml");
  final RequestEntity entity = new StringRequestEntity(contactXml, "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;
}
项目:scribe    文件:MicroSoftAccountTest.java   
/**
 * creates a account in MS. account Xml is passed as request body.
 * 
 * @param httpClient
 * @param accountXml
 * @return
 * @throws HttpException
 * @throws URIException
 */

private final int createAccount(final HttpClient httpClient, final String accountXml) throws Exception {

  final PostMethod post = new PostMethod(cadURL + "/object/account?_type=xml");
  post.addRequestHeader("Content-Type", "application/xml");
  final RequestEntity entity = new StringRequestEntity(accountXml, "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;
}
项目:scribe    文件:MSCRMOCPTest.java   
/**
 * 
 * @param url
 * @param soapEnvelope
 * @return
 * @throws UnsupportedEncodingException
 */
public final static String getSOAPResponse(final String url, final String soapEnvelope) throws UnsupportedEncodingException {

  final PostMethod postMethod = new PostMethod(url);
  postMethod.addRequestHeader("Content-Type", "application/soap+xml; charset=UTF-8");
  final HttpClient httpclient = new HttpClient();
  RequestEntity entity = new StringRequestEntity(soapEnvelope, "application/x-www-form-urlencoded", null);
  postMethod.setRequestEntity(entity);
  try {

    try {
      System.out.println("URI: " + postMethod.getURI());
      final int result = httpclient.executeMethod(postMethod);
      System.out.println("Response code: " + result);
      return postMethod.getResponseBodyAsString();
    } catch (Exception exception) {
      System.err.println(exception);
    }
  } finally {
    postMethod.releaseConnection();
  }

  return null;
}
项目:scribe    文件:HTTPClient.java   
private static void createAccount() throws HttpException, IOException {

    File input = new File(testFolder + "Account.xml");
    PostMethod post =
        new PostMethod(cadURL + "/object/User?_type=xml&externalServiceType=FBMC&externalUsername=8x8webservice&externalPassword=E4qtjWZLYKre");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void updateAccount() throws HttpException, IOException {
  System.out.println("Sent HTTP PUT request to update Account");
  File input = new File(testFolder + "Account.xml");
  PutMethod put =
      new PutMethod(cadURL + "/object/User?_type=xml&externalServiceType=FBMC&externalUsername=8x8webservice&externalPassword=E4qtjWZLYKre");
  put.addRequestHeader("Content-Type", "application/xml");
  RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
  put.setRequestEntity(entity);
  HttpClient httpclient = new HttpClient();
  try {
    int result = httpclient.executeMethod(put);
    System.out.println("Response status code: " + result);
    System.out.println("Response body: " + put.getResponseBodyAsString());
  } finally {
    put.releaseConnection();
  }
}
项目:scribe    文件:HTTPClient.java   
private static void createCustomer() throws HttpException, IOException {
  System.out.println("Sent HTTP POST request to add Customer");
  File input = new File(testFolder + "Customer.xml");
  PostMethod post = new PostMethod(cadURL + "/object/customer?_type=xml");
  post.addRequestHeader("Content-Type", "application/xml");
  RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
  post.setRequestEntity(entity);
  HttpClient httpclient = new HttpClient();
  try {
    System.out.println("URI: " + post.getURI());
    int result = httpclient.executeMethod(post);
    System.out.println("Response status code: " + result);
    System.out.println("Response body: " + post.getResponseBodyAsString());
  } finally {
    post.releaseConnection();
  }
}
项目:scribe    文件:HTTPClient.java   
private static void updateCustomer() throws HttpException, IOException {
  System.out.println("Sent HTTP PUT request to update Customer");
  File input = new File(testFolder + "Customer.xml");
  PutMethod put = new PutMethod(cadURL + "/object/customer?_type=xml");
  put.addRequestHeader("Content-Type", "application/xml");
  RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
  put.setRequestEntity(entity);
  HttpClient httpclient = new HttpClient();
  try {
    System.out.println("URI: " + put.getURI());
    int result = httpclient.executeMethod(put);
    System.out.println("Response status code: " + result);
    System.out.println("Response body: " + put.getResponseBodyAsString());
  } finally {
    put.releaseConnection();
  }
}
项目:scribe    文件:HTTPClient.java   
private static void createLead() throws HttpException, IOException {
  System.out.println("Sent HTTP POST request to create Lead");
  File input = new File(testFolder + "Lead.xml");
  PostMethod post = new PostMethod(cadURL + "/object/lead?_type=xml");
  post.addRequestHeader("Content-Type", "application/xml");
  RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
  post.setRequestEntity(entity);
  HttpClient httpclient = new HttpClient();
  try {
    System.out.println("URI: " + post.getURI());
    int result = httpclient.executeMethod(post);
    System.out.println("Response status code: " + result);
    System.out.println("Response body: " + post.getResponseBodyAsString());
  } finally {
    post.releaseConnection();
  }
}
项目:scribe    文件:HTTPClient.java   
private static void createContact() throws HttpException, IOException {
  System.out.println("Sent HTTP POST request to createContact");
  File input = new File(testFolder + "Contact.xml");
  PostMethod post = new PostMethod(cadURL + "/object/oltp?_type=xml");
  post.addRequestHeader("Content-Type", "application/xml");
  RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
  post.setRequestEntity(entity);
  HttpClient httpclient = new HttpClient();
  try {
    System.out.println("URI: " + post.getURI());
    int result = httpclient.executeMethod(post);
    System.out.println("Response status code: " + result);
    System.out.println("Response body: " + post.getResponseBodyAsString());
  } finally {
    post.releaseConnection();
  }
}
项目:scribe    文件:HTTPClient.java   
private static void updateContact() throws HttpException, IOException {
  System.out.println("Sent HTTP POST request to createContact");
  File input = new File(testFolder + "Contact.xml");
  PutMethod put = new PutMethod(cadURL + "/object/oltp?_type=xml");
  put.addRequestHeader("Content-Type", "application/xml");
  RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
  put.setRequestEntity(entity);
  HttpClient httpclient = new HttpClient();
  try {
    System.out.println("URI: " + put.getURI());
    int result = httpclient.executeMethod(put);
    System.out.println("Response status code: " + result);
    System.out.println("Response body: " + put.getResponseBodyAsString());
  } finally {
    put.releaseConnection();
  }
}
项目:scribe    文件:HTTPClient.java   
private static void createFAQCatagory() throws HttpException, IOException {
  System.out.println("Sent HTTP POST request to createFAQCatagory");
  File input = new File(testFolder + "FAQCatagory.xml");
  PostMethod post = new PostMethod(cadURL + "/object/faqcategory?_type=xml");
  post.addRequestHeader("Content-Type", "application/xml");
  RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
  post.setRequestEntity(entity);
  HttpClient httpclient = new HttpClient();
  try {
    System.out.println("URI: " + post.getURI());
    int result = httpclient.executeMethod(post);
    System.out.println("Response status code: " + result);
    System.out.println("Response body: " + post.getResponseBodyAsString());
  } finally {
    post.releaseConnection();
  }
}
项目:scribe    文件:HTTPClient.java   
private static void createUser() throws HttpException, IOException {

    File input = new File(testFolder + "User.xml");
    PostMethod post = new PostMethod(cadURL + "/object/user?_type=xml&batch=dummy");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("hii");
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void updateUser() throws HttpException, IOException {

    File input = new File(testFolder + "User.xml");
    PutMethod put = new PutMethod(cadURL + "/object/user?_type=xml");
    put.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    put.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + put.getURI());
      int result = httpclient.executeMethod(put);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + put.getResponseBodyAsString());
    } finally {
      put.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void createTask() throws HttpException, IOException {

    File input = new File(testFolder + "Task.xml");
    PostMethod post = new PostMethod(cadURL + "/object/task?_type=xml");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void createSupportCase() throws HttpException, IOException {

    File input = new File(testFolder + "SupportCase.xml");
    PostMethod post = new PostMethod(cadURL + "/object/supportcase?_type=xml");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void createPhoneCall() throws HttpException, IOException {

    File input = new File(testFolder + "PhoneCall.xml");
    PostMethod post = new PostMethod(cadURL + "/object/phonecall?_type=xml");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void createOpportunity() throws HttpException, IOException {

    File input = new File(testFolder + "Opportunity.xml");
    PostMethod post = new PostMethod(cadURL + "/object/opportunity?_type=xml");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void createIncident() throws HttpException, IOException {

    File input = new File(testFolder + "Incident.xml");
    PostMethod post = new PostMethod(cadURL + "/object/incident?_type=xml");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void createCase() throws HttpException, IOException {

    File input = new File(testFolder + "Case.xml");
    PostMethod post = new PostMethod(cadURL + "/object/oltp?_type=xml");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void updateCase() throws HttpException, IOException {

    File input = new File(testFolder + "Case.xml");
    PutMethod post = new PutMethod(cadURL + "/object/oltp?_type=xml");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void createFollowup() throws HttpException, IOException {

    File input = new File(testFolder + "Followup.xml");
    PostMethod post = new PostMethod(cadURL + "/object/oltp?_type=xml");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:scribe    文件:HTTPClient.java   
private static void updateFollowup() throws HttpException, IOException {

    File input = new File(testFolder + "Followup.xml");
    PutMethod post = new PutMethod(cadURL + "/object/oltp?_type=xml");
    post.addRequestHeader("Content-Type", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    try {
      System.out.println("URI: " + post.getURI());
      int result = httpclient.executeMethod(post);
      System.out.println("Response status code: " + result);
      System.out.println("Response body: " + post.getResponseBodyAsString());
    } finally {
      post.releaseConnection();
    }
  }
项目:OSCAR-ConCert    文件:OntarioMD.java   
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;
}
项目:cashion    文件:UserValidate.java   
public static void main(String[] args) throws Exception {
    HttpClient hc = new HttpClient();
        PostMethod method = null;
        //同步企业名录
        method = new PostMethod("http://test.vop.onlyou.com/interface/bpo/UserValidate.htm");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("username", "pancs_qd");
        jsonObject.put("password", "123456");
        String transJson = jsonObject.toString();
        RequestEntity se = new StringRequestEntity(transJson,"application/json","UTF-8");
        method.setRequestEntity(se);
        //使用系统提供的默认的恢复策略
        method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
        //设置超时的时间
        method.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 3000);             
        int statusCode = hc.executeMethod(method);
        System.out.println(statusCode);
        byte[] responseBody = method.getResponseBody();
        System.out.println(new String(responseBody));
        System.out.println("getStatusLine:"+method.getStatusLine());
        String response = new String(method.getResponseBodyAsString().getBytes("utf-8"));
        System.out.println("response:"+response);
}
项目:cashion    文件:allBPOInterface.java   
public void getCustomerList()  throws JSONException, IOException {
    HttpClient hc = new HttpClient();
    PostMethod method = null;
    JSONObject jsonObject = new JSONObject();
    System.out.println("同步企业名录");
    method = new PostMethod("http://test.vop.onlyou.com/interface/bpo/getCustomerList.htm");
    jsonObject.put("lastSyncDate", "201501");
    String transJson = jsonObject.toString();
    RequestEntity se = new StringRequestEntity(transJson,"application/json","UTF-8");
    method.setRequestEntity(se);
    //使用系统提供的默认的恢复策略
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
    //设置超时的时间
    method.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 3000);
    hc.executeMethod(method);
    InputStream strStream = method.getResponseBodyAsStream();
    ByteArrayOutputStream   baos   =   new   ByteArrayOutputStream(); 
    int   i=-1; 
    while((i=strStream.read())!=-1){ 
    baos.write(i); 
    } 
   String strBody =   baos.toString(); 
    System.out.println(new String(strBody));
    System.out.println("getStatusLine:"+method.getStatusLine());
}