org.apache.hc.core5.http.HttpException Java Examples
The following examples show how to use
org.apache.hc.core5.http.HttpException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpLoaderServer.java From mts with GNU General Public License v3.0 | 6 votes |
public void receiveResponse(String method, String uri, int numberRequest)throws HttpException, IOException { HttpResponse response; try { for(int i=0; i < numberRequest; i++) { BasicHttpRequest br = new BasicHttpRequest(method, uri+i); //response=myclass.doReceiveResponse(br,Clientconn,context); //System.out.println(EntityUtils.toString(response.getEntity())); // response.getEntity().consumeContent(); //System.out.println(response.getStatusLine()); } } catch(Exception e) {} }
Example #2
Source File: HijackingHttpRequestExecutor.java From docker-java with Apache License 2.0 | 6 votes |
@Override public ClassicHttpResponse execute( ClassicHttpRequest request, HttpClientConnection conn, HttpResponseInformationCallback informationCallback, HttpContext context ) throws IOException, HttpException { Objects.requireNonNull(request, "HTTP request"); Objects.requireNonNull(conn, "Client connection"); Objects.requireNonNull(context, "HTTP context"); InputStream hijackedInput = (InputStream) context.getAttribute(HIJACKED_INPUT_ATTRIBUTE); if (hijackedInput != null) { return executeHijacked(request, conn, context, hijackedInput); } return super.execute(request, conn, informationCallback, context); }
Example #3
Source File: ListenpointHttp2.java From mts with GNU General Public License v3.0 | 5 votes |
@Override public void handle( final Message<HttpRequest, byte[]> requestMessage, final ResponseTrigger responseTrigger, final HttpContext context ) throws HttpException, IOException { try { byte[] body = (byte[]) requestMessage.getBody(); MsgHttp2 msg = new MsgHttp2(stack, requestMessage.getHead()); TransactionId transactionId = new TransactionId(UUID.randomUUID().toString()); Trans transaction = new Trans(stack, msg); msg.setTransaction(transaction); msg.setTransactionId(transactionId); msg.setResponseTrigger(responseTrigger); msg.setContext(context); msg.setListenpoint(listenpoint); if (body != null) { msg.setMessageContent(new String(body)); } stack.receiveMessage(msg); GlobalLogger.instance().getApplicationLogger().debug(TextEvent.Topic.PROTOCOL, "Listenpoint: receiveMessage() ", msg); } catch (Exception e) { GlobalLogger.instance().getApplicationLogger().error(TextEvent.Topic.PROTOCOL, e); throw new IOException(e); } }
Example #4
Source File: HttpLoaderServer.java From mts with GNU General Public License v3.0 | 5 votes |
public void receiveRequest( HttpRequest request, HttpContext context, ClassicHttpResponse response )throws HttpException, IOException { String method = request.getMethod().toUpperCase(); String target = request.getPath(); sendResponse(response,context,request); }
Example #5
Source File: HttpLoaderServer.java From mts with GNU General Public License v3.0 | 5 votes |
public void sendResponse( ClassicHttpResponse response,HttpContext context, HttpRequest request)throws HttpException, IOException { response.setCode(HttpStatus.SC_OK); File file = new File("D:/XMLloader/testPileHttp/test/fileTestHttp.txt"); //FileEntity body = new FileEntity(file, "text/html"); HttpEntity body = new StringEntity(""); response.setEntity(body); }
Example #6
Source File: HttpUtils.java From drftpd with GNU General Public License v2.0 | 5 votes |
public static String retrieveHttpAsString(String url) throws HttpException, IOException { RequestConfig requestConfig = RequestConfig.custom() .setResponseTimeout(5000, TimeUnit.MILLISECONDS) .setConnectTimeout(5000, TimeUnit.MILLISECONDS) .setConnectionRequestTimeout(5000, TimeUnit.MILLISECONDS) .setCookieSpec(StandardCookieSpec.IGNORE) .build(); CloseableHttpClient httpclient = HttpClients.custom() .setDefaultRequestConfig(requestConfig) .setUserAgent(_userAgent) .build(); HttpGet httpGet = new HttpGet(url); httpGet.setConfig(requestConfig); CloseableHttpResponse response = null; try { response = httpclient.execute(httpGet); final int statusCode = response.getCode(); if (statusCode != HttpStatus.SC_OK) { throw new HttpException("Error " + statusCode + " for URL " + url); } HttpEntity entity = response.getEntity(); String data = EntityUtils.toString(entity); EntityUtils.consume(entity); return data; } catch (IOException e) { throw new IOException("Error for URL " + url, e); } finally { if (response != null) { response.close(); } httpclient.close(); } }
Example #7
Source File: HttpUtils.java From drftpd with GNU General Public License v2.0 | 5 votes |
public static String retrieveHttpAsString(String url) throws HttpException, IOException { RequestConfig requestConfig = RequestConfig.custom() .setResponseTimeout(5000, TimeUnit.MILLISECONDS) .setConnectTimeout(5000, TimeUnit.MILLISECONDS) .setConnectionRequestTimeout(5000, TimeUnit.MILLISECONDS) .setCookieSpec(StandardCookieSpec.IGNORE) .build(); CloseableHttpClient httpclient = HttpClients.custom() .setDefaultRequestConfig(requestConfig) .setUserAgent(_userAgent) .build(); HttpGet httpGet = new HttpGet(url); httpGet.setConfig(requestConfig); CloseableHttpResponse response = null; try { response = httpclient.execute(httpGet); final int statusCode = response.getCode(); if (statusCode != HttpStatus.SC_OK) { throw new HttpException("Error " + statusCode + " for URL " + url); } HttpEntity entity = response.getEntity(); String data = EntityUtils.toString(entity); EntityUtils.consume(entity); return data; } catch (IOException e) { throw new IOException("Error for URL " + url, e); } finally { if (response != null) { response.close(); } httpclient.close(); } }
Example #8
Source File: ListenpointHttp2.java From mts with GNU General Public License v3.0 | 4 votes |
@Override public AsyncRequestConsumer<Message<HttpRequest, byte[]>> prepare(final HttpRequest request, final EntityDetails entityDetails, final HttpContext context) throws HttpException { return new BasicRequestConsumer<>(() -> new BasicAsyncEntityConsumer()); }
Example #9
Source File: HttpLoaderServer.java From mts with GNU General Public License v3.0 | 4 votes |
public void handle(final HttpRequest request, final ClassicHttpResponse response, final HttpContext context)throws HttpException, IOException { receiveRequest(request,context,response); }
Example #10
Source File: HttpLoaderServer.java From mts with GNU General Public License v3.0 | 4 votes |
@Override public void handle(ClassicHttpRequest request, ClassicHttpResponse response, HttpContext context) throws HttpException, IOException { receiveRequest(request,context,response); }
Example #11
Source File: HijackingHttpRequestExecutor.java From docker-java with Apache License 2.0 | 4 votes |
private ClassicHttpResponse executeHijacked( ClassicHttpRequest request, HttpClientConnection conn, HttpContext context, InputStream hijackedInput ) throws HttpException, IOException { try { context.setAttribute(HttpCoreContext.SSL_SESSION, conn.getSSLSession()); context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, conn.getEndpointDetails()); final ProtocolVersion transportVersion = request.getVersion(); if (transportVersion != null) { context.setProtocolVersion(transportVersion); } conn.sendRequestHeader(request); conn.sendRequestEntity(request); conn.flush(); ClassicHttpResponse response = conn.receiveResponseHeader(); if (response.getCode() != HttpStatus.SC_SWITCHING_PROTOCOLS) { conn.terminateRequest(request); throw new ProtocolException("Expected 101 Switching Protocols, got: " + new StatusLine(response)); } Thread thread = new Thread(() -> { try { BasicClassicHttpRequest fakeRequest = new BasicClassicHttpRequest("POST", "/"); fakeRequest.setHeader(HttpHeaders.CONTENT_LENGTH, Long.MAX_VALUE); fakeRequest.setEntity(new HijackedEntity(hijackedInput)); conn.sendRequestEntity(fakeRequest); } catch (Exception e) { throw new RuntimeException(e); } }); thread.setName("docker-java-httpclient5-hijacking-stream-" + System.identityHashCode(request)); thread.setDaemon(true); thread.start(); // 101 -> 200 response.setCode(200); conn.receiveResponseEntity(response); return response; } catch (final HttpException | IOException | RuntimeException ex) { Closer.closeQuietly(conn); throw ex; } }