org.apache.hc.core5.http.ClassicHttpRequest Java Examples
The following examples show how to use
org.apache.hc.core5.http.ClassicHttpRequest.
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: HttpClient.java From webdrivermanager with Apache License 2.0 | 6 votes |
public CloseableHttpResponse execute(ClassicHttpRequest method) throws IOException { CloseableHttpResponse response = closeableHttpClient.execute(method); int responseCode = response.getCode(); if (responseCode >= SC_BAD_REQUEST) { String errorMessage; String methodUri = ""; try { methodUri = method.getUri().toString(); } catch (Exception e) { log.trace("Exception reading URI from method: {}", e.getMessage()); } errorMessage = "Error HTTP " + responseCode + " executing " + methodUri; log.error(errorMessage); throw new WebDriverManagerException(errorMessage); } return response; }
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: SocketClientHttp.java From mts with GNU General Public License v3.0 | 5 votes |
public void sendMessage(MsgHttp msg) throws Exception { this.requestsSent.offer(msg); try { ClassicHttpRequest classicHttpRequest = (ClassicHttpRequest) msg.getMessage(); clientConnection.sendRequestHeader(classicHttpRequest); String method = classicHttpRequest.getMethod().toLowerCase(); if (!method.equals("get") && !method.equals("head")){ clientConnection.sendRequestEntity(classicHttpRequest); if (classicHttpRequest.getEntity() == null) { clientConnection.flush(); } } else { clientConnection.flush(); } } catch(Exception e) { GlobalLogger.instance().getApplicationLogger().warn(TextEvent.Topic.PROTOCOL, e, "Error while sending message"); synchronized(this.connHttp) { this.restoreConnection(); } } }
Example #4
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 #5
Source File: NIOSocketServerHttp.java From mts with GNU General Public License v3.0 | 4 votes |
@Override public boolean handle(HybridSocket hybridSocket) { if(false == init) return true; try { GlobalLogger.instance().getApplicationLogger().debug(TextEvent.Topic.PROTOCOL, "ServerSocketHttp waiting for header"); ClassicHttpRequest request = defaultHttpServerConnection.receiveRequestHeader(); String method = request.getMethod().toLowerCase(); if(!method.equals("get") && !method.equals("head")) { GlobalLogger.instance().getApplicationLogger().debug(TextEvent.Topic.PROTOCOL, "ServerSocketHttp receiving entity"); defaultHttpServerConnection.receiveRequestEntity((ClassicHttpRequest)request); } Stack stack = StackFactory.getStack(StackFactory.PROTOCOL_HTTP); MsgHttp msgRequest = new MsgHttp(stack, request); // // Set the channel attached to the msg // msgRequest.setChannel(this.connHttp); synchronized(messagesReceived) { messagesReceived.addLast(msgRequest); } // // Call back to the generic stack // stack.receiveMessage(msgRequest); } catch(Exception e) { if(messagesReceived.isEmpty()) { GlobalLogger.instance().getApplicationLogger().warn(TextEvent.Topic.PROTOCOL, e, "Exception in ServerSocketHttp without pending messages"); } else { GlobalLogger.instance().getApplicationLogger().error(TextEvent.Topic.PROTOCOL, e, "Exception in ServerSocketHttp with pending messages"); } // // try to close itself // try { synchronized (this) { StackFactory.getStack(StackFactory.PROTOCOL_HTTP).closeChannel(this.connHttp.getName()); } } catch(Exception ee) { GlobalLogger.instance().getApplicationLogger().error(TextEvent.Topic.PROTOCOL, ee, "Error while closing connection ", this.connHttp); } GlobalLogger.instance().getApplicationLogger().info(TextEvent.Topic.PROTOCOL, "ServerSocketHttp ended"); } return _continue; }
Example #6
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; } }