// Have one (or more) threads ready to do the async tasks. Do this during startup of your app. ExecutorService executor = Executors.newFixedThreadPool(1); // Fire a request. Future<Response> response = executor.submit(new Request(new URL("http://google.com"))); // Do your other tasks here (will be processed immediately, current thread won't block). // ... // Get the response (here the current thread will block until response is returned). InputStream body = response.get().getBody(); // ... // Shutdown the threads during shutdown of your app. executor.shutdown();
public static void invokeAdminService(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { jettyServerHandler.handle(null, new Request(null, null), request, response); }
// could be any class that implements Map Map<String, String> mHeaders = new ArrayMap<String, String>(); mHeaders.put("user", USER); mHeaders.put("pass", PASSWORD); Request req = new Request(url, postBody, listener, errorListener) { public Map<String, String> getHeaders() { return mHeaders; } }
private static Request newRequest() { HttpChannel channel = mock( HttpChannel.class ); Response response = new Response( channel, mock( HttpOutput.class ) ); Request request = new Request( channel, mock( HttpInput.class ) ); when( channel.getRequest() ).thenReturn( request ); when( channel.getResponse() ).thenReturn( response ); return request; }
public void callWebService() { SampleService srv1 = new SampleService(); Request req = new Request(); req.companyId = "1"; req.userName = "userName"; req.password = "pas"; Response response = srv1.ServiceSample(req); }
var foo = new Request({ url: 'http://fragged.org/Epitome/example/data/', method: 'get', onComplete: function (data) { // returns an object with name and surname new Element('div[html="{name} {surname}"]'.substitute(JSON.decode(data))).inject(document.body); } }); // need to remove that or CORS will need to match it specifically delete foo.headers['X-Requested-With']; foo.send();
new Request({ url: 'hanteraTaBortAnvandare.php', method: 'post', data: { 'id': '10' }, onComplete: function(response) { alert(response); } });
var myRequest = new Request({ url: "something.php", evalScripts: true, onSuccess: function(responseText, responseXML){ .... } }); myRequest.send();
public RequestBuilder { // setters and getters for all properties public Request build() { doStuff(); Request request = new Request(this); doAfterStuff(); return request; } }
var request = new Request({ url: 'form.php', method: 'post', data: { userId:1111, test: 'test' }, onSuccess: function(response){ Whatever you want to do} } request.send();
public class Client { public Status get(String request) { return get(new Request(request)); } public Status get(Request request) { // do stuff } }
Map<String, String> mHeaders = new ArrayMap<String, String>(); mHeaders.put("StringType", Stringg); mHeaders.put("IntType", integerr); Request req = new Request(url, postBody, listener, errorListener) { public Map<String, String> getHeaders() { return mHeaders; } }
public void callWebService(){ SampleService srv1 = new SampleService(); Request req = new Request(); req.companyId = "1"; req.userName = "userName"; req.password = "pas"; Response response = srv1.ServiceSample(req); }
SampleService srv1 = new SampleService(); req = new Request(); req.companyId = "1"; req.userName = "userName"; req.password = "pas"; Response response = srv1.ServiceSample(req);
Client client = new Client(Protocol.HTTP); Request r = new Request(); r.setResourceRef("http://127.0.0.1:8182/sample"); r.setMethod(Method.GET); r.getClientInfo().getAcceptedMediaTypes().add(new Preference<MediaType>(MediaType.TEXT_XML)); client.handle(r).getEntity().write(System.out);
public HttpChannel(Connector connector, HttpConfiguration configuration, EndPoint endPoint, HttpTransport transport, HttpInput<T> input) { _connector = connector; _configuration = configuration; _endPoint = endPoint; _transport = transport; _uri = new HttpURI(URIUtil.__CHARSET); _state = new HttpChannelState(this); _request = new Request(this, input); _response = new Response(this, new HttpOutput(this)); }