/** * Default constructor that creates a new instance of {@link HttpClient}. */ public JettyClientHttpConnector() { this(new HttpClient()); }
@Override public boolean isRunning() { return this.httpClient.isRunning(); }
protected ResponseEntity<String> executeRequest(URI url, HttpMethod method, HttpHeaders headers, @Nullable String body) { Request httpRequest = this.httpClient.newRequest(url).method(method); addHttpHeaders(httpRequest, headers); if (body != null) { httpRequest.content(new StringContentProvider(body)); } ContentResponse response; try { response = httpRequest.send(); } catch (Exception ex) { throw new SockJsTransportFailureException("Failed to execute request to " + url, ex); } HttpStatus status = HttpStatus.valueOf(response.getStatus()); HttpHeaders responseHeaders = toHttpHeaders(response.getHeaders()); return (response.getContent() != null ? new ResponseEntity<>(response.getContentAsString(), responseHeaders, status) : new ResponseEntity<>(responseHeaders, status)); }
public Iterable<String> call(Iterator<String> input) { ArrayList<String> content = new ArrayList<String>(); ArrayList<ContentExchange> cea = new ArrayList<ContentExchange>(); HttpClient client = new HttpClient(); try { client.start(); while (input.hasNext()) { ContentExchange exchange = new ContentExchange(true); exchange.setURL("http://qrzcq.com/call/" + input.next()); client.send(exchange); cea.add(exchange); } for (ContentExchange exchange : cea) { exchange.waitForDone(); content.add(exchange.getResponseContent()); } } catch (Exception e) { } return content; }}); System.out.println(StringUtils.join(result.collect(), ","));
private void executeReceiveRequest(URI url, HttpHeaders headers, SockJsResponseListener listener) { if (logger.isTraceEnabled()) { logger.trace("Starting XHR receive request, url=" + url); } Request httpRequest = this.httpClient.newRequest(url).method(HttpMethod.POST); addHttpHeaders(httpRequest, headers); httpRequest.send(listener); }
private Request translateRequest(final ClientRequest clientRequest) { final URI uri = clientRequest.getUri(); final Request request = client.newRequest(uri); request.method(clientRequest.getMethod()); request.followRedirects(clientRequest.resolveProperty(ClientProperties.FOLLOW_REDIRECTS, true)); final Object readTimeout = clientRequest.getConfiguration().getProperties().get(ClientProperties.READ_TIMEOUT); if (readTimeout != null && readTimeout instanceof Integer && (Integer) readTimeout > 0) { request.timeout((Integer) readTimeout, TimeUnit.MILLISECONDS); } return request; }
/** * Constructor with an {@link JettyResourceFactory} that will manage shared resources. * @param resourceFactory the {@link JettyResourceFactory} to use * @param customizer the lambda used to customize the {@link HttpClient} */ public JettyClientHttpConnector( JettyResourceFactory resourceFactory, @Nullable Consumer<HttpClient> customizer) { HttpClient httpClient = new HttpClient(); httpClient.setExecutor(resourceFactory.getExecutor()); httpClient.setByteBufferPool(resourceFactory.getByteBufferPool()); httpClient.setScheduler(resourceFactory.getScheduler()); if (customizer != null) { customizer.accept(httpClient); } this.httpClient = httpClient; }
@Override public void stop() { try { httpClient.stop(); } catch (Exception e) { throw Throwables.propagate(e); } } }
public CodeServlet(String mainClass, String[] classPath) { this.mainClass = mainClass; this.classPath = classPath.clone(); httpClient = new HttpClient(); httpClient.setFollowRedirects(false); }
@Override public void init() throws ServletException { super.init(); // Note that httpClientProvider is setup to return same HttpClient instance on each get() so // it is same http client as that is used by parent ProxyServlet. broadcastClient = newHttpClient(); try { broadcastClient.start(); } catch (Exception e) { throw new ServletException(e); } }
static Tuple2<String, ContentExchange> createRequestForSign(String sign, HttpClient client) throws Exception { ContentExchange exchange = new ContentExchange(true); exchange.setURL("http://new73s.herokuapp.com/qsos/" + sign + ".json"); client.send(exchange); return new Tuple2(sign, exchange); } static ObjectMapper createMapper() {
static CallLog[] readExchangeCallLog(ObjectMapper mapper, ContentExchange exchange) { try { exchange.waitForDone(); String responseJson = exchange.getResponseContent(); return mapper.readValue(responseJson, CallLog[].class); } catch (Exception e) { return new CallLog[0]; } }
/** * Constructor with an {@link JettyResourceFactory} that will manage shared resources. * @param resourceFactory the {@link JettyResourceFactory} to use * @param customizer the lambda used to customize the {@link HttpClient} */ public JettyClientHttpConnector( JettyResourceFactory resourceFactory, @Nullable Consumer<HttpClient> customizer) { HttpClient httpClient = new HttpClient(); httpClient.setExecutor(resourceFactory.getExecutor()); httpClient.setByteBufferPool(resourceFactory.getByteBufferPool()); httpClient.setScheduler(resourceFactory.getScheduler()); if (customizer != null) { customizer.accept(httpClient); } this.httpClient = httpClient; }
/** * Default constructor that creates a new instance of {@link HttpClient}. */ public JettyClientHttpConnector() { this(new HttpClient()); }
@Override public void stop() { try { client.stop(); } catch (Exception ex) { log.info("Error stopping HTTP client: " + ex); } }
@Override protected AbstractXhrTransport createXhrTransport() { return new JettyXhrTransport(new HttpClient()); }
@Override public void close() { try { client.stop(); } catch (final Exception e) { throw new ProcessingException("Failed to stop the client.", e); } } }
@Override public void destroy() { super.destroy(); try { broadcastClient.stop(); } catch (Exception e) { log.warn(e, "Error stopping servlet"); } }