org.eclipse.jetty.client.HttpRequest Java Examples
The following examples show how to use
org.eclipse.jetty.client.HttpRequest.
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: SyncHttpRequestSendInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { HttpRequest request = (HttpRequest) objInst; ContextCarrier contextCarrier = new ContextCarrier(); AbstractSpan span = ContextManager.createExitSpan(request.getURI() .getPath(), contextCarrier, request.getHost() + ":" + request .getPort()); span.setComponent(ComponentsDefine.JETTY_CLIENT); Tags.HTTP.METHOD.set(span, getHttpMethod(request)); Tags.URL.set(span, request.getURI().toString()); SpanLayer.asHttp(span); CarrierItem next = contextCarrier.items(); HttpFields field = request.getHeaders(); while (next.hasNext()) { next = next.next(); field.add(next.getHeadKey(), next.getHeadValue()); } }
Example #2
Source File: SyncHttpRequestSendInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { HttpRequest request = (HttpRequest) objInst; ContextCarrier contextCarrier = new ContextCarrier(); AbstractSpan span = ContextManager.createExitSpan(request.getURI() .getPath(), contextCarrier, request.getHost() + ":" + request .getPort()); span.setComponent(ComponentsDefine.JETTY_CLIENT); Tags.HTTP.METHOD.set(span, getHttpMethod(request)); Tags.URL.set(span, request.getURI().toString()); SpanLayer.asHttp(span); CarrierItem next = contextCarrier.items(); HttpFields field = request.getHeaders(); while (next.hasNext()) { next = next.next(); field.add(next.getHeadKey(), next.getHeadValue()); } }
Example #3
Source File: AdminProxyHandler.java From pulsar with Apache License 2.0 | 5 votes |
/** * Ensure the Authorization header is carried over after a 307 redirect * from brokers. */ @Override protected Request copyRequest(HttpRequest oldRequest, URI newURI) { String authorization = oldRequest.getHeaders().get(HttpHeader.AUTHORIZATION); Request newRequest = super.copyRequest(oldRequest, newURI); if (authorization != null) { newRequest.header(HttpHeader.AUTHORIZATION, authorization); } return newRequest; }
Example #4
Source File: SyncHttpRequestSendInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
public String getHttpMethod(HttpRequest request) { String method = request.getMethod(); if (method == null || method.length() == 0) { method = "GET"; } return method; }
Example #5
Source File: SyncHttpRequestSendInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
public String getHttpMethod(HttpRequest request) { HttpMethod httpMethod = HttpMethod.GET; /** * The method is null if the client using GET method. * * @see org.eclipse.jetty.client.HttpRequest#GET(String uri) * @see org.eclipse.jetty.client.HttpRequest( org.eclipse.jetty.client.HttpClient client, long conversation, java.net.URI uri) */ if (request.getMethod() != null) { httpMethod = request.getMethod(); } return httpMethod.name(); }
Example #6
Source File: ReverseProxyServlet.java From logbook-kai with MIT License | 5 votes |
/** * <p> * ライブラリのバグを修正します<br> * URLにマルチバイト文字が含まれている場合にURLが正しく組み立てられないバグを修正します * </p> */ private static void fixQueryString(Request proxyRequest, String queryString) { if (queryString != null && !queryString.isEmpty()) { if (proxyRequest instanceof HttpRequest) { try { FieldHolder.QUERY_FIELD.set(proxyRequest, queryString); } catch (IllegalArgumentException | IllegalAccessException e) { throw new RuntimeException(e); } } } }
Example #7
Source File: HelloWorldClient.java From opencensus-java with Apache License 2.0 | 4 votes |
/** * HelloWorldClient sends http request periodically to {@link HelloWorldServer}. These requests * are instrumented using opencensus jetty client library to enable tracing and monitoring stats. */ public static void main(String[] args) throws Exception { BasicConfigurator.configure(); initTracing(); initStatsExporter(); // Create http client that will trace requests. By default trace context is propagated using // w3c TraceContext propagator. // To use B3 propagation use following // OcJettyHttpClient httpClient = // new OcJettyHttpClient( // new HttpClientTransportOverHTTP(), // new SslContextFactory(), // null, // Tracing.getPropagationComponent().getB3Format()); OcJettyHttpClient httpClient = new OcJettyHttpClient( new HttpClientTransportOverHTTP(), new SslContextFactory(), null, null); httpClient.start(); do { HttpRequest request = (HttpRequest) httpClient .newRequest("http://localhost:8080/helloworld/request") .method(HttpMethod.GET); HttpRequest asyncRequest = (HttpRequest) httpClient .newRequest("http://localhost:8080/helloworld/request/async") .method(HttpMethod.GET); HttpRequest postRequest = (HttpRequest) httpClient .newRequest("http://localhost:8080/helloworld/request") .method(HttpMethod.POST); postRequest.content(new StringContentProvider("{\"hello\": \"world\"}"), "application/json"); if (request == null) { logger.info("Request is null"); break; } request.send(); asyncRequest.send(); postRequest.send(); try { Thread.sleep(15000); } catch (Exception e) { logger.error("Error while sleeping"); } } while (true); }
Example #8
Source File: MockRemoteRepository.java From database with GNU General Public License v2.0 | 4 votes |
public static MockRemoteRepository create(final String tupleQueryResponse, final String graphQueryResponse) { // pojo to retrieve values from mock service final Data data = new Data(); String serviceURL = "http://localhost"; HttpClient httpClient = new HttpClient() { @Override protected void send(HttpRequest request, List<ResponseListener> listeners) { // Store HTTP request data.request = request; data.listeners = listeners; for (ResponseListener listener: listeners) { if (listener instanceof JettyResponseListener) { HttpResponse response = new HttpResponse(request, null){ @Override public int getStatus() { return 200; }; }; String requestMimeType = request.getHeaders().get(HttpHeader.ACCEPT).split(";")[0]; TupleQueryResultFormat tupleQueryMimeType = TupleQueryResultFormat.forMIMEType(requestMimeType); String responseMimeType; String responseContent; if (tupleQueryMimeType!=null) { responseMimeType = TupleQueryResultFormat.TSV.getDefaultMIMEType(); responseContent = tupleQueryResponse; } else { responseMimeType = RDFFormat.NTRIPLES.getDefaultMIMEType(); responseContent = graphQueryResponse; } response.getHeaders().add(HttpHeader.CONTENT_TYPE, responseMimeType); ((JettyResponseListener)listener).onHeaders(response); java.nio.ByteBuffer buf = java.nio.ByteBuffer.allocate(responseContent.length()); buf.put(responseContent.getBytes(Charset.forName(StandardCharsets.UTF_8.name()))); buf.flip(); ((JettyResponseListener)listener).onContent(response, buf, Callback.NOOP); ((JettyResponseListener)listener).onSuccess(response); ((JettyResponseListener)listener).onComplete(new Result(request, response)); } } } @Override public boolean isStopped() { return false; } }; Executor executor = Executors.newCachedThreadPool(); RemoteRepositoryManager mgr = new RemoteRepositoryManager(serviceURL, httpClient, executor) { @Override public JettyResponseListener doConnect(ConnectOptions opts) throws Exception { // Store connection options data.opts = opts; return super.doConnect(opts); } }; return new MockRemoteRepository(mgr, serviceURL, null, data); }