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

项目: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();
    }
  }
项目:product-ei    文件:PropertyIntegrationHTTP_SCTestCase.java   
@Test(groups = "wso2.esb", description = "Getting HTTP status code number ")
public void testHttpResponseCode() throws Exception {

    int responseStatus = 0;

    String strXMLFilename = FrameworkPathUtil.getSystemResourceLocation() + "artifacts"
                            + File.separator + "ESB" + File.separator + "mediatorconfig" +
                            File.separator + "property" + File.separator + "GetQuoteRequest.xml";

    File input = new File(strXMLFilename);
    PostMethod post = new PostMethod(getProxyServiceURLHttp("HTTP_SCTestProxy"));
    RequestEntity entity = new FileRequestEntity(input, "text/xml");
    post.setRequestEntity(entity);
    post.setRequestHeader("SOAPAction", "getQuote");

    HttpClient httpclient = new HttpClient();

    try {
        responseStatus = httpclient.executeMethod(post);
    } finally {
        post.releaseConnection();
    }

    assertEquals(responseStatus, 404, "Response status should be 404");
}
项目:lib-commons-httpclient    文件:PostXML.java   
/**
 *
 * Usage:
 *          java PostXML http://mywebserver:80/ c:\foo.xml
 *
 *  @param args command line arguments
 *                 Argument 0 is a URL to a web server
 *                 Argument 1 is a local filename
 *
 */
public static void main(String[] args) throws Exception {
    if (args.length != 2) {
        System.out.println("Usage: java -classpath <classpath> [-Dorg.apache.commons.logging.simplelog.defaultlog=<loglevel>] PostXML <url> <filename>]");
        System.out.println("<classpath> - must contain the commons-httpclient.jar and commons-logging.jar");
        System.out.println("<loglevel> - one of error, warn, info, debug, trace");
        System.out.println("<url> - the URL to post the file to");
        System.out.println("<filename> - file to post to the URL");
        System.out.println();
        System.exit(1);
    }
    // Get target URL
    String strURL = args[0];
    // Get file to be posted
    String strXMLFilename = args[1];
    File input = new File(strXMLFilename);
    // Prepare HTTP post
    PostMethod post = new PostMethod(strURL);
    // Request content will be retrieved directly
    // from the input stream
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    // Get HTTP client
    HttpClient httpclient = new HttpClient();
    // Execute request
    try {
        int result = httpclient.executeMethod(post);
        // Display status code
        System.out.println("Response status code: " + result);
        // Display response
        System.out.println("Response body: ");
        System.out.println(post.getResponseBodyAsString());
    } finally {
        // Release current connection to the connection pool once you are done
        post.releaseConnection();
    }
}
项目:fuse-karaf    文件:CrmSecureTest.java   
/**
 * HTTP POST http://localhost:8181/cxf/crm/customerservice/customers is used to upload the contents of
 * the add_customer.xml file to add a new customer to the system.
 * <p/>
 * On the server side, it matches the CustomerService's addCustomer() method
 *
 * @throws Exception
 */
@Test
public void postCustomerTest() throws IOException {
    LOG.info("============================================");
    LOG.info("Sent HTTP POST request to add customer");
    String inputFile = this.getClass().getResource("/add_customer.xml").getFile();
    File input = new File(inputFile);
    PostMethod post = new PostMethod(CUSTOMER_SERVICE_URL);
    post.getHostAuthState().setAuthScheme(scheme);
    post.addRequestHeader("Accept", "text/xml");
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);

    String res = "";

    try {
        int result = httpClient.executeMethod(post);
        LOG.info("Response status code: " + result);
        LOG.info("Response body: ");
        res = post.getResponseBodyAsString();
        LOG.info(res);
    } catch (IOException e) {
        LOG.error("Error connecting to {}", CUSTOMER_SERVICE_URL);
        LOG.error("You should build the 'rest' quick start and deploy it to a local Fuse before running this test");
        LOG.error("Please read the README.md file in 'rest' quick start root");
        fail("Connection error");
    } finally {
        // Release current connection to the connection pool once you are
        // done
        post.releaseConnection();
    }
    assertTrue(res.contains("Jack"));

}
项目:fuse-karaf    文件:CrmSecureTest.java   
/**
 * HTTP PUT http://localhost:8181/cxf/crm/customerservice/customers is used to upload the contents of
 * the update_customer.xml file to update the customer information for customer 123.
 * <p/>
 * On the server side, it matches the CustomerService's updateCustomer() method
 *
 * @throws Exception
 */
@Test
public void putCustomerTest() throws IOException {

    LOG.info("============================================");
    LOG.info("Sent HTTP PUT request to update customer info");

    String inputFile = this.getClass().getResource("/update_customer.xml").getFile();
    File input = new File(inputFile);
    PutMethod put = new PutMethod(CUSTOMER_SERVICE_URL);
    put.getHostAuthState().setAuthScheme(scheme);
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    put.setRequestEntity(entity);

    int result = 0;
    try {
        result = httpClient.executeMethod(put);
        LOG.info("Response status code: " + result);
        LOG.info("Response body: ");
        LOG.info(put.getResponseBodyAsString());
    } catch (IOException e) {
        LOG.error("Error connecting to {}", CUSTOMER_SERVICE_URL);
        LOG.error("You should build the 'rest' quick start and deploy it to a local Fuse before running this test");
        LOG.error("Please read the README.md file in 'rest' quick start root");
        fail("Connection error");
    } finally {
        // Release current connection to the connection pool once you are
        // done
        put.releaseConnection();
    }

    assertEquals(result, 200);
}
项目:fuse-karaf    文件:CrmTest.java   
/**
 * HTTP POST http://localhost:8181/cxf/crm/customerservice/customers is used to upload the contents of
 * the add_customer.json file to add a new customer to the system.
 * <p/>
 * On the server side, it matches the CustomerService's addCustomer() method
 *
 * @throws Exception
 */
@Test
public void postCustomerTestJson() throws Exception {
    LOG.info("Sent HTTP POST request to add customer");
    String inputFile = this.getClass().getResource("/add_customer.json").getFile();
    File input = new File(inputFile);
    PostMethod post = new PostMethod(CUSTOMER_SERVICE_URL);
    post.addRequestHeader("Accept", "application/json");
    RequestEntity entity = new FileRequestEntity(input, "application/json; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    String res = "";

    try {
        int result = httpclient.executeMethod(post);
        LOG.info("Response status code: " + result);
        LOG.info("Response body: ");
        res = getStringFromInputStream(post.getResponseBodyAsStream());
        LOG.info(res);
    } catch (IOException e) {
        LOG.error("Error connecting to {}", CUSTOMER_SERVICE_URL);
        LOG.error("You should build the 'rest' quick start and deploy it to a local Fuse before running this test");
        LOG.error("Please read the README.md file in 'rest' quick start root");
        fail("Connection error");
    } finally {
        // Release current connection to the connection pool once you are
        // done
        post.releaseConnection();
    }
    assertTrue(res.contains("Jack"));

}
项目:fuse-karaf    文件:CrmTest.java   
/**
 * HTTP POST http://localhost:8181/cxf/crm/customerservice/customers is used to upload the contents of
 * the add_customer.xml file to add a new customer to the system.
 * <p/>
 * On the server side, it matches the CustomerService's addCustomer() method
 *
 * @throws Exception
 */
@Test
public void postCustomerTest() throws Exception {
    LOG.info("Sent HTTP POST request to add customer");
    String inputFile = this.getClass().getResource("/add_customer.xml").getFile();
    File input = new File(inputFile);
    PostMethod post = new PostMethod(CUSTOMER_SERVICE_URL);
    post.addRequestHeader("Accept", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "application/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    String res = "";

    try {
        int result = httpclient.executeMethod(post);
        LOG.info("Response status code: " + result);
        LOG.info("Response body: ");
        res = getStringFromInputStream(post.getResponseBodyAsStream());
        LOG.info(res);
    } catch (IOException e) {
        LOG.error("Error connecting to {}", CUSTOMER_SERVICE_URL);
        LOG.error("You should build the 'rest' quick start and deploy it to a local Fuse before running this test");
        LOG.error("Please read the README.md file in 'rest' quick start root");
        fail("Connection error");
    } finally {
        // Release current connection to the connection pool once you are
        // done
        post.releaseConnection();
    }
    assertTrue(res.contains("Jack"));

}
项目:fuse-karaf    文件:CrmTest.java   
/**
 * HTTP PUT http://localhost:8181/cxf/crm/customerservice/customers is used to upload the contents of
 * the update_customer.xml file to update the customer information for customer 123.
 * <p/>
 * On the server side, it matches the CustomerService's updateCustomer() method
 *
 * @throws Exception
 */
@Test
public void putCustomerTest() throws IOException {

    LOG.info("Sent HTTP PUT request to update customer info");

    String inputFile = this.getClass().getResource("/update_customer.xml").getFile();
    File input = new File(inputFile);
    PutMethod put = new PutMethod(CUSTOMER_SERVICE_URL);
    RequestEntity entity = new FileRequestEntity(input, "application/xml; charset=ISO-8859-1");
    put.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    int result = 0;
    try {
        result = httpclient.executeMethod(put);
        LOG.info("Response status code: " + result);
        LOG.info("Response body: ");
        LOG.info(put.getResponseBodyAsString());
    } catch (IOException e) {
        LOG.error("Error connecting to {}", CUSTOMER_SERVICE_URL);
        LOG.error("You should build the 'rest' quick start and deploy it to a local Fuse before running this test");
        LOG.error("Please read the README.md file in 'rest' quick start root");
        fail("Connection error");
    } finally {
        // Release current connection to the connection pool once you are
        // done
        put.releaseConnection();
    }

    assertEquals(result, 200);
}
项目:product-ei    文件:MessageWithoutContentTypeTestCase.java   
/**
 * Sending a message without mentioning Content Type and check the body part at the listening port
 * <p/>
 * Public JIRA:    WSO2 Carbon/CARBON-6029
 * Responses With No Content-Type Header not handled properly
 * <p/>
 * Test Artifacts: ESB Sample 0
 *
 * @throws Exception   - if the scenario fail
 */
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.ALL})
@Test(groups = "wso2.esb")
public void testMessageWithoutContentType() throws Exception {

    // Get target URL
    String strURL = getMainSequenceURL();
    // Get SOAP action
    String strSoapAction = "getQuote";
    // Get file to be posted
    String strXMLFilename = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator +
            "ESB" + File.separator + "synapseconfig" + File.separator + "messagewithoutcontent" +
            File.separator + "request.xml";

    File input = new File(strXMLFilename);
    // Prepare HTTP post
    PostMethod post = new PostMethod(strURL);
    // Request content will be retrieved directly
    // from the input stream
    RequestEntity entity = new FileRequestEntity(input, "text/xml");
    post.setRequestEntity(entity);
    // consult documentation for your web service
    post.setRequestHeader("SOAPAction", strSoapAction);
    // Get HTTP client
    HttpClient httpclient = new HttpClient();
    // Execute request
    try {
        int result = httpclient.executeMethod(post);
        // Display status code
        log.info("Response status code: " + result);
        // Display response
        log.info("Response body: ");
        log.info(post.getResponseBodyAsString());
    } finally {
        // Release current connection to the connection pool once you are done
        post.releaseConnection();
    }
}
项目:product-ei    文件:MessageWithoutContentTypeTestCase.java   
/**
 * Sending a message without mentioning Content Type and check the body part at the listening port
 * <p/>
 * Public JIRA:    WSO2 Carbon/CARBON-6029
 * Responses With No Content-Type Header not handled properly
 * <p/>
 * Test Artifacts: ESB Sample 0
 *
 * @throws Exception   - if the scenario fail
 */
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.ALL})
@Test(groups = "wso2.esb")
public void testMessageWithoutContentType() throws Exception {

    // Get target URL
    String strURL = getMainSequenceURL();
    // Get SOAP action
    String strSoapAction = "getQuote";
    // Get file to be posted
    String strXMLFilename = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator +
                            "ESB" + File.separator + "synapseconfig" + File.separator + "messagewithoutcontent" +
                            File.separator + "request.xml";

    File input = new File(strXMLFilename);
    // Prepare HTTP post
    PostMethod post = new PostMethod(strURL);
    // Request content will be retrieved directly
    // from the input stream
    RequestEntity entity = new FileRequestEntity(input, "text/xml");
    post.setRequestEntity(entity);
    // consult documentation for your web service
    post.setRequestHeader("SOAPAction", strSoapAction);
    // Get HTTP client
    HttpClient httpclient = new HttpClient();
    // Execute request
    try {
        int result = httpclient.executeMethod(post);
        // Display status code
        log.info("Response status code: " + result);
        // Display response
        log.info("Response body: ");
        log.info(post.getResponseBodyAsString());
    } finally {
        // Release current connection to the connection pool once you are done
        post.releaseConnection();
    }
}
项目:product-ei    文件:ESBJAVA_4239_HTTP_SC_HandlingTests.java   
@Test(groups = "wso2.esb", description = "Test whether response HTTP status code getting correctly after callout " +
                                         "mediator successfully execute")
public void testHttpStatusCodeGettingSuccessfully() throws Exception {
    String endpoint = getProxyServiceURLHttp("TestCalloutHTTP_SC");
    String soapRequest = TestConfigurationProvider.getResourceLocation() + "artifacts" + File.separator +
                         "ESB" + File.separator + "mediatorconfig" + File.separator + "callout" +
                         File.separator + "SOAPRequestWithHeader.xml";
    File input = new File(soapRequest);
    PostMethod post = new PostMethod(endpoint);
    RequestEntity entity = new FileRequestEntity(input, "text/xml");
    post.setRequestEntity(entity);
    post.setRequestHeader("SOAPAction", "getQuote");
    HttpClient httpClient = new HttpClient();
    boolean errorLog = false;

    try {
        httpClient.executeMethod(post);

        LogEvent[] logs = logViewerClient.getAllSystemLogs();
        for (LogEvent logEvent : logs) {
            if (logEvent.getPriority().equals("INFO")) {
                String message = logEvent.getMessage();
                if (message.contains("STATUS-Fault") && message.contains("404 Error: Not Found")) {
                    errorLog = true;
                    break;
                }
            }
        }
    } finally {
        post.releaseConnection();
    }

    if (!errorLog) {
        fail("Response HTTP code not return successfully.");
    }
}
项目:product-ei    文件:ESBJAVA_4118_SOAPHeaderHandlingTest.java   
@Test(groups = "wso2.esb", description = "Test whether the callout mediator successfully handle SOAP messages " +
        "Having SOAP header")
public void testSOAPHeaderHandling () throws Exception{
    String endpoint = "http://localhost:8480/services/TestCalloutSoapHeader";
    String soapRequest = TestConfigurationProvider.getResourceLocation() + "artifacts" + File.separator +
            "ESB" + File.separator + "mediatorconfig" + File.separator + "callout" +
            File.separator + "SOAPRequestWithHeader.xml";
    File input = new File(soapRequest);
    PostMethod post = new PostMethod(endpoint);
    RequestEntity entity = new FileRequestEntity(input, "text/xml");
    post.setRequestEntity(entity);
    post.setRequestHeader("SOAPAction","getQuote");
    HttpClient httpClient = new HttpClient();
    boolean errorLog = false;

    try {
        int result = httpClient.executeMethod(post);
        String responseBody = post.getResponseBodyAsString();
        log.info("Response Status: " + result);
        log.info("Response Body: "+ responseBody);

        LogEvent[] logs = logViewerClient.getAllSystemLogs();
        for (LogEvent logEvent : logs) {
            if (logEvent.getPriority().equals("ERROR")) {
                String message = logEvent.getMessage();
                if (message.contains("Unable to convert to SoapHeader Block")) {
                    errorLog = true;
                    break;
                }
            }
        }
    } finally {
        post.releaseConnection();
    }
    assertFalse(errorLog, "Mediator Hasn't invoked successfully.");
}
项目:product-ei    文件:PropertyIntegrationForceSCAcceptedPropertyTestCase.java   
@Test(groups = "wso2.esb", description = "Testing functionality of FORCE_SC_ACCEPTED " +
                                         "- Enabled False")
public void testFORCE_SC_ACCEPTEDPropertyEnabledFalseScenario() throws Exception {
    verifyProxyServiceExistence("FORCE_SC_ACCEPTED_FalseTestProxy");

    int responseStatus = 0;

    String strXMLFilename = FrameworkPathUtil.getSystemResourceLocation() + "artifacts"
                            + File.separator + "ESB" + File.separator + "mediatorconfig" +
                            File.separator + "property" + File.separator + "GetQuoteRequest.xml";

    File input = new File(strXMLFilename);
    PostMethod post = new PostMethod(getProxyServiceURLHttp("FORCE_SC_ACCEPTED_FalseTestProxy"));
    RequestEntity entity = new FileRequestEntity(input, "text/xml");
    post.setRequestEntity(entity);
    post.setRequestHeader("SOAPAction", "getQuote");

    HttpClient httpclient = new HttpClient();

    try {
        responseStatus = httpclient.executeMethod(post);
    } finally {
        post.releaseConnection();
    }

    assertEquals(responseStatus, 200, "Response status should be 200");

}
项目:product-ei    文件:PropertyIntegrationForceSCAcceptedPropertyTestCase.java   
@Test(groups = "wso2.esb", description = "Testing functionality of FORCE_SC_ACCEPTED " +
                                         "Enabled True  - " +
                                         "Client should receive 202 message",
      dependsOnMethods = "testFORCE_SC_ACCEPTEDPropertyEnabledFalseScenario")
public void testWithFORCE_SC_ACCEPTEDPropertyEnabledTrueScenario() throws Exception {
    verifyProxyServiceExistence("FORCE_SC_ACCEPTED_TrueTestProxy");

    int responseStatus = 0;

    String strXMLFilename = FrameworkPathUtil.getSystemResourceLocation() + "artifacts"
                            + File.separator + "ESB" + File.separator + "mediatorconfig" +
                            File.separator + "property" + File.separator + "PlaceOrder.xml";

    File input = new File(strXMLFilename);
    PostMethod post = new PostMethod(getProxyServiceURLHttp("FORCE_SC_ACCEPTED_TrueTestProxy"));
    RequestEntity entity = new FileRequestEntity(input, "text/xml");
    post.setRequestEntity(entity);
    post.setRequestHeader("SOAPAction", "placeOrder");

    HttpClient httpclient = new HttpClient();

    try {
        responseStatus = httpclient.executeMethod(post);
    } finally {
        post.releaseConnection();
    }

    assertEquals(responseStatus, 202, "Response status should be 202");
}
项目:SI    文件:Tr069DMAdapter.java   
private void callPutFileApi(String fileType, String url, String filePath, String oui, String prodClass, String version) throws HttpException, IOException, HitDMException {
    org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient();

    PutMethod putMethod = new PutMethod(url);
    File input = new File(filePath);
    RequestEntity entity = new FileRequestEntity(input, "Content-Length: 1431");
    putMethod.setRequestEntity(entity);
    putMethod.setRequestHeader("fileType", fileType);
    putMethod.setRequestHeader("oui", oui);
    putMethod.setRequestHeader("productClass", prodClass);
    putMethod.setRequestHeader("version", version);

    client.executeMethod(putMethod);

    if (putMethod.getStatusCode() != 200) {
        String debugStr = "DM Server return:"+ putMethod.getStatusCode();
        byte[] body;
        try {
            body = putMethod.getResponseBody();
            if (body != null) {
                debugStr += "\r\nBody:"+new String(body);
            }
        } catch (Exception e) {
            debugStr += e.getMessage();
        }

        throw new HitDMException(putMethod.getStatusCode(), debugStr);
    }

}
项目:SI    文件:Tr069DMAdapter.java   
private void callPutFileApi(String fileType, String url, String filePath, String oui, String prodClass, String version) throws HttpException, IOException, HitDMException {
    org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient();

    PutMethod putMethod = new PutMethod(url);
    File input = new File(filePath);
    RequestEntity entity = new FileRequestEntity(input, "Content-Length: 1431");
    putMethod.setRequestEntity(entity);
    putMethod.setRequestHeader("fileType", fileType);
    putMethod.setRequestHeader("oui", oui);
    putMethod.setRequestHeader("productClass", prodClass);
    putMethod.setRequestHeader("version", version);

    client.executeMethod(putMethod);

    if (putMethod.getStatusCode() != 200) {
        String debugStr = "DM Server return:"+ putMethod.getStatusCode();
        byte[] body;
        try {
            body = putMethod.getResponseBody();
            if (body != null) {
                debugStr += "\r\nBody:"+new String(body);
            }
        } catch (Exception e) {
            debugStr += e.getMessage();
        }

        throw new HitDMException(putMethod.getStatusCode(), debugStr);
    }

}
项目:cats    文件:AbstractService.java   
/**
 * Create Project Via GET
 * 
 * @param requestUrl
 *            Relative request URL
 * @param mapperClass
 *            Class to which the response should cast to.
 * @return JAXB deserialized response
 */
protected Object createProject( final String requestUrl, Class< ? > mapperClass, File config )
{
    Object domainObject = null;
    HttpClient client = new HttpClient();
    try
    {
        PostMethod request = new PostMethod( getAbsoluteUrl( requestUrl ) );
        request.addRequestHeader( CONTENT_TYPE, APPLICATION_XML );
        RequestEntity entity = new FileRequestEntity( config, "text/xml; charset=UTF-8" );
        request.setRequestEntity( entity );
        String apiToken = jenkinsClientProperties.getJenkinsApiToken();
        if ( !apiToken.isEmpty() )
        {
            request.setDoAuthentication( true );
        }

        domainObject = sendRequestToJenkins( mapperClass, domainObject, client, request, apiToken );

    }
    catch ( Exception e )
    {
        LOGGER.error( e.getMessage() );
    }

    return domainObject;
}
项目:lib-commons-httpclient    文件:PostSOAP.java   
/**
 *
 * Usage:
 *          java PostSOAP http://mywebserver:80/ SOAPAction c:\foo.xml
 *
 *  @param args command line arguments
 *                 Argument 0 is a URL to a web server
 *                 Argument 1 is the SOAP Action
 *                 Argument 2 is a local filename
 *
 */
public static void main(String[] args) throws Exception {
    if (args.length != 3) {
        System.out.println("Usage: java -classpath <classpath> [-Dorg.apache.commons.logging.simplelog.defaultlog=<loglevel>] PostSOAP <url> <soapaction> <filename>]");
        System.out.println("<classpath> - must contain the commons-httpclient.jar and commons-logging.jar");
        System.out.println("<loglevel> - one of error, warn, info, debug, trace");
        System.out.println("<url> - the URL to post the file to");
        System.out.println("<soapaction> - the SOAP action header value");
        System.out.println("<filename> - file to post to the URL");
        System.out.println();
        System.exit(1);
    }
    // Get target URL
    String strURL = args[0];
    // Get SOAP action
    String strSoapAction = args[1];
    // Get file to be posted
    String strXMLFilename = args[2];
    File input = new File(strXMLFilename);
    // Prepare HTTP post
    PostMethod post = new PostMethod(strURL);
    // Request content will be retrieved directly
    // from the input stream
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    // consult documentation for your web service
    post.setRequestHeader("SOAPAction", strSoapAction);
    // Get HTTP client
    HttpClient httpclient = new HttpClient();
    // Execute request
    try {
        int result = httpclient.executeMethod(post);
        // Display status code
        System.out.println("Response status code: " + result);
        // Display response
        System.out.println("Response body: ");
        System.out.println(post.getResponseBodyAsString());
    } finally {
        // Release current connection to the connection pool once you are done
        post.releaseConnection();
    }
}
项目:teamcity-s3-artifact-storage-plugin    文件:S3ArtifactsPublisher.java   
private List<ArtifactDataInstance> publishFilesWithPreSignedUrls(@NotNull AgentRunningBuild build, @NotNull String bucketName, @NotNull Map<File, String> filesToPublish) {
  final Map<File, String> fileToNormalizedArtifactPathMap = new HashMap<File, String>();
  final Map<File, String> fileToS3ObjectKeyMap = new HashMap<File, String>();
  final String s3ObjectKeyPrefix = getPathPrefix(build);

  build.getBuildLogger().message("Artifacts are published to the S3 path " + s3ObjectKeyPrefix + " in the S3 bucket " + bucketName);

  for (Map.Entry<File, String> entry : filesToPublish.entrySet()){
    String normalizeArtifactPath = normalizeArtifactPath(entry.getValue(), entry.getKey());
    fileToNormalizedArtifactPathMap.put(entry.getKey(), normalizeArtifactPath);
    fileToS3ObjectKeyMap.put(entry.getKey(), s3ObjectKeyPrefix + normalizeArtifactPath);
  }

  final Map<String, URL> preSignedUploadUrls;
  try {
    preSignedUploadUrls = resolveUploadUrls(build, fileToS3ObjectKeyMap.values());
  } catch (IOException e) {
    throw new ArtifactPublishingFailedException(e.getMessage(), false, e);
  }
  final int connectionTimeout = build.getAgentConfiguration().getServerConnectionTimeout();

  return CollectionsUtil.convertAndFilterNulls(filesToPublish.keySet(), new Converter<ArtifactDataInstance, File>() {
    @Override
    public ArtifactDataInstance createFrom(@NotNull File file) {
      String artifactPath = fileToNormalizedArtifactPathMap.get(file);
      URL uploadUrl = preSignedUploadUrls.get(fileToS3ObjectKeyMap.get(file));
      if(uploadUrl == null){
        throw new ArtifactPublishingFailedException("Failed to publish artifact " + artifactPath + ". Can't get presigned upload url.", false, null);
      }
      HttpClient httpClient = HttpUtil.createHttpClient(connectionTimeout, uploadUrl, null);
      try {
        PutMethod putMethod = new PutMethod(uploadUrl.toString());
        putMethod.setRequestEntity(new FileRequestEntity(file, "application/octet-stream"));
        int responseCode = httpClient.executeMethod(putMethod);
        if(responseCode == 200){
          LOG.debug(String.format("Successfully upload artifact %s to %s", artifactPath, uploadUrl));
        } else{
          throw new ArtifactPublishingFailedException(String.format("Failed upload artifact %s to %s. Response code received: %d.", artifactPath, uploadUrl, responseCode), false, null);
        }
      } catch (IOException ex){
        throw new ArtifactPublishingFailedException(ex.getMessage(), false, ex);
      }
      return ArtifactDataInstance.create(artifactPath, file.length());
    }
  });
}
项目:spring-usc    文件:HttpClientPost.java   
private void postFile(File file, PostMethod method) throws IOException {
    method.setRequestEntity(new FileRequestEntity(file, null));
    doRequest(file, method);
}
项目:simple-http    文件:HttpRequestBuilder.java   
public HttpRequestBuilder setFileContent(File content, String contentType) {
    return setContent(new FileRequestEntity(content, contentType));
}