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

项目:lib-commons-httpclient    文件:TestMethodCharEncoding.java   
public void testRussianInRequestBody() throws IOException {
    PostMethod httppost = new PostMethod("/");
    String s = constructString(RUSSIAN_STUFF_UNICODE);
    // Test UTF-8 encoding
    httppost.setRequestEntity(
        new StringRequestEntity(s, "text/plain", CHARSET_UTF8));
    verifyEncoding(httppost.getRequestEntity(), RUSSIAN_STUFF_UTF8);
    // Test KOI8-R
    httppost.setRequestEntity(
        new StringRequestEntity(s, "text/plain", CHARSET_KOI8_R));
    verifyEncoding(httppost.getRequestEntity(), RUSSIAN_STUFF_KOI8R);
    // Test WIN1251
    httppost.setRequestEntity(
        new StringRequestEntity(s, "text/plain", CHARSET_WIN1251));
    verifyEncoding(httppost.getRequestEntity(), RUSSIAN_STUFF_WIN1251);
}
项目:DBus    文件:HttpRequest.java   
public String doPut(String url, String charset, String jsonObj) {
    String resStr = null;
    HttpClient htpClient = new HttpClient();
    PutMethod putMethod = new PutMethod(url);
    putMethod.getParams().setParameter(
            HttpMethodParams.HTTP_CONTENT_CHARSET, charset);
    try {
        putMethod.setRequestEntity(new StringRequestEntity(jsonObj,
                "application/json", charset));
        int statusCode = htpClient.executeMethod(putMethod);
        if (statusCode != HttpStatus.SC_OK) {
            log.error("Method failed: " + putMethod.getStatusLine());
            return null;
        }
        byte[] responseBody = putMethod.getResponseBody();
        resStr = new String(responseBody, charset);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        putMethod.releaseConnection();
    }
    return resStr;
}
项目:alfresco-remote-api    文件:PublicApiHttpClient.java   
public HttpResponse post(final RequestContext rq, final String scope, final int version, final String entityCollectionName, final Object entityId,
            final String relationCollectionName, final Object relationshipEntityId, final String body, String contentType, final Map<String, String> params) throws IOException
{
    RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), scope, version, entityCollectionName, entityId, relationCollectionName,
                relationshipEntityId, params);
    String url = endpoint.getUrl();

    PostMethod req = new PostMethod(url.toString());
    if (body != null)
    {
        if (contentType == null || contentType.isEmpty())
        {
            contentType = "application/json";
        }
        StringRequestEntity requestEntity = new StringRequestEntity(body, contentType, "UTF-8");
        req.setRequestEntity(requestEntity);
    }
    return submitRequest(req, rq);
}
项目:lib-commons-httpclient    文件:TestProxy.java   
/**
 * Tests POST via non-authenticating proxy + host auth + connection keep-alive 
 */
public void testPostHostAuthConnKeepAlive() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");

    this.client.getState().setCredentials(AuthScope.ANY, creds);

    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds, "test", true));
    handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));

    this.server.setRequestHandler(handlerchain);

    PostMethod post = new PostMethod("/");
    post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null));
    try {
        this.client.executeMethod(post);
        assertEquals(HttpStatus.SC_OK, post.getStatusCode());
        assertNotNull(post.getResponseBodyAsString());
    } finally {
        post.releaseConnection();
    }
}
项目:lib-commons-httpclient    文件:TestProxy.java   
/**
 * Tests POST via non-authenticating proxy + host auth + connection close 
 */
public void testPostHostAuthConnClose() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");

    this.client.getState().setCredentials(AuthScope.ANY, creds);

    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds, "test", false));
    handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));

    this.server.setRequestHandler(handlerchain);

    PostMethod post = new PostMethod("/");
    post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null));
    try {
        this.client.executeMethod(post);
        assertEquals(HttpStatus.SC_OK, post.getStatusCode());
        assertNotNull(post.getResponseBodyAsString());
    } finally {
        post.releaseConnection();
    }
}
项目:lib-commons-httpclient    文件:TestProxy.java   
/**
 * Tests POST via non-authenticating proxy + invalid host auth 
 */
public void testPostHostInvalidAuth() throws Exception {

    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");

    this.client.getState().setCredentials(AuthScope.ANY, creds);

    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds));
    handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));

    this.client.getState().setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials("testuser", "wrongstuff"));

    this.server.setRequestHandler(handlerchain);

    PostMethod post = new PostMethod("/");
    post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null));
    try {
        this.client.executeMethod(post);
        assertEquals(HttpStatus.SC_UNAUTHORIZED, post.getStatusCode());
    } finally {
        post.releaseConnection();
    }
}
项目:lib-commons-httpclient    文件:TestProxy.java   
/**
 * Tests POST via non-authenticating proxy + interactive host auth + connection keep-alive 
 */
public void testPostInteractiveHostAuthConnKeepAlive() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");

    this.client.getParams().setParameter(CredentialsProvider.PROVIDER, 
            new GetItWrongThenGetItRight());

    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds, "test", true));
    handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));

    this.server.setRequestHandler(handlerchain);

    PostMethod post = new PostMethod("/");
    post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null));
    try {
        this.client.executeMethod(post);
        assertEquals(HttpStatus.SC_OK, post.getStatusCode());
        assertNotNull(post.getResponseBodyAsString());
    } finally {
        post.releaseConnection();
    }
}
项目:lib-commons-httpclient    文件:TestProxy.java   
/**
 * Tests POST via non-authenticating proxy + interactive host auth + connection close 
 */
public void testPostInteractiveHostAuthConnClose() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");

    this.client.getParams().setParameter(CredentialsProvider.PROVIDER, 
            new GetItWrongThenGetItRight());

    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds, "test", false));
    handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));

    this.server.setRequestHandler(handlerchain);

    PostMethod post = new PostMethod("/");
    post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null));
    try {
        this.client.executeMethod(post);
        assertEquals(HttpStatus.SC_OK, post.getStatusCode());
        assertNotNull(post.getResponseBodyAsString());
    } finally {
        post.releaseConnection();
    }
}
项目:lib-commons-httpclient    文件:TestProxy.java   
/**
 * Tests POST via authenticating proxy
 */
public void testPostAuthProxy() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");

    this.client.getState().setProxyCredentials(AuthScope.ANY, creds);
    this.server.setHttpService(new FeedbackService());

    this.proxy.requireAuthentication(creds, "test", true);

    PostMethod post = new PostMethod("/");
    post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null));
    try {
        this.client.executeMethod(post);
        assertEquals(HttpStatus.SC_OK, post.getStatusCode());
        assertNotNull(post.getResponseBodyAsString());
    } finally {
        post.releaseConnection();
    }
}
项目:lib-commons-httpclient    文件:TestProxy.java   
/**
 * Tests POST via authenticating proxy + host auth + connection keep-alive 
 */
public void testPostProxyAuthHostAuthConnKeepAlive() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");

    this.client.getState().setCredentials(AuthScope.ANY, creds);
    this.client.getState().setProxyCredentials(AuthScope.ANY, creds);

    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds, "test", true));
    handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));

    this.server.setRequestHandler(handlerchain);

    this.proxy.requireAuthentication(creds, "test", true);

    PostMethod post = new PostMethod("/");
    post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null));
    try {
        this.client.executeMethod(post);
        assertEquals(HttpStatus.SC_OK, post.getStatusCode());
        assertNotNull(post.getResponseBodyAsString());
    } finally {
        post.releaseConnection();
    }
}
项目:lib-commons-httpclient    文件:TestProxy.java   
/**
 * Tests POST via authenticating proxy + host auth + connection close 
 */
public void testPostProxyAuthHostAuthConnClose() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");

    this.client.getState().setCredentials(AuthScope.ANY, creds);
    this.client.getState().setProxyCredentials(AuthScope.ANY, creds);

    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds, "test", false));
    handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));

    this.server.setRequestHandler(handlerchain);

    this.proxy.requireAuthentication(creds, "test", true);

    PostMethod post = new PostMethod("/");
    post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null));
    try {
        this.client.executeMethod(post);
        assertEquals(HttpStatus.SC_OK, post.getStatusCode());
        assertNotNull(post.getResponseBodyAsString());
    } finally {
        post.releaseConnection();
    }
}
项目:lib-commons-httpclient    文件:TestProxy.java   
/**
 * Tests POST via non-authenticating proxy + interactive host auth + connection keep-alive 
 */
public void testPostInteractiveProxyAuthHostAuthConnKeepAlive() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");

    this.client.getParams().setParameter(CredentialsProvider.PROVIDER, 
            new GetItWrongThenGetItRight());

    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds, "test", true));
    handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));

    this.server.setRequestHandler(handlerchain);

    this.proxy.requireAuthentication(creds, "test", true);

    PostMethod post = new PostMethod("/");
    post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null));
    try {
        this.client.executeMethod(post);
        assertEquals(HttpStatus.SC_OK, post.getStatusCode());
        assertNotNull(post.getResponseBodyAsString());
    } finally {
        post.releaseConnection();
    }
}
项目:lib-commons-httpclient    文件:TestProxy.java   
/**
 * Tests POST via non-authenticating proxy + interactive host auth + connection close 
 */
public void testPostInteractiveProxyAuthHostAuthConnClose() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");

    this.client.getParams().setParameter(CredentialsProvider.PROVIDER, 
            new GetItWrongThenGetItRight());

    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds, "test", false));
    handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));

    this.server.setRequestHandler(handlerchain);

    this.proxy.requireAuthentication(creds, "test", true);

    PostMethod post = new PostMethod("/");
    post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null));
    try {
        this.client.executeMethod(post);
        assertEquals(HttpStatus.SC_OK, post.getStatusCode());
        assertNotNull(post.getResponseBodyAsString());
    } finally {
        post.releaseConnection();
    }
}
项目: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;
}
项目: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;
}
项目:teamcity-s3-artifact-storage-plugin    文件:S3ArtifactsPublisher.java   
@NotNull
private static Map<String, URL> resolveUploadUrls(AgentRunningBuild build, @NotNull Collection<String> s3ObjectKeys) throws IOException {
  BuildAgentConfiguration agentConfiguration = build.getAgentConfiguration();
  String targetUrl = agentConfiguration.getServerUrl() + HTTP_AUTH + ARTEFACTS_S3_UPLOAD_PRESIGN_URLS_HTML;
  int connectionTimeout = agentConfiguration.getServerConnectionTimeout();
  UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(build.getAccessUser(), build.getAccessCode());
  HttpClient httpClient = HttpUtil.createHttpClient(connectionTimeout, new URL(targetUrl), credentials);
  PostMethod post = new PostMethod(targetUrl);
  post.setRequestEntity(new StringRequestEntity(S3PreSignUrlHelper.writeS3ObjectKeys(s3ObjectKeys), APPLICATION_XML, UTF_8));
  post.setDoAuthentication(true);
  int responseCode = httpClient.executeMethod(post);
  if(responseCode != 200){
    LOG.debug("Failed resolving S3 pre-signed URL for build " + build.describe(false) + " . Response code " + responseCode);
    return Collections.emptyMap();
  }
  return S3PreSignUrlHelper.readPreSignUrlMapping(post.getResponseBodyAsString());
}
项目: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());
}
项目:cashion    文件:allBPOInterface.java   
public void UserValidate() throws JSONException, IOException {
    HttpClient hc = new HttpClient();
    PostMethod method = null;
    System.out.println(" 扫描前置客户端权限校验");
    method = new PostMethod("http://test.vop.onlyou.com/interface/bpo/UserValidate.htm");
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("username", "pancs_qd");
    jsonObject.put("password", "111111");
    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());
}
项目:cashion    文件:getCustomerList.java   
public static void main(String[] args) throws Exception {
      HttpClient hc = new HttpClient();
          PostMethod method = null;
          JSONObject jsonObject = new JSONObject();
          //同步企业名录
          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);
          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);
}
项目:product-ei    文件:ESBJAVA2615TestCase.java   
private String httpClient(String proxyLocation, String xml) {
    try {
        HttpClient httpclient = new HttpClient();
        PostMethod post = new PostMethod(proxyLocation);

        post.setRequestEntity(new StringRequestEntity(xml));
        post.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1");
        post.setRequestHeader("SOAPAction", "urn:mediate");
        httpclient.executeMethod(post);

        InputStream in = post.getResponseBodyAsStream();

        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line;
        StringBuffer buffer = new StringBuffer();
        while ((line = reader.readLine()) != null) {
            buffer.append(line);
            buffer.append("\n");
        }
        reader.close();
        return buffer.toString();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
项目:product-ei    文件:ESBJAVA4846HttpProtocolVersionTestCase.java   
@Test(groups = "wso2.esb", description = "Sending HTTP1.0 message")
public void sendingHTTP10Message() throws Exception {
    PostMethod post = new PostMethod(getProxyServiceURLHttp("StockQuoteProxyTestHTTPVersion"));
    RequestEntity entity = new StringRequestEntity(getPayload(), "text/xml", "UTF-8");
    post.setRequestEntity(entity);
    post.setRequestHeader("SOAPAction", "urn:getQuote");
    HttpMethodParams params = new HttpMethodParams();
    params.setVersion(HttpVersion.HTTP_1_0);
    post.setParams(params);
    HttpClient httpClient = new HttpClient();
    String httpVersion = "";

    try {
        httpClient.executeMethod(post);
        post.getResponseBodyAsString();
        httpVersion = post.getStatusLine().getHttpVersion();
    } finally {
        post.releaseConnection();
    }
    Assert.assertEquals(httpVersion, HttpVersion.HTTP_1_0.toString(), "Http version mismatched");

}
项目:product-ei    文件:ESBJAVA4846HttpProtocolVersionTestCase.java   
@Test(groups = "wso2.esb", description = "Sending HTTP1.1 message")
public void sendingHTTP11Message() throws Exception {
    PostMethod post = new PostMethod(getProxyServiceURLHttp("StockQuoteProxyTestHTTPVersion"));
    RequestEntity entity = new StringRequestEntity(getPayload(), "text/xml", "UTF-8");
    post.setRequestEntity(entity);
    post.setRequestHeader("SOAPAction", "urn:getQuote");
    HttpMethodParams params = new HttpMethodParams();
    params.setVersion(HttpVersion.HTTP_1_1);
    post.setParams(params);
    HttpClient httpClient = new HttpClient();
    String httpVersion = "";

    try {
        httpClient.executeMethod(post);
        post.getResponseBodyAsString();
        httpVersion = post.getStatusLine().getHttpVersion();
    } finally {
        post.releaseConnection();
    }
    Assert.assertEquals(httpVersion, HttpVersion.HTTP_1_1.toString(), "Http version mismatched");
}
项目:intellij-ce-playground    文件:JiraIntegrationTest.java   
private String createIssueViaRestApi(@NotNull String project, @NotNull String summary) throws Exception {
  final HttpClient client = myRepository.getHttpClient();
  final PostMethod method = new PostMethod(myRepository.getUrl() + "/rest/api/latest/issue");
  try {
    // For simplicity assume that project, summary and username don't contain illegal characters
    @Language("JSON")
    final String json = "{\"fields\": {\n" +
                        "  \"project\": {\n" +
                        "    \"key\": \"" + project + "\"\n" +
                        "  },\n" +
                        "  \"issuetype\": {\n" +
                        "    \"name\": \"Bug\"\n" +
                        "  },\n" +
                        "  \"assignee\": {\n" +
                        "    \"name\": \"" + myRepository.getUsername() + "\"\n" +
                        "  },\n" +
                        "  \"summary\": \"" + summary + "\"\n" +
                        "}}";
    method.setRequestEntity(new StringRequestEntity(json, "application/json", "utf-8"));
    client.executeMethod(method);
    return new Gson().fromJson(method.getResponseBodyAsString(), JsonObject.class).get("id").getAsString();
  }
  finally {
    method.releaseConnection();
  }
}
项目:build-notifications-plugin    文件:BotecoMessage.java   
@Override
public void send() {
  HttpClient client = new HttpClient();
  PostMethod post = new PostMethod(endpoint);
  post.setRequestHeader("Content-Type", "application/json; charset=utf-8");
  Map<String, String> values = new HashMap<String, String>();
  values.put("title", title);
  values.put("text", content + "\n\n" + extraMessage);
  values.put("url", url);
  values.put("priority", priority);
  try {
    post.setRequestEntity(new StringRequestEntity(JSONObject.fromObject(values).toString(),
        "application/json", "UTF-8"));
    client.executeMethod(post);
  } catch (IOException e) {
    LOGGER.severe("Error while sending notification: " + e.getMessage());
    e.printStackTrace();
  }
}
项目:HareDBWebRESTful    文件:HareSparkResourceTest.java   
@BeforeClass
public static void setUpBeforeClass() throws Exception{
    checkLocalJarFile();
    checkSparkAssemblyJar();

    clusterConfiguration = HareSparkResourceTest.class.getResource("/hadoopConf").getPath();

    PostMethod method = new PostMethod(httpUrlRoot + "/usersession");
    String json = HareSparkResourceTest.objectToJsonStr(HareSparkResourceTest.getUserSession());

    StringRequestEntity requestEntity = new StringRequestEntity(json, contentType, charSet);
    method.setRequestEntity(requestEntity);

    int statusCode = client.executeMethod(method);
    assertEquals(200, statusCode);//test create session
}
项目:HareDBWebRESTful    文件:HareSparkResourceTest.java   
@Test
public void testAlterTable() throws Exception{
    testCreateTable();
    String tableName = "testtable";

    PostMethod method = new PostMethod(httpUrlRoot + "/altertable");
    AlterTableBean alterTableBean = new AlterTableBean();
    alterTableBean.setTablename(tableName);
    alterTableBean.setColumnNames(Arrays.asList("col1", "col2"));
    alterTableBean.setDataTypes(Arrays.asList("string", "string"));

    String json = HareSparkResourceTest.objectToJsonStr(alterTableBean);

    StringRequestEntity requestEntity = new StringRequestEntity(json, contentType, charSet);
    method.setRequestEntity(requestEntity);
    int status = client.executeMethod(method);
    assertEquals(200, status);

    byte[] resultByte = method.getResponseBody(1024 * 1024 * 10);
    String result = new String(resultByte);

    Gson gson = new Gson();
    ResponseInfoBean response = gson.fromJson(result, ResponseInfoBean.class);
    assertEquals("success", response.getStatus());
}
项目:HareDBWebRESTful    文件:HareSparkResourceTest.java   
@Test
public void testUploadDataFileStatus() throws Exception{
    String jobName = this.uploadFile("uploadTable");

    PostMethod method = new PostMethod(httpUrlRoot + "/uploaddatafile/status");
    UploadDataFileStatusBean uploadDataFileStatusBean = new UploadDataFileStatusBean();
    uploadDataFileStatusBean.setUploadJobName(jobName);

    String json = HareSparkResourceTest.objectToJsonStr(uploadDataFileStatusBean);

    StringRequestEntity requestEntity = new StringRequestEntity(json, contentType, charSet);
    method.setRequestEntity(requestEntity);
    client.executeMethod(method);

    byte[] resultByte = method.getResponseBody(1024 * 1024 * 20);
    String result = new String(resultByte);

    Gson gson = new Gson();
    UploadDataFileStatusResponseBean response = gson.fromJson(result, UploadDataFileStatusResponseBean.class);
    assertEquals(response.getStatus(), "success");
    assertTrue(response.getException() == null);
}
项目:HareDBWebRESTful    文件:HareSparkResourceTest.java   
@Ignore
@Test
public void testQueryStatus() throws Exception{
    PostMethod method = new PostMethod(httpUrlRoot + "/querystatus");
    QueryStatusBean queryStatusBean = new QueryStatusBean();
    //TODO set appliationName

    String json = HareSparkResourceTest.objectToJsonStr(queryStatusBean);

    StringRequestEntity requestEntity = new StringRequestEntity(json, contentType, charSet);
    method.setRequestEntity(requestEntity);
    client.executeMethod(method);

    byte[] resultByte = method.getResponseBody(1024 * 1024 * 10);
    String result = new String(resultByte);

    Gson gson = new Gson();
    QueryStatusResponseBean response = gson.fromJson(result, QueryStatusResponseBean.class);
    response.getJobStatus();
}
项目:HareDBWebRESTful    文件:HareSparkResourceTest.java   
private ResponseInfoBean createTable(String tableName) throws Exception{
    PostMethod method = new PostMethod(httpUrlRoot + "/createtable");
    CreateTableBean createTableBean = new CreateTableBean();
    createTableBean.setTablename(tableName);
    createTableBean.setColumnNames(Arrays.asList("col1", "col2", "col3", "col4"));
    createTableBean.setDataTypes(Arrays.asList("string", "string", "string", "string"));

    String json = HareSparkResourceTest.objectToJsonStr(createTableBean);
    StringRequestEntity requestEntity = new StringRequestEntity(json, contentType, charSet);
    method.setRequestEntity(requestEntity);
    client.executeMethod(method);
    byte[] resultByte = method.getResponseBody(1024 * 1024 * 10);
    String result = new String(resultByte);

    Gson gson = new Gson();
    return gson.fromJson(result, ResponseInfoBean.class);
}
项目:HareDBWebRESTful    文件:HareSparkResourceTest.java   
private DescribeTableResponseBean tableDescribe(String tableName) throws Exception{
    PostMethod method = new PostMethod(httpUrlRoot + "/describetable");
    DescribeTableBean describeTableBean = new DescribeTableBean();
    describeTableBean.setTablename(tableName);
    String json = HareSparkResourceTest.objectToJsonStr(describeTableBean);

    StringRequestEntity requestEntity = new StringRequestEntity(json, contentType, charSet);
    method.setRequestEntity(requestEntity);

    int statusCode = client.executeMethod(method);
    assertEquals(200, statusCode);

    byte[] resultByte = method.getResponseBody(1024 * 1024 *10);
    String result = new String(resultByte);

    Gson gson = new Gson();
    return gson.fromJson(result, DescribeTableResponseBean.class);
}
项目:HareDBWebRESTful    文件:HareSparkResourceTest.java   
private boolean isExists(String tableName) throws Exception{
    PostMethod method = new PostMethod(httpUrlRoot + "/isExists");

    StringRequestEntity requestEntity = new StringRequestEntity(tableName, contentType, charSet);
    method.setRequestEntity(requestEntity);
    client.executeMethod(method);
    byte[] resultByte = method.getResponseBody(1024 * 1024 * 10);
    String result = new String(resultByte);

    Gson gson = new Gson();
    if(gson.fromJson(result, String.class).equals("true")){
        return true;
    }else{
        return false;
    }
}