List of usage examples for org.apache.http.client.methods HttpUriRequest getURI
URI getURI();
From source file:com.fujitsu.dc.test.jersey.DcRestAdapter.java
/** * ?./*ww w. j a v a2s.co m*/ * @param req ??Request * @param body ?? */ private void debugHttpRequest(final HttpUriRequest req, final String body) { log.debug(req.getURI()); if (log.isDebugEnabled()) { log.debug("?Request " + req.getMethod() + " " + req.getURI()); Header[] headers = req.getAllHeaders(); for (int i = 0; i < headers.length; i++) { log.debug("RequestHeader[" + headers[i].getName() + "] : " + headers[i].getValue()); } log.debug("RequestBody: " + body); } }
From source file:tech.sirwellington.alchemy.http.AlchemyRequestMapperTest.java
@Test public void testDelete() throws Exception { instance = AlchemyRequestMapper.DELETE; assertThat(instance, notNullValue()); HttpUriRequest result = instance.convertToApacheRequest(request); assertThat(result, notNullValue());/*from ww w . j a v a2 s .c o m*/ assertThat(result, instanceOf(HttpDelete.class)); assertThat(result.getURI(), is(url.toURI())); }
From source file:com.comcast.cim.rest.client.xhtml.TestRequestBuilder.java
@Test public void testAddsMultipleInstancesOfInputNamesToQueryParams() throws Exception { Element form = new Element("form", XhtmlParser.XHTML_NS_URI); form.setAttribute("method", "GET"); 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 .ja v a2s. c om*/ Element input2 = new Element("input", XhtmlParser.XHTML_NS_URI); input2.setAttribute("type", "text"); input2.setAttribute("name", "arg0"); 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("http://foo.example.com/?arg0=val0&arg0=val0", result.getURI().toString()); }
From source file:com.flicklib.service.HttpClientSourceLoader.java
private Source buildSource(String url, HttpResponse response, HttpRequestBase httpMethod, HttpContext ctx) throws IOException { LOGGER.info("Finished loading at " + httpMethod.getURI().toString()); final HttpEntity entity = response.getEntity(); String responseCharset = EntityUtils.getContentCharSet(entity); String contentType = EntityUtils.getContentMimeType(entity); LOGGER.info("Response charset = " + responseCharset); String content = EntityUtils.toString(entity); HttpUriRequest req = (HttpUriRequest) ctx.getAttribute(ExecutionContext.HTTP_REQUEST); HttpHost target = (HttpHost) ctx.getAttribute(ExecutionContext.HTTP_TARGET_HOST); URI resultUri;/*from www .ja v a 2 s .co m*/ try { resultUri = (target != null && req != null) ? new URI(target.toURI() + req.getURI().toString()) : httpMethod.getURI(); } catch (URISyntaxException e) { e.printStackTrace(); resultUri = httpMethod.getURI(); } // String contentType = URLConnection.guessContentTypeFromName(url) return new Source(resultUri.toString(), content, contentType, url); }
From source file:com.subgraph.vega.internal.http.requests.HttpRequestEngine.java
private RequestEngineException translateException(HttpUriRequest request, Throwable ex) { final StringBuilder sb = new StringBuilder(); if (ex instanceof IOException) { sb.append("Network problem"); } else if (ex instanceof HttpException) { sb.append("Protocol problem"); } else {//w w w.j av a 2s . com sb.append("Unknown problem"); } sb.append(" while retrieving URI "); sb.append(request.getURI().toString()); sb.append(" ["); sb.append(ex.getMessage()); sb.append("]"); return new RequestEngineException(sb.toString(), ex); }
From source file:com.twitter.hbc.SitestreamController.java
@VisibleForTesting HttpResponse makeControlStreamRequest(HttpUriRequest request) throws IOException, ControlStreamException { HttpResponse response = client.execute(request); if (response.getStatusLine() == null) { throw new ControlStreamException("No status line in response"); }/* www . ja v a2 s . c o m*/ logger.debug("{} returned with status line: {}", request.getURI(), response.getStatusLine()); if (response.getStatusLine().getStatusCode() != HttpConstants.Codes.SUCCESS) { logger.warn("{} returned with status code {}", request.getURI(), response.getStatusLine().getStatusCode()); if (response.getEntity() != null) { // close the resources if the request failed. this might be redundant EntityUtils.consume(response.getEntity()); } throw new ControlStreamException(response.getStatusLine()); } return response; }
From source file:org.jboss.pull.player.LabelProcessor.java
private HttpResponse execute(final HttpUriRequest request, final int status) throws IOException { final HttpResponse response = client.execute(request); if (response.getStatusLine().getStatusCode() != status) { err.printf("Could not %s to %s %n\t%s%n", request.getMethod(), request.getURI(), response.getStatusLine()); }//from w w w .j av a2 s. c om return response; }
From source file:com.github.mfpdev.marketing.StoreCategorySegmentResolverResource.java
private JSONObject getJSONObjectFromRequest(HttpUriRequest request) { JSONObject jsonObject = null;//from ww w. j a va 2 s .c o m try { String responseBody = httpClient.execute(request, responseHandler); jsonObject = JSONObject.parse(responseBody); } catch (IOException e) { logger.log(Level.SEVERE, "Issue while trying to invoke a request " + request.getURI() + " " + e.getMessage(), e); } return jsonObject; }
From source file:nl.salp.warcraft4j.battlenet.api.BattlenetHttpApi.java
/** * Execute the request and return the result body. * * @param request The request to execute. * @param client The client to use for executing the request. * * @return The result body./*from ww w . jav a2 s. c o m*/ * * @throws IOException When the call couldn't be executed or the server returned an error. */ private String execute(HttpUriRequest request, CloseableHttpClient client) throws IOException { try (CloseableHttpResponse response = client.execute(request)) { StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() > 300) { LOGGER.error("Request to '{}' returned code {} with message '{}'", request.getURI().toASCIIString(), statusLine.getStatusCode(), statusLine.getReasonPhrase()); throw new IOException( format("Error %d: %s", statusLine.getStatusCode(), statusLine.getReasonPhrase())); } HttpEntity entity = response.getEntity(); String result = EntityUtils.toString(entity); EntityUtils.consume(entity); LOGGER.debug("Request to '{}' successfully completed with code {}", request.getURI().toASCIIString(), statusLine.getStatusCode()); return result; } }
From source file:org.apache.sling.etcd.client.impl.EtcdClientImpl.java
@Nonnull private HttpUriRequest logMethod(@Nonnull HttpUriRequest method) { if (LOG.isDebugEnabled()) { LOG.debug("Execute {} request for uri {}", new Object[] { method.getMethod(), method.getURI() }); }// ww w. j ava2s . c om return method; }