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() {
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(), ","));
public void setURL(String url) { ce.setURL(url); }
public ContentExchange sendRequest(String url, ContentExchange httpRequest) { httpRequest.setURL(url); try { httpClient.send(httpRequest); } catch (IOException e) { LOG.error("Issues with httpClient.send: {}", e.toString()); } int ex = HttpExchange.STATUS_EXCEPTED; // Waits until the exchange is terminated try { ex = httpRequest.waitForDone(); } catch (InterruptedException e) { LOG.error("Issues with waitForDone: {}", e.toString()); } return httpRequest; }
public ContentExchange sendRequest(String url, OdlOnem2mHttpRequestPrimitive onem2mRequest) { onem2mRequest.httpRequest.setURL(url + onem2mRequest.to + "?" + onem2mRequest.uriQueryString); try { httpClient.send(onem2mRequest.httpRequest); } catch (IOException e) { LOG.error("Issues with httpClient.send: {}", e.toString()); } int ex = HttpExchange.STATUS_EXCEPTED; // Waits until the exchange is terminated try { ex = onem2mRequest.httpRequest.waitForDone(); } catch (InterruptedException e) { LOG.error("Issues with waitForDone: {}", e.toString()); } return onem2mRequest.httpRequest; } }
@Override public Future<Document> execute() throws IOException { final SettableFuture<Document> future = SettableFuture.create(); ContentExchange exchange = new ContentExchange() { protected void onResponseComplete() throws IOException { super.onResponseComplete(); String responseContent = this.getResponseContent(); try { future.set(db.parse(new InputSource(responseContent))); } catch (SAXException e) { future.setException(e); } } }; exchange.setRequestHeader("Accept", "text/xml, application/xml"); exchange.setMethod("GET"); exchange.setURL(url.toExternalForm()); // start the exchange client.send(exchange); return future; } }
/** * HTTP notifications will be set out to subscribers interested in resources from the tree where they have have hung * onem2m subscription resources * @param url where do i send this onem2m notify message * @param payload contents of the notification */ @Override public void sendNotification(String url, String payload) { ContentExchange ex = new ContentExchange(); ex.setURL(url); ex.setRequestContentSource(new ByteArrayInputStream(payload.getBytes())); ex.setRequestContentType(Onem2m.ContentType.APP_VND_NTFY_JSON); Integer cl = payload != null ? payload.length() : 0; ex.setRequestHeader("Content-Length", cl.toString()); ex.setMethod("post"); LOG.debug("HTTP: Send notification uri: {}, payload: {}:", url, payload); try { client.send(ex); } catch (IOException e) { LOG.error("Dropping notification: uri: {}, payload: {}", url, payload); } }
exchange.setURL(url.toString());
exchange.setURL(url);