List of usage examples for org.apache.http.client.methods HttpRequestBase getRequestLine
public RequestLine getRequestLine()
From source file:com.sap.core.odata.testutil.tool.core.SupaController.java
private String call(final String supaCommand) { HttpRequestBase request = null; try {/* www .ja v a2s.c o m*/ request = new HttpGet(baseUri + supaCommand); LOG.debug("Call for request line '{}'", request.getRequestLine()); final HttpHost targetHost = new HttpHost(baseUri.getHost(), baseUri.getPort()); final HttpResponse response = httpClient.execute(targetHost, request); // return extractSupaInformation(response.getEntity()); } catch (final IOException e) { LOG.debug("Got exception for calling supa command '" + supaCommand + "'."); return "Exception"; } finally { if (request != null) { request.releaseConnection(); } } }
From source file:com.sap.core.odata.testutil.tool.core.AbstractTestClient.java
private void call(final URI baseUri, final TestRequest testPath) { HttpRequestBase request = null; try {/*w ww . j a v a 2 s . com*/ request = createRequest(baseUri, testPath); testPath.applyHeaders(request); LOG.debug("Call for request line '{}'", request.getRequestLine()); final HttpHost targetHost = new HttpHost(baseUri.getHost(), baseUri.getPort()); final HttpResponse response = httpClient.execute(targetHost, request); // handleSuccessCall(baseUri, testPath, request, response); } catch (Exception e) { handleFailureCall(testPath, request, e); } finally { if (request != null) { request.releaseConnection(); } } }
From source file:com.fanfou.app.opensource.http.SimpleClient.java
private final HttpResponse executeImpl(final HttpRequestBase request) throws IOException { if (request == null) { throw new IOException("http request is null"); }// w ww . j a v a 2 s . co m final HttpClient client = getHttpClient(); if (AppContext.DEBUG) { Log.d(SimpleClient.TAG, "[Request] " + request.getRequestLine().toString()); } final HttpResponse response = client.execute(request); if (AppContext.DEBUG) { Log.d(SimpleClient.TAG, "[Response] " + response.getStatusLine().toString()); } return response; }
From source file:org.couch4j.http.HttpConnectionManager.java
private ServerResponse executeMethod(HttpRequestBase method) { if (logger.isDebugEnabled()) { logger.debug("REQUEST: " + method.getRequestLine()); }/*from www .j a v a2 s . c o m*/ try { HttpResponse response = client.execute(method); int statusCode = response.getStatusLine().getStatusCode(); // Read the response body. HttpEntity entity = response.getEntity(); JSONObject jsonObject = fromResponseStream(entity); switch (statusCode) { case HttpStatus.SC_NOT_FOUND: throw new DocumentNotFoundException(jsonObject); case HttpStatus.SC_CONFLICT: throw new DocumentUpdateConflictException(jsonObject); case HttpStatus.SC_OK: case HttpStatus.SC_CREATED: break; default: throw new Couch4JException(jsonObject); } return JsonServerResponse.fromJson(jsonObject); } catch (IOException e) { throw new Couch4JException(e); } }
From source file:com.k42b3.zubat.TrafficTableModel.java
public Object getValueAt(int rowIndex, int columnIndex) { if (rowIndex >= 0 && rowIndex < rows.size()) { HttpRequestBase request = rows.get(rowIndex).getRequest(); HttpResponse response = rows.get(rowIndex).getResponse(); switch (columnIndex) { case 0:/*from w w w.ja va2 s . c o m*/ return request.getMethod(); case 1: return response.getStatusLine(); case 2: return request.getRequestLine().getUri(); } } return null; }
From source file:org.scigap.iucig.controller.ScienceDisciplineController.java
@ResponseBody @RequestMapping(value = "/getUsersScienceDiscipline", method = RequestMethod.GET) public String getUsersScienceDiscipline(@RequestParam(value = "selectedCluster") String cluster, HttpServletRequest request) throws Exception { String responseJSON = null;/* w w w . j a v a 2s .com*/ String remoteUser; if (request != null) { remoteUser = request.getRemoteUser(); } else { throw new Exception("Remote user is null"); } DefaultHttpClient httpClient = new DefaultHttpClient(); String url = SCIENCE_DISCIPLINE_URL + "user/" + remoteUser + "?format=json&fields=disciplines&cluster=" + cluster; System.out.println(url); HttpRequestBase disciplines = new HttpGet(url); logger.debug("Executing REST GET request" + disciplines.getRequestLine()); try { httpClient = (DefaultHttpClient) WebClientDevWrapper.wrapClient(httpClient); HttpResponse response = httpClient.execute(disciplines); HttpEntity entity = response.getEntity(); if (entity != null && response.getStatusLine().getStatusCode() == HttpStatus.OK.value()) { responseJSON = convertStreamToString(entity.getContent()); } EntityUtils.consume(entity); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return responseJSON; }
From source file:org.scigap.iucig.controller.ScienceDisciplineController.java
@ResponseBody @RequestMapping(value = "/getScienceDiscipline", method = RequestMethod.GET) public String getScienceDiscipline(@RequestParam(value = "selectedCluster") String cluster) { String responseJSON = null;/*from w w w . j a va 2 s . c om*/ DefaultHttpClient httpClient = new DefaultHttpClient(); HttpRequestBase disciplines = new HttpGet( SCIENCE_DISCIPLINE_URL + "discipline/?format=json&cluster=" + cluster); logger.debug("Executing REST GET request" + disciplines.getRequestLine()); try { httpClient = (DefaultHttpClient) WebClientDevWrapper.wrapClient(httpClient); HttpResponse response = httpClient.execute(disciplines); HttpEntity entity = response.getEntity(); if (entity != null && response.getStatusLine().getStatusCode() == HttpStatus.OK.value()) { responseJSON = convertStreamToString(entity.getContent()); } EntityUtils.consume(entity); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return responseJSON; }
From source file:com.woonoz.proxy.servlet.HttpRequestHandler.java
private void performHttpRequest(HttpRequestBase requestToServer, HttpServletResponse responseToClient, ServerHeadersHandler serverHeadersHandler) throws IOException, URISyntaxException { HttpContext context = new BasicHttpContext(); context.setAttribute(HttpRequestHandler.class.getName(), this); HttpResponse responseFromServer = client.execute(requestToServer, context); logger.debug("Performed request: {} --> {}", requestToServer.getRequestLine(), responseFromServer.getStatusLine()); responseToClient.setStatus(responseFromServer.getStatusLine().getStatusCode()); copyHeaders(responseFromServer, responseToClient, serverHeadersHandler); HttpEntity entity = responseFromServer.getEntity(); if (entity != null) { try {/* w ww.ja v a 2 s. c o m*/ entity.writeTo(responseToClient.getOutputStream()); } finally { EntityUtils.consume(entity); } } }
From source file:com.threatconnect.sdk.conn.HttpRequestExecutor.java
/** * Execute an HTTP request and return the raw input stream. <i>Caller is responsible for closing InputStream.</i> * * @param path url to issue request to// ww w . j av a 2 s.co m * @return raw input stream from response * @throws IOException On error */ @Override public InputStream executeDownloadByteStream(String path) throws IOException { if (this.conn.getConfig() == null) { throw new IllegalStateException("Can't execute HTTP request when configuration is undefined."); } InputStream stream = null; String fullPath = this.conn.getConfig().getTcApiUrl() + path.replace("/api/", "/"); logger.trace("Calling GET: " + fullPath); HttpRequestBase httpBase = getBase(fullPath, HttpMethod.GET); String headerPath = httpBase.getURI().getRawPath() + "?" + httpBase.getURI().getRawQuery(); ConnectionUtil.applyHeaders(this.conn.getConfig(), httpBase, httpBase.getMethod(), headerPath, conn.getConfig().getContentType(), ContentType.APPLICATION_OCTET_STREAM.toString()); logger.trace("Request: " + httpBase.getRequestLine()); logger.trace("Headers: " + Arrays.toString(httpBase.getAllHeaders())); CloseableHttpResponse response = this.conn.getApiClient().execute(httpBase); logger.trace(response.getStatusLine().toString()); HttpEntity entity = response.getEntity(); if (entity != null) { stream = entity.getContent(); logger.trace(String.format("Result stream size: %d, encoding: %s", entity.getContentLength(), entity.getContentEncoding())); } return stream; }
From source file:com.woonoz.proxy.servlet.HttpRequestHandler.java
public void execute() { UrlRewriter urlRewriter = new UrlRewriterImpl(request, targetServer); ClientHeadersHandler clientHeadersHandler = createClientHeadersHandler(urlRewriter); ServerHeadersHandler serverHeadersHandler = new ServerHeadersHandler(urlRewriter); HttpRequestBase httpCommand = null; try {/*ww w. j a va 2 s.co m*/ logger.debug("Doing rewrite for uri: {}", request.getRequestURL()); final URI targetUri = urlRewriter.rewriteUri(new URI(request.getRequestURL().toString())); logger.debug("Making request for rewritten uri: {}", targetUri); httpCommand = createHttpCommand(targetUri, clientHeadersHandler); logger.debug("Http client command: {}, headers: {}", httpCommand.getRequestLine(), Arrays.asList(httpCommand.getAllHeaders())); performHttpRequest(httpCommand, response, serverHeadersHandler); } catch (URISyntaxException e) { handleException(httpCommand, e); } catch (IOException e) { handleException(httpCommand, e); } catch (InvalidCookieException e) { handleException(httpCommand, e); } catch (FileUploadException e) { handleException(httpCommand, e); } catch (RuntimeException e) { handleException(httpCommand, e); } finally { try { response.getOutputStream().flush(); } catch (IOException e) { logger.error("Exception flushing OutputStream ", e); } } }