List of usage examples for org.apache.commons.httpclient.params HttpMethodParams HttpMethodParams
public HttpMethodParams()
From source file:org.onebusaway.nyc.integration_tests.TraceSupport.java
public String uploadTraceForSimulation(String fileName, InputStream in, boolean _bypassInference) throws IOException { try {//w w w. ja v a2s. co m HttpClient client = new HttpClient(); String url = url("/vehicle-location-simulation!upload-trace.do"); PostMethod post = new PostMethod(url); ByteArrayPartSource source = getResourceAsPartSource(fileName, in); FilePart filePart = new FilePart("file", source); StringPart returnIdParam = new StringPart("returnId", "true"); StringPart shiftStartTimeParam = new StringPart("shiftStartTime", "" + shiftStartTime); StringPart traceTypeParam = new StringPart("traceType", "NycTestInferredLocationRecord"); StringPart historySize = new StringPart("historySize", "" + 0); StringPart bypassInference = new StringPart("bypassInference", "false"); if (_bypassInference == true) { bypassInference = new StringPart("bypassInference", "true"); } post.setRequestEntity(new MultipartRequestEntity(new Part[] { filePart, returnIdParam, shiftStartTimeParam, traceTypeParam, historySize, bypassInference }, new HttpMethodParams())); client.executeMethod(post); return post.getResponseBodyAsString(); } catch (HttpException ex) { throw new IllegalStateException(ex); } }
From source file:org.onebusaway.nyc.integration_tests.vehicle_tracking_webapp.TraceSupport.java
public String uploadTraceForSimulation(String fileName, InputStream in) throws IOException { try {//from www .j a v a 2 s .c o m HttpClient client = new HttpClient(); String url = url("/vehicle-location-simulation!upload-trace.do"); PostMethod post = new PostMethod(url); ByteArrayPartSource source = getResourceAsPartSource(fileName, in); FilePart filePart = new FilePart("file", source); StringPart returnIdParam = new StringPart("returnId", "true"); StringPart shiftStartTimeParam = new StringPart("shiftStartTime", "" + shiftStartTime); StringPart traceTypeParam = new StringPart("traceType", "NycTestLocationRecord"); post.setRequestEntity(new MultipartRequestEntity( new Part[] { filePart, returnIdParam, shiftStartTimeParam, traceTypeParam }, new HttpMethodParams())); client.executeMethod(post); return post.getResponseBodyAsString(); } catch (HttpException ex) { throw new IllegalStateException(ex); } }
From source file:org.pentaho.pac.server.PacServiceImpl.java
public String getHomePageAsHtml(String url) { String html = null;// ww w . j a v a 2s .co m HttpClient client = new HttpClient(); GetMethod get = null; try { String timeOut = AppConfigProperties.getInstance().getHomepageTimeout(); HttpMethodParams params = new HttpMethodParams(); params.setParameter(HttpMethodParams.SO_TIMEOUT, Integer.parseInt(timeOut)); get = new GetMethod(url); get.setParams(params); client.executeMethod(get); //getResponseBodyAsString() and the like were decoding as ISO-8859-1 instead of UTF-8. //This is indeed the default behavior of HttpClient if the charset is not defined in //the Content-Type reponse header. We're overriding that since we know our source is //UTF-8 byte[] bytes = get.getResponseBody(); html = new String(bytes, "UTF-8"); //$NON-NLS-1$ } catch (Exception e) { logger.error(e); html = showStatic(); } finally { if (get != null) { get.releaseConnection(); } } final String BODY_TAG = "<body>"; //$NON-NLS-1$ int afterBodyIdx = html.indexOf(BODY_TAG); if (-1 != afterBodyIdx) { html = html.substring(html.indexOf(BODY_TAG) + BODY_TAG.length()); html = html.substring(0, html.indexOf("</body>")); //$NON-NLS-1$ } return html; }
From source file:org.wso2.carbon.esb.proxyservice.test.proxyservices.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);/* w ww.j ava 2s.c o m*/ 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"); }
From source file:org.wso2.carbon.esb.proxyservice.test.proxyservices.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);/*from w w w .j av a2 s . c o m*/ 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"); }
From source file:org.zaproxy.zap.extension.ascanrulesAlpha.CloudMetadataScanner.java
void sendMessageWithCustomHostHeader(HttpMessage message, String host) throws IOException { HttpMethodParams params = new HttpMethodParams(); params.setVirtualHost(host);/*from ww w.j a va 2s . c o m*/ HttpMethod method = createRequestMethod(message.getRequestHeader(), message.getRequestBody(), params); if (!(method instanceof EntityEnclosingMethod) || method instanceof ZapGetMethod) { method.setFollowRedirects(false); } User forceUser = getParent().getHttpSender().getUser(message); message.setTimeSentMillis(System.currentTimeMillis()); if (forceUser != null) { getParent().getHttpSender().executeMethod(method, forceUser.getCorrespondingHttpState()); } else { getParent().getHttpSender().executeMethod(method, null); } message.setTimeElapsedMillis((int) (System.currentTimeMillis() - message.getTimeSentMillis())); HttpMethodHelper.updateHttpRequestHeaderSent(message.getRequestHeader(), method); HttpResponseHeader resHeader = HttpMethodHelper.getHttpResponseHeader(method); resHeader.setHeader(HttpHeader.TRANSFER_ENCODING, null); message.setResponseHeader(resHeader); message.getResponseBody().setCharset(resHeader.getCharset()); message.getResponseBody().setLength(0); message.getResponseBody().append(method.getResponseBody()); message.setResponseFromTargetHost(true); getParent().notifyNewMessage(this, message); }