Example usage for org.apache.commons.httpclient.methods InputStreamRequestEntity InputStreamRequestEntity

List of usage examples for org.apache.commons.httpclient.methods InputStreamRequestEntity InputStreamRequestEntity

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods InputStreamRequestEntity InputStreamRequestEntity.

Prototype

public InputStreamRequestEntity(InputStream paramInputStream, long paramLong, String paramString) 

Source Link

Usage

From source file:com.ebt.platform.utility.WebServiceCaller.java

public static String CallCasWebService(String xml) {
    PostMethod postMethod = new PostMethod("http://ws.e-baotong.cn:8085/CASServer.asmx?wsdl");
    String responseString = null;
    try {// w w  w.ja  va  2s .  c o m
        byte[] b = xml.getBytes("utf-8");
        InputStream inS = new ByteArrayInputStream(b, 0, b.length);
        RequestEntity req = new InputStreamRequestEntity(inS, b.length, "text/xml; charset=utf-8");
        postMethod.setRequestEntity(req);

        HttpClient httpClient = new HttpClient();
        int statusCode = httpClient.executeMethod(postMethod);
        if (statusCode == 200) {
            responseString = new String(postMethod.getResponseBodyAsString().getBytes("ISO-8859-1"), "UTF-8");
            System.out.println("WebService??====" + responseString);
        } else {
            System.out.println("WebService??" + statusCode);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return responseString;
}

From source file:com.ebt.platform.utility.WebServiceCaller.java

private static String CallDatv2WebService(String xml) {
    PostMethod postMethod = new PostMethod("http://datv2.e-baotong.cn:9089/GetVersionData.asmx?wsdl");
    String responseString = null;
    try {//w  ww. j a v  a2 s .  c o  m
        byte[] b = xml.getBytes("utf-8");
        InputStream inS = new ByteArrayInputStream(b, 0, b.length);
        RequestEntity req = new InputStreamRequestEntity(inS, b.length, "text/xml; charset=utf-8");
        postMethod.setRequestEntity(req);

        HttpClient httpClient = new HttpClient();
        int statusCode = httpClient.executeMethod(postMethod);
        if (statusCode == 200) {
            responseString = new String(postMethod.getResponseBodyAsString().getBytes("ISO-8859-1"), "UTF-8");
            System.out.println("WebService??====" + responseString);
        } else {
            System.out.println("WebService??" + statusCode);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return responseString;
}

From source file:com.zimbra.common.httpclient.HttpClientUtil.java

public static <T extends EntityEnclosingMethod> T addInputStreamToHttpMethod(T method, InputStream is,
        long size, String contentType) {
    if (size < 0) {
        size = InputStreamRequestEntity.CONTENT_LENGTH_AUTO;
    }/*from  ww  w.jav  a 2  s . co m*/
    method.setRequestEntity(new InputStreamRequestEntity(is, size, contentType));
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new InputStreamRequestHttpRetryHandler());
    return method;
}

From source file:com.hp.alm.ali.rest.client.InputData.java

public RequestEntity getRequestEntity(String encoding) {
    if (data != null) {
        RequestEntity requestEntity;/*from   www .jav  a  2  s  .  co  m*/
        try {
            requestEntity = new StringRequestEntity(data, "application/xml", encoding);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
        return requestEntity;
    } else if (dataStream != null) {
        return new InputStreamRequestEntity(dataStream, size, "application/xml");
    } else {
        return null;
    }
}

From source file:com.tasktop.c2c.server.web.proxy.HttpProxy.java

@Override
protected void proxy(String targetUrl, final HttpServletRequest request, final HttpServletResponse response)
        throws IOException {

    final HttpMethod proxyRequest = createProxyRequest(targetUrl, request);

    if (proxyRequest instanceof EntityEnclosingMethod) {
        EntityEnclosingMethod entityEnclosingMethod = (EntityEnclosingMethod) proxyRequest;
        RequestEntity requestEntity = new InputStreamRequestEntity(request.getInputStream(),
                request.getContentLength(), request.getContentType());
        entityEnclosingMethod.setRequestEntity(requestEntity);
    }/*from   www .  j av a  2 s.  c om*/
    int code = httpClient.executeMethod(proxyRequest);
    response.setStatus(code);
    copyProxyReponse(proxyRequest, response);

}

From source file:com.founder.zykc.controller.FdbzcrjryController.java

@RestfulAnnotation(serverId = "3")
@RequestMapping(value = "/queryFdbzcrjList", method = RequestMethod.POST)
public @ResponseBody EasyUIPage queryList(EasyUIPage page,
        @RequestParam(value = "rows", required = false) Integer rows, String sfzhm, String zwxm,
        SessionBean sessionBean) {//from w ww .  j a  v  a 2 s. c o  m

    page.setPagePara(rows);

    String url = "http://10.78.17.154:9999/lbs";
    String urlParameter = "operation=ForbiddenDepartureManagement_GetInfoByIDName_v001&license=a756244eb0236bdc26061cb6b6bdb481&content=";

    int total = 0;
    List<FdbzcrjryVo> list = new ArrayList<FdbzcrjryVo>();

    String content = "";
    boolean isUpdated = false;
    if (!StringUtils.isEmpty(sfzhm) && !StringUtils.isEmpty(zwxm)) {

        content = "{\"data\":[{\"SFZHM\":\"" + sfzhm + "\"," + "\"ZWXM\":\"" + zwxm + "\"}]," + "\"pageindex\":"
                + (Integer.valueOf(page.getPage()) - 1) + "," + "\"pagesize\":" + rows + "}";
    } else if (StringUtils.isEmpty(sfzhm)) {
        content = "{\"data\":[{\"ZWXM\":\"" + zwxm + "\"}]," + "\"pageindex\":"
                + (Integer.valueOf(page.getPage()) - 1) + "," + "\"pagesize\":" + rows + "}";
    } else if (StringUtils.isEmpty(zwxm)) {
        // content = "{\"data\":[{\"SFZHM\":\"" + sfzhm
        // + "\"}]}";
        content = "{\"data\":[{\"SFZHM\":\"" + sfzhm + "\"}]," + "\"pageindex\":"
                + (Integer.valueOf(page.getPage()) - 1) + "," + "\"pagesize\":" + rows + "}";
    }

    try {
        content = urlParameter + java.net.URLEncoder.encode(content, "UTF-8");
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
    }
    PostMethod postMethod = new PostMethod(url);
    byte[] b;
    try {
        b = content.getBytes("utf-8");

        InputStream is = new ByteArrayInputStream(b, 0, b.length);
        RequestEntity re = new InputStreamRequestEntity(is, b.length, "application/soap+xml; charset=utf-8");
        postMethod.setRequestEntity(re);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    HttpClient httpClient = new HttpClient();
    HttpConnectionManagerParams managerParams = httpClient.getHttpConnectionManager().getParams();
    managerParams.setConnectionTimeout(50000);

    int statusCode = 0;
    try {
        statusCode = httpClient.executeMethod(postMethod);
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (statusCode == 200) {
        String soapResponseData = "";
        try {
            soapResponseData = postMethod.getResponseBodyAsString();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        JSONObject jb = JSONObject.fromObject(soapResponseData);

        if ((Integer) jb.get("datalen") > 0) {

            Map<String, String> dictHkszd = new HashMap<String, String>();//?
            Map<String, String> dictFlyj = new HashMap<String, String>();//??
            Map<String, String> dictCsd = new HashMap<String, String>();//
            Map<String, String> dictBbrylx = new HashMap<String, String>();//
            Map<String, String> dictPcs = new HashMap<String, String>();//
            Map<String, String> dictXb = new HashMap<String, String>();//
            Map<String, String> dictZjzl = new HashMap<String, String>();//??   
            Map<String, String> dictZzjg = new HashMap<String, String>();//      
            Map<String, String> dictMj = new HashMap<String, String>();//

            try {
                dictHkszd = sysDictGlService.getDictMap("BD_D_FDBZCJHKSZD");
                dictFlyj = sysDictGlService.getDictMap("BD_D_FDBZCJFLYJ");
                dictCsd = sysDictGlService.getDictMap("BD_D_FDBZCJCSD");
                dictBbrylx = sysDictGlService.getDictMap("BD_D_FDBZCJBBRYLB");
                dictPcs = sysDictGlService.getDictMap("BD_D_FDBZCJPCS");
                dictXb = sysDictGlService.getDictMap("BD_D_FDBZCJXB");
                dictZjzl = sysDictGlService.getDictMap("BD_D_FDBZCJZJZL");
                dictZzjg = sysDictGlService.getDictMap("BD_D_FDBZCJORG");
                dictMj = sysDictGlService.getDictMap("BD_D_FDBZCJMJ");

            } catch (Exception e2) {
                // TODO Auto-generated catch block
                e2.printStackTrace();
            }

            total = Integer.valueOf(jb.getString("total"));

            for (int i = 0; i < (Integer) jb.get("datalen"); i++) {
                JSONObject jo = jb.getJSONArray("data").getJSONObject(i);

                FdbzcrjryVo vo = new FdbzcrjryVo();
                if (jo.containsKey("BBDWBM")) {
                    vo.setBbdwbm(dictZzjg.get(jo.getString("BBDWBM")));
                }
                if (jo.containsKey("BBLXDH")) {
                    vo.setBblxdh(jo.getString("BBLXDH"));
                }
                if (jo.containsKey("BBLXR")) {
                    vo.setBblxr(jo.getString("BBLXR"));
                }
                if (jo.containsKey("BBQX")) {
                    vo.setBbqx(jo.getString("BBQX"));
                }
                if (jo.containsKey("BBRQ")) {
                    vo.setBbrq(jo.getString("BBRQ"));
                }
                if (jo.containsKey("BBRYLB")) {
                    vo.setBbrylb(dictBbrylx.get(jo.getString("BBRYLB")));
                }
                if (jo.containsKey("BBYY")) {
                    vo.setBbyy(jo.getString("BBYY"));
                }
                if (jo.containsKey("BZ")) {
                    vo.setBz(jo.getString("BZ"));
                }
                if (jo.containsKey("CSD")) {
                    vo.setCsd(dictCsd.get(jo.getString("CSD")));
                }
                if (jo.containsKey("DAH")) {
                    vo.setDah(jo.getString("DAH"));
                }
                if (jo.containsKey("DWDH")) {
                    vo.setDwdh(jo.getString("DWDH"));
                }
                if (jo.containsKey("FLYJ")) {
                    vo.setFlyj(dictFlyj.get(jo.getString("FLYJ")));
                }
                if (jo.containsKey("GZDW")) {
                    vo.setGzdw(jo.getString("GZDW"));
                }
                if (jo.containsKey("HKSZD")) {
                    vo.setHkszd(dictHkszd.get(jo.getString("HKSZD")));
                }
                if (jo.containsKey("FLYJ")) {
                    vo.setFlyj(dictFlyj.get(jo.getString("FLYJ")));
                }
                if (jo.containsKey("JTDH")) {
                    vo.setJtdh(jo.getString("JTDH"));
                }
                if (jo.containsKey("MJ")) {
                    vo.setMj(dictMj.get(jo.getString("MJ")));
                }
                if (jo.containsKey("PCSSZD")) {
                    vo.setPcsszd(dictPcs.get(jo.getString("PCSSZD")));
                }
                if (jo.containsKey("PYXM")) {
                    vo.setPyxm(jo.getString("PYXM"));
                }
                if (jo.containsKey("SFZDCK")) {
                    vo.setSfzdck(jo.getString("SFZDCK"));
                }
                if (jo.containsKey("SFZHM")) {
                    vo.setSfzhm(jo.getString("SFZHM"));
                }
                if (jo.containsKey("XB")) {
                    vo.setXb(dictXb.get(jo.getString("XB")));
                }
                if (jo.containsKey("XZZ")) {
                    vo.setXzz(jo.getString("XZZ"));
                }
                if (jo.containsKey("ZJHM")) {
                    vo.setZjhm(jo.getString("ZJHM"));
                }
                if (jo.containsKey("ZJZL")) {
                    vo.setZjzl(dictZjzl.get(jo.getString("ZJZL")));
                }
                if (jo.containsKey("ZWM")) {
                    vo.setZwm(jo.getString("ZWM"));
                }
                if (jo.containsKey("ZWX")) {
                    vo.setZwx(jo.getString("ZWX"));
                }
                if (jo.containsKey("RYDH")) {
                    vo.setRydh(jo.getString("RYDH"));
                }
                list.add(vo);
            }
        }
    } else {
        System.out.println("????" + statusCode);
    }
    page.setRows(list);
    page.setTotal(total);
    return page;
}

From source file:net.sf.antcontrib.net.httpclient.PostMethodTask.java

protected void configureMethod(HttpMethodBase method) {
    PostMethod post = (PostMethod) method;

    if (parts.size() == 1 && !multipart) {
        Object part = parts.get(0);
        if (part instanceof FilePartType) {
            FilePartType filePart = (FilePartType) part;
            try {
                stream = new FileInputStream(filePart.getPath().getAbsolutePath());
                post.setRequestEntity(new InputStreamRequestEntity(stream, filePart.getPath().length(),
                        filePart.getContentType()));
            } catch (IOException e) {
                throw new BuildException(e);
            }//w  w  w.  j  a v  a 2  s. c  o m
        } else if (part instanceof TextPartType) {
            TextPartType textPart = (TextPartType) part;
            try {
                post.setRequestEntity(new StringRequestEntity(textPart.getValue(), textPart.getContentType(),
                        textPart.getCharSet()));
            } catch (UnsupportedEncodingException e) {
                throw new BuildException(e);
            }
        }
    } else if (!parts.isEmpty()) {
        Part partArray[] = new Part[parts.size()];
        for (int i = 0; i < parts.size(); i++) {
            Object part = parts.get(i);
            if (part instanceof FilePartType) {
                FilePartType filePart = (FilePartType) part;
                try {
                    partArray[i] = new FilePart(filePart.getPath().getName(), filePart.getPath().getName(),
                            filePart.getPath(), filePart.getContentType(), filePart.getCharSet());
                } catch (FileNotFoundException e) {
                    throw new BuildException(e);
                }
            } else if (part instanceof TextPartType) {
                TextPartType textPart = (TextPartType) part;
                partArray[i] = new StringPart(textPart.getName(), textPart.getValue(), textPart.getCharSet());
                ((StringPart) partArray[i]).setContentType(textPart.getContentType());
            }
        }
        MultipartRequestEntity entity = new MultipartRequestEntity(partArray, post.getParams());
        post.setRequestEntity(entity);
    }
}

From source file:com.founder.zykc.controller.FdbzcrjryController.java

@SuppressWarnings("static-access")
@RequestMapping(value = "/queryFdbzcrjryPhoto.jpg", method = RequestMethod.GET)
public HttpEntity<byte[]> queryFdbzcrjryPhoto(String rydh, SessionBean sessionBean) {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.IMAGE_JPEG);
    sessionBean = getSessionBean(sessionBean);

    byte[] pictureByte = null;

    String url = "http://10.78.17.154:9999/lbs";
    String zpParameter = "operation=ForbiddenDepartureManagement_GetPhotoByID_v001&license=a756244eb0236bdc26061cb6b6bdb481&content=";
    String zpContent = "{\"data\":[{\"RYDH\":\"" + rydh + "\"}]}";
    try {/*from  www . j  a  va 2s.  c o m*/

        zpContent = zpParameter + java.net.URLEncoder.encode(zpContent, "UTF-8");
        PostMethod postMethod = new PostMethod(url);
        byte[] b = zpContent.getBytes("utf-8");
        InputStream is = new ByteArrayInputStream(b, 0, b.length);
        RequestEntity re = new InputStreamRequestEntity(is, b.length, "application/soap+xml; charset=utf-8");
        postMethod.setRequestEntity(re);
        HttpClient httpClient = new HttpClient();
        HttpConnectionManagerParams managerParams = httpClient.getHttpConnectionManager().getParams();
        managerParams.setConnectionTimeout(50000);
        int statusCode = httpClient.executeMethod(postMethod);
        if (statusCode == 200) {
            String soapResponseData = postMethod.getResponseBodyAsString();
            JSONObject jb = JSONObject.fromObject(soapResponseData);
            if ((Integer) jb.get("datalen") > 0) {
                JSONObject jo = jb.getJSONArray("data").getJSONObject(0);

                try {
                    pictureByte = new BASE64Decoder().decodeBuffer(jo.getString("PHOTO"));
                } catch (Exception ex) {
                }
                if (pictureByte != null) {

                } else {
                    System.out.println("??" + statusCode);
                    byte[] empty_ryzp = SystemConfig.getByteArray("empty_ryzp");
                    headers.setContentLength(empty_ryzp.length);
                    return new HttpEntity(empty_ryzp, headers);
                }

            } else {
                System.out.println("??" + statusCode);
                byte[] empty_ryzp = SystemConfig.getByteArray("empty_ryzp");
                headers.setContentLength(empty_ryzp.length);
                return new HttpEntity(empty_ryzp, headers);
            }

        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    headers.setContentLength(pictureByte.length);
    return new HttpEntity(pictureByte, headers);

}

From source file:com.ebt.platform.utility.WebServiceCaller.java

public static String CallTKWebService(String xml, String webservicePath) {
    PostMethod postMethod = new PostMethod(webservicePath);
    String responseString = null;
    String key = "HOCMojuo1SY=";
    try {/*from  w w w .ja va  2  s  .com*/
        byte[] b = Base64.encode(DESCoder.encrypt(xml.getBytes("GBK"), key)).getBytes("UTF-8");
        InputStream inS = new ByteArrayInputStream(b, 0, b.length);
        RequestEntity req = new InputStreamRequestEntity(inS, b.length, "text/xml; charset=UTF-8");
        postMethod.setRequestEntity(req);

        HttpClient httpClient = new HttpClient();
        int statusCode = httpClient.executeMethod(postMethod);
        if (statusCode == 200) {
            //String teString = "Rc8vPD/7VKO5hmhaSEFIs+5Y4+vxCWsgxJRd2T3vtFuyOoJwklhLP+Rom/FPTqnA7XUqxV+tVaOL jr5oD9Kl4YgoVY/VedW7zYzSr95IIs1lB5J8PFws6s2M0q/eSCLNJx2pIfGaAoilvQKp0zzxoQxt 1JFTWwxNzO/kSu5IAj3uhQghuFBSjL8XDayI0z+xf2GfBm0cGCAZsuHXFZZQCn6cqTr7r8rBKKjH Q8nBkewMSwkiOcgqayiox0PJwZHslrOc+35gnEgy9mfmvxgJkgzXjdJsSjlJ4pQvxUHV8OmlA5hY pWLBIFR/4cyH6PY+BkDbVHv07XhjJXJymBAFn4tlHQjkHsKWrYeQWedxU7D1/rUeeOl27kdLMNCB i6OsAhHHQPK5PBqL2H/z3clPHyD6UaNQIHEf/wfQy6xZYmGaqXVgjZ2hIgGWGreKSEIJEzBvIFZm qCMMhE1nM/PAkemyUv9YJr0cvwvQgQ50f26rmc1VjVgnp7+LHpMEPs7AQxl+e3o9WaPaVh24E7A/ HEdLMNCBi6OsPQy6Sec0txkEtMxfrDjcHYxmHlzEujar";
            byte[] responses = Base64.decode(postMethod.getResponseBodyAsString());
            //byte[] responses = Base64.decode(teString);
            responseString = new String(DESCoder.decrypt(responses, key), "UTF-8");
            System.out.println("WebService??====" + responseString);
        } else {
            System.out.println("WebService??" + statusCode);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return responseString;
}

From source file:com.zimbra.qa.unittest.TestZimbraHttpConnectionManager.java

public void testSoTimeoutViaHttpPostMethod() throws Exception {

    int serverPort = 7778;
    String resourceToPost = "/opt/zimbra/unittest/rights-unittest.xml";
    long delayInServer = 100000; // delay 10 seconds in server
    int soTimeout = 60000; // 3000;  // 3 seconds, 0 for infinite wait

    String qp = "?" + SimpleHttpServer.DelayWhen.BEFORE_WRITING_RESPONSE_HEADERS.name() + "=" + delayInServer;
    String uri = "http://localhost:" + serverPort + resourceToPost + qp;

    // start a http server for testing
    SimpleHttpServer.start(serverPort);/*from  ww w.j a  va 2 s  .  c  o  m*/

    // post the exported content to the target server
    HttpClient httpClient = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
    PostMethod method = new PostMethod(uri);
    method.getParams().setSoTimeout(soTimeout); // infinite wait because it can take a long time to import a large mailbox

    File file = new File(resourceToPost);
    FileInputStream fis = null;

    long startTime = System.currentTimeMillis();
    long endTime;
    try {
        fis = new FileInputStream(file);
        InputStreamRequestEntity isre = new InputStreamRequestEntity(fis, file.length(),
                MimeConstants.CT_APPLICATION_OCTET_STREAM);
        method.setRequestEntity(isre);
        int respCode = httpClient.executeMethod(method);

        dumpResponse(respCode, method, "");
        Assert.fail(); // nope, it should have timed out
    } catch (java.net.SocketTimeoutException e) {
        e.printStackTrace();
        // good, just what we want
        endTime = System.currentTimeMillis();
        long elapsedTime = endTime - startTime;
        System.out.println("Client timed out after " + elapsedTime + " msecs");
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail();
    } finally {
        method.releaseConnection();
    }

    // shutdown the server
    SimpleHttpServer.shutdown();
}