List of usage examples for org.apache.http.client.methods HttpUriRequest getMethod
String getMethod();
From source file:com.comcast.cim.rest.client.xhtml.TestRequestBuilder.java
@Test public void testBuildsAPostRequestIfFormMethodSaysSo() throws Exception { Element form = new Element("form", XhtmlParser.XHTML_NS_URI); form.setAttribute("method", "post"); form.setAttribute("action", "http://foo.example.com/"); buildDocument(form);/* ww w. jav a2 s .c o m*/ URL context = new URL("http://www.example.com/"); HttpUriRequest result = impl.submitForm(form, context, args); Assert.assertEquals("POST", result.getMethod()); }
From source file:ch.cyberduck.core.s3.RequestEntityRestStorageService.java
@Override protected HttpUriRequest setupConnection(final HTTP_METHOD method, final String bucketName, final String objectKey, final Map<String, String> requestParameters) throws S3ServiceException { final HttpUriRequest request = super.setupConnection(method, bucketName, objectKey, requestParameters); if (preferences.getBoolean("s3.upload.expect-continue")) { if ("PUT".equals(request.getMethod())) { // #7621 final Jets3tProperties properties = getJetS3tProperties(); if (!properties.getBoolProperty("s3service.disable-expect-continue", false)) { request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE); }// w w w.jav a 2s . c o m } } if (preferences.getBoolean("s3.bucket.requesterpays")) { // Only for AWS if (session.getHost().getHostname().endsWith(preferences.getProperty("s3.hostname.default"))) { // Downloading Objects in Requester Pays Buckets if ("GET".equals(request.getMethod()) || "POST".equals(request.getMethod())) { final Jets3tProperties properties = getJetS3tProperties(); if (!properties.getBoolProperty("s3service.disable-request-payer", false)) { // For GET and POST requests, include x-amz-request-payer : requester in the header request.addHeader("x-amz-request-payer", "requester"); } } } } return request; }
From source file:org.jasig.portlet.proxy.service.web.HttpContentServiceImpl.java
public GenericContentResponseImpl getContent(HttpContentRequestImpl proxyRequest, PortletRequest request, boolean runWrapperMethods) { try {//from w ww. j a v a2 s . co m // get an HttpClient appropriate for this user and portlet instance // and set any basic auth credentials, if applicable final AbstractHttpClient httpclient = httpClientService.getHttpClient(request); // create the request final HttpUriRequest httpRequest = getHttpRequest(proxyRequest, request); if (log.isTraceEnabled()) { log.trace("Proxying " + httpRequest.getURI() + " via " + httpRequest.getMethod()); } // execute the request final HttpContext context = new BasicHttpContext(); final HttpResponse response = httpclient.execute(httpRequest, context); final HttpEntity entity = response.getEntity(); // create the response object and set the content stream final HttpContentResponseImpl proxyResponse = new HttpContentResponseImpl(entity); proxyResponse.setContent(entity.getContent()); // add each response header to our response object for (Header header : response.getAllHeaders()) { proxyResponse.getHeaders().put(header.getName(), header.getValue()); } // set the final URL of the response in case it was redirected String finalUrl = (String) context.getAttribute(RedirectTrackingResponseInterceptor.FINAL_URL_KEY); if (finalUrl == null) { finalUrl = proxyRequest.getProxiedLocation(); } proxyResponse.setProxiedLocation(finalUrl); return proxyResponse; } catch (ClientProtocolException e) { log.error("Exception retrieving remote content", e); } catch (IOException e) { log.error("Exception retrieving remote content", e); } return null; }
From source file:com.comcast.cim.rest.client.xhtml.TestRequestBuilder.java
@Test public void testBuildsAPostRequestWithFormUrlEncodingForMethodPost() throws Exception { Element form = new Element("form", XhtmlParser.XHTML_NS_URI); form.setAttribute("method", "POST"); form.setAttribute("action", "http://foo.example.com/"); Element input = new Element("input", XhtmlParser.XHTML_NS_URI); input.setAttribute("type", "text"); input.setAttribute("name", "arg0"); form.addContent(input);// w ww.j a v a2 s. co m Element input2 = new Element("input", XhtmlParser.XHTML_NS_URI); input2.setAttribute("type", "submit"); form.addContent(input2); buildDocument(form); URL context = new URL("http://www.example.com/foo/bar"); args.put("arg0", "val0"); HttpUriRequest result = impl.submitForm(form, context, args); Assert.assertEquals("POST", result.getMethod()); HttpEntity entity = ((HttpPost) result).getEntity(); Assert.assertNotNull(entity); Assert.assertEquals("arg0=val0", EntityUtils.toString(entity)); }
From source file:com.comcast.cim.rest.client.xhtml.TestRequestBuilder.java
@Test public void testWillSubmitADefaultSelectionIfNotSpecified() throws Exception { Element form = new Element("form", XhtmlParser.XHTML_NS_URI); form.setAttribute("method", "POST"); form.setAttribute("action", "http://foo.example.com/"); Element select = new Element("select", XhtmlParser.XHTML_NS_URI); select.setAttribute("name", "arg0"); Element option = new Element("option", XhtmlParser.XHTML_NS_URI); option.setAttribute("value", "val0"); option.setAttribute("selected", "true"); option.setText("Description of val0"); select.addContent(option);/* ww w . ja v a 2 s . c o m*/ form.addContent(select); buildDocument(form); URL context = new URL("http://www.example.com/foo/bar"); HttpUriRequest result = impl.submitForm(form, context, args); Assert.assertEquals("POST", result.getMethod()); HttpEntity entity = ((HttpPost) result).getEntity(); Assert.assertNotNull(entity); Assert.assertEquals("arg0=val0", EntityUtils.toString(entity)); }
From source file:org.soyatec.windowsazure.internal.util.HttpUtilities.java
/** * Create the http request with common headers. * //w w w.java2s. c o m * @param uri * @param method * @param timeout * @return HttpRequest */ public static HttpRequest createHttpRequestWithCommonHeaders(URI uri, String method, TimeSpan timeout) { HttpUriRequest request = createHttpRequest(uri, method); // Some header setting // request.Timeout = (int)timeout.TotalMilliseconds; if (timeout != null) { request.addHeader(HeaderNames.Sotimeout, Long.toString(timeout.toMilliseconds())); } // request.ReadWriteTimeout = (int)timeout.TotalMilliseconds; // request.ContentLength = 0; if (request.getHeaders(HeaderNames.ContentLength) == null || request.getHeaders(HeaderNames.ContentLength).length <= 0) { if (!request.getMethod().equals(HttpMethod.Put) && !request.getMethod().equals(HttpMethod.Post)) { // not set content length header for put method request.addHeader(HeaderNames.ContentLength, "0"); } } // set timeout request.addHeader(HeaderNames.StorageDateTime, Utilities.getUTCTime()); return request; }
From source file:com.comcast.cim.rest.client.xhtml.TestRequestBuilder.java
@Test public void testCanSubmitAFormWithASelectInput() throws Exception { Element form = new Element("form", XhtmlParser.XHTML_NS_URI); form.setAttribute("method", "POST"); form.setAttribute("action", "http://foo.example.com/"); Element select = new Element("select", XhtmlParser.XHTML_NS_URI); select.setAttribute("name", "arg0"); Element option1 = new Element("option", XhtmlParser.XHTML_NS_URI); option1.setAttribute("value", "val0"); option1.setText("Description of val0"); select.addContent(option1);//from ww w . j a v a 2 s .c o m Element option2 = new Element("option", XhtmlParser.XHTML_NS_URI); option2.setAttribute("value", "val1"); option2.setAttribute("selected", "true"); option2.setText("Description of val1"); select.addContent(option2); form.addContent(select); buildDocument(form); URL context = new URL("http://www.example.com/foo/bar"); args.put("arg0", "val0"); HttpUriRequest result = impl.submitForm(form, context, args); Assert.assertEquals("POST", result.getMethod()); HttpEntity entity = ((HttpPost) result).getEntity(); Assert.assertNotNull(entity); Assert.assertEquals("arg0=val0", EntityUtils.toString(entity)); }
From source file:com.socialize.net.AsyncHttpRequestProcessor.java
@Override protected AsyncHttpResponse doInBackground(AsyncHttpRequest... params) { AsyncHttpRequest request = params[0]; AsyncHttpResponse response = new AsyncHttpResponse(); response.setRequest(request);//from w w w.ja v a 2 s.c om try { HttpUriRequest httpRequest = request.getRequest(); if (!clientFactory.isDestroyed()) { if (logger != null && logger.isDebugEnabled()) { logger.debug( "Request: " + httpRequest.getMethod() + " " + httpRequest.getRequestLine().getUri()); StringBuilder builder = new StringBuilder(); Header[] allHeaders = httpRequest.getAllHeaders(); for (Header header : allHeaders) { builder.append(header.getName()); builder.append(":"); builder.append(header.getValue()); builder.append("\n"); } logger.debug("REQUEST \nurl:[" + httpRequest.getURI().toString() + "] \nheaders:\n" + builder.toString()); if (httpRequest instanceof HttpPost) { HttpPost post = (HttpPost) httpRequest; HttpEntity entity = post.getEntity(); if (!(entity instanceof MultipartEntity)) { String requestData = ioUtils.readSafe(entity.getContent()); logger.debug("REQUEST \ndata:[" + requestData + "]"); } } } HttpClient client = clientFactory.getClient(); HttpResponse httpResponse = client.execute(httpRequest); response.setResponse(httpResponse); if (logger != null && logger.isDebugEnabled()) { logger.debug("RESPONSE CODE: " + httpResponse.getStatusLine().getStatusCode()); } HttpEntity entity = null; try { entity = httpResponse.getEntity(); if (httpUtils.isHttpError(httpResponse)) { String msg = ioUtils.readSafe(entity.getContent()); throw new SocializeApiError(httpUtils, httpResponse.getStatusLine().getStatusCode(), msg); } else { String responseData = ioUtils.readSafe(entity.getContent()); if (logger != null && logger.isDebugEnabled()) { logger.debug("RESPONSE: " + responseData); } response.setResponseData(responseData); } } finally { closeEntity(entity); } } else { throw new SocializeException("Cannot execute http request. HttpClient factory was destroyed."); } } catch (Exception e) { response.setError(e); } return response; }
From source file:com.comcast.cim.rest.client.xhtml.TestRequestBuilder.java
@Test public void testCanBuildRequestForAbsoluteLinkHref() throws Exception { Element a = new Element("a", XhtmlParser.XHTML_NS_URI); String absoluteUri = "http://www.example.com/foo"; a.setAttribute("href", absoluteUri); buildDocument(a);//from ww w . ja v a 2s . c o m URL context = new URL("http://bar.example.com/"); HttpUriRequest result = impl.followLink(a, context); Assert.assertNotNull(result); Assert.assertEquals("GET", result.getMethod()); Assert.assertEquals(absoluteUri, result.getURI().toString()); }
From source file:com.comcast.cim.rest.client.xhtml.TestRequestBuilder.java
@Test public void testCanBuildRequestForRelativeLinkHref() throws Exception { Element a = new Element("a", XhtmlParser.XHTML_NS_URI); a.setAttribute("href", "/foo"); buildDocument(a);/* w ww. j a v a 2 s. co m*/ URL context = new URL("http://www.example.com/bar"); HttpUriRequest result = impl.followLink(a, context); Assert.assertNotNull(result); Assert.assertEquals("GET", result.getMethod()); Assert.assertEquals("http://www.example.com/foo", result.getURI().toString()); }