Java Code Examples for com.google.gwt.http.client.RequestCallback

The following are top voted examples for showing how to use com.google.gwt.http.client.RequestCallback. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: empiria.player   File: SynchronousScriptsLoaderTest.java   Source Code and License 6 votes vote down vote up
@Test
public void shouldFireOnLoad_afterLastScriptLoaded() {
    // given
    ScriptUrl[] scripts = new ScriptUrl[]{firstScript, secondScript};
    Request request = mock(Request.class);
    Response response = mock(Response.class);
    when(response.getText()).thenReturn(RESPONSE_TEXT);

    // when
    testObj.injectScripts(scripts, synchronousScriptsCallback);
    verify(requestWrapper).get(eq(FIRST_SCRIPT_URL), requestCallbackCaptor.capture());
    RequestCallback requestCallback = requestCallbackCaptor.getValue();
    requestCallback.onResponseReceived(request, response);

    // then
    verify(scriptInjectorWrapper).fromString(RESPONSE_TEXT);

    verify(requestWrapper).get(SECOND_SCRIPT_URL, requestCallback);
    requestCallback.onResponseReceived(request, response);
    verify(synchronousScriptsCallback).onLoad();
}
 
Example 2
Project: onecmdb   File: MDRStartWidget.java   Source Code and License 6 votes vote down vote up
public void doStop() {
 for (TabItem item : advanced.getItems()) {
	 final CIModel model = (CIModel)item.getData("model");

	 // Do a HTTP request..
	 RequestBuilder req = new RequestBuilder(RequestBuilder.GET, getStopURL(model));

	 try {
		 Info.display("Stop", "Send stop to " + model.getDisplayName());
		 req.sendRequest(null, new RequestCallback() {

			 public void onResponseReceived(Request request, Response response) {
				 Info.display("Stop", "COMPLETED. Stop sent to " + model.getDisplayName());
			 }

			 public void onError(Request arg0, Throwable arg1) {
				 Info.display("Stop", "FAILED. to stop " + model.getDisplayName());
			 }
		 });

	 } catch (RequestException e) {
		 Info.display("Stop", "ERROR. to stop " + model.getDisplayName());
	 } 
 }
}
 
Example 3
Project: firefly   File: RequestBuilderServerTask.java   Source Code and License 6 votes vote down vote up
void start(RequestCallback callback) {
//        taskRunningCnt++;
//        showDebugTask();
//        runningList.add(this);
        if (_state!= State.START) {
            throw new IllegalStateException("Server task must be in the START state to call start(). "+
                                            "Current state: "+ _state+
                                            " You can return to the start state using reset()");
        }
        _state= State.WORKING;
        if(isAutoMask) {
            mask();
        }
        _activeCallback= callback;
        try {
//            startTime= System.currentTimeMillis();
            doTask(callback);
        } catch (RequestException e) {
            doFailure(e);
        }
    }
 
Example 4
Project: firefly   File: HtmlRegionLoader.java   Source Code and License 6 votes vote down vote up
public void load(String url, final String regionName) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    try {
        builder.sendRequest(null, new RequestCallback(){
            public void onResponseReceived(com.google.gwt.http.client.Request req, Response res) {
                updateHtml(res.getText(), regionName);
            }

            public void onError(com.google.gwt.http.client.Request request, Throwable exception) {
            }
        });
    } catch (RequestException e) {
        e.printStackTrace();
    }

}
 
Example 5
Project: turbogwt-http   File: RequestImpl.java   Source Code and License 6 votes vote down vote up
private void dispatch(RequestBuilder.Method method, RequestCallback callback) {
    ensureHeaders();

    // Execute filters on this request
    final List<RequestFilter> filters = filterManager.getRequestFilters();
    for (RequestFilter filter : filters) {
        filter.filter(this);
    }

    String body = serializePayload();

    ServerConnection connection = server.getConnection();

    try {
        connection.sendRequest(timeout, user, password, headers, method, uri, body, callback);
    } catch (final RequestException e) {
        throw new RequestDispatchException("It was not possible to dispatch the request.", e);
    }
}
 
Example 6
Project: turbogwt-http   File: ServerConnectionImpl.java   Source Code and License 6 votes vote down vote up
@Override
public void sendRequest(int timeout, @Nullable String user, @Nullable String password, @Nullable Headers headers,
                        RequestBuilder.Method method, String url, String data, RequestCallback callback)
        throws RequestException {
    final RequestBuilder requestBuilder = new RequestBuilder(method, url);
    if (timeout > 0) requestBuilder.setTimeoutMillis(timeout);
    if (user != null) requestBuilder.setUser(user);
    if (password != null) requestBuilder.setPassword(password);
    if (user != null && password != null) requestBuilder.setIncludeCredentials(true);
    if (headers != null) {
        for (Header header : headers) {
            requestBuilder.setHeader(header.getName(), header.getValue());
        }
    }
    requestBuilder.sendRequest(data, callback);
}
 
Example 7
Project: OneCMDBwithMaven   File: MDRStartWidget.java   Source Code and License 6 votes vote down vote up
public void doStop() {
 for (TabItem item : advanced.getItems()) {
	 final CIModel model = (CIModel)item.getData("model");

	 // Do a HTTP request..
	 RequestBuilder req = new RequestBuilder(RequestBuilder.GET, getStopURL(model));

	 try {
		 Info.display("Stop", "Send stop to " + model.getDisplayName());
		 req.sendRequest(null, new RequestCallback() {

			 public void onResponseReceived(Request request, Response response) {
				 Info.display("Stop", "COMPLETED. Stop sent to " + model.getDisplayName());
			 }

			 public void onError(Request arg0, Throwable arg1) {
				 Info.display("Stop", "FAILED. to stop " + model.getDisplayName());
			 }
		 });

	 } catch (RequestException e) {
		 Info.display("Stop", "ERROR. to stop " + model.getDisplayName());
	 } 
 }
}
 
Example 8
Project: ineform   File: RestDataConnectorComplexTest.java   Source Code and License 6 votes vote down vote up
private void prepareRequestBuilder(
    RequestBuilder requestBuilder,
    String responseText,
    int statusCode) throws Exception {
    final Response response = mock(Response.class);
    when(response.getStatusCode()).thenReturn(statusCode);
    when(response.getText()).thenReturn(responseText);

    when(requestBuilder.sendRequest(anyString(), any(RequestCallback.class)))
        .thenAnswer(new Answer<Request>() {

            @Override
            public Request answer(InvocationOnMock invocation) throws Throwable {
                ((RequestCallback) invocation.getArguments()[1])
                    .onResponseReceived(null, response);
                return null;
            }
        });
}
 
Example 9
Project: ineform   File: RestDataConnectorComplexTest.java   Source Code and License 6 votes vote down vote up
@Test
public void createRequest() throws Exception {
    prepareRequestBuilder(requestBuilder, response.replace("'", "\""), 200);

    restDataConnector.objectCreateOrEditRequested(testKvo, callback);

    ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
    verify(requestBuilder).sendRequest(argument.capture(), any(RequestCallback.class));
    Assert.assertEquals(response, argument.getValue());
    ArgumentCaptor<ObjectManipulationActionResult> omrCapture = ArgumentCaptor
        .forClass(ObjectManipulationActionResult.class);
    verify(callback).onManipulationResult(omrCapture.capture());

    TestUtil.assertEquals(
        testKvo,
        omrCapture.getValue().getObjectsNewState(),
        TestUtil.descriptorStore);

}
 
Example 10
Project: geomajas-project-client-gwt2   File: AbstractWfsServiceTest.java   Source Code and License 6 votes vote down vote up
protected void prepareResponse(String resource) throws Exception {
	capabilitiesXml = IOUtils.toString(this.getClass().getResourceAsStream(resource), "UTF-8");
	DOMParser parser = new DOMParser();
	parser.parse(new InputSource(new StringReader(capabilitiesXml)));
	capabilitiesDoc = w3cToGoogle(parser.getDocument());
	final Response response = mock(Response.class);
	when(response.getStatusCode()).thenReturn(200);
	when(response.getText()).thenReturn(capabilitiesXml);

	when(requestBuilder.sendRequest(anyString(), any(RequestCallback.class))).thenAnswer(new Answer<Request>() {

		@Override
		public Request answer(InvocationOnMock invocation) throws Throwable {
			((RequestCallback) invocation.getArguments()[1]).onResponseReceived(null, response);
			return null;
		}
	});
}
 
Example 11
Project: geomajas-project-client-gwt2   File: AbstractWmsServiceTest.java   Source Code and License 6 votes vote down vote up
protected void prepareResponse(String resource) throws Exception {
	capabilitiesXml = IOUtils.toString(this.getClass().getResourceAsStream(resource), "UTF-8");
	DOMParser parser = new DOMParser();
	parser.parse(new InputSource(new StringReader(capabilitiesXml)));
	capabilitiesDoc = w3cToGoogle(parser.getDocument());
	final Response response = mock(Response.class);
	when(response.getStatusCode()).thenReturn(200);
	when(response.getText()).thenReturn(capabilitiesXml);

	when(requestBuilder.sendRequest(anyString(), any(RequestCallback.class))).thenAnswer(new Answer<Request>() {

		@Override
		public Request answer(InvocationOnMock invocation) throws Throwable {
			((RequestCallback) invocation.getArguments()[1]).onResponseReceived(null, response);
			return null;
		}
	});
}
 
Example 12
Project: empiria.player   File: RequestWrapper.java   Source Code and License 5 votes vote down vote up
public void get(String url, RequestCallback callback) {
    try {
        new RequestBuilder(RequestBuilder.GET, url).sendRequest("", callback);
    } catch (RequestException e) {
        logger.error(e);
    }
}
 
Example 13
Project: empiria.player   File: SynchronousScriptsLoader.java   Source Code and License 5 votes vote down vote up
public void injectScripts(ScriptUrl[] scripts, SynchronousScriptsCallback callback) {
    Stack<ScriptUrl> scriptsStack = new Stack<>();
    Collections.addAll(scriptsStack, scripts);
    Collections.reverse(scriptsStack);

    RequestCallback nextScriptLoaderCallback = createNextScriptLoaderCallback(scriptsStack, callback);

    injectScript(scriptsStack, nextScriptLoaderCallback);
}
 
Example 14
Project: shortyz   File: ShortyzGadget.java   Source Code and License 5 votes vote down vote up
public static native void makePostRequest(String url, String postdata,
    RequestCallback callback) /*-{
var response = function(obj) { 
    @com.totsp.crossword.web.gadget.ShortyzGadget::onSuccessInternal(Lcom/totsp/crossword/web/client/GadgetResponse;Lcom/google/gwt/http/client/RequestCallback;)(obj, callback);
};
var params = {};
params[$wnd.gadgets.io.RequestParameters.HEADERS] = {
"Content-Type": "text/x-gwt-rpc"
};
params[$wnd.gadgets.io.RequestParameters.METHOD] = $wnd.gadgets.io.MethodType.POST; 
params[$wnd.gadgets.io.RequestParameters.POST_DATA]= postdata; 
$wnd.gadgets.io.makeRequest(url, response, params);


}-*/;
 
Example 15
Project: shortyz   File: ShortyzGadget.java   Source Code and License 5 votes vote down vote up
static void onSuccessInternal(final GadgetResponse response,
    RequestCallback callback) {
    try {
        callback.onResponseReceived(null, new FakeResponse(response));
    } catch (Exception e) {
        callback.onError(null, e);
    }
}
 
Example 16
Project: shortyz   File: ShortyzWave.java   Source Code and License 5 votes vote down vote up
public static native void makePostRequest(String url, String postdata,
    RequestCallback callback) /*-{
var response = function(obj) {
@com.totsp.crossword.web.wave.ShortyzWave::onSuccessInternal(Lcom/totsp/crossword/web/client/GadgetResponse;Lcom/google/gwt/http/client/RequestCallback;)(obj, callback);
};
var params = {};
params[$wnd.gadgets.io.RequestParameters.HEADERS] = {
"Content-Type": "text/x-gwt-rpc"
};
params[$wnd.gadgets.io.RequestParameters.METHOD] = $wnd.gadgets.io.MethodType.POST;
params[$wnd.gadgets.io.RequestParameters.POST_DATA]= postdata;
$wnd.gadgets.io.makeRequest(url, response, params);


}-*/;
 
Example 17
Project: shortyz   File: ShortyzWave.java   Source Code and License 5 votes vote down vote up
static void onSuccessInternal(final GadgetResponse response,
    RequestCallback callback) {
    try {
        callback.onResponseReceived(null, new FakeResponse(response));
    } catch (Exception e) {
        callback.onError(null, e);
    }
}
 
Example 18
Project: firefly   File: JsonUtils.java   Source Code and License 5 votes vote down vote up
public static void jsonRequest(String baseUrl,
                               String cmd,
                               List<Param> paramList,
                               RequestCallback cb) throws RequestException {
    String url = makeURL(baseUrl, cmd, paramList, false);
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    builder.setCallback(cb);
    builder.send();
}
 
Example 19
Project: turbogwt-http   File: RequestImpl.java   Source Code and License 5 votes vote down vote up
private <T, C extends Collection> RequestPromise<Collection<T>> send(RequestBuilder.Method method,
                                                                     Class<T> responseType,
                                                                     Class<C> containerType) {
    final DeferredCollectionResult<T> deferred = new DeferredCollectionResult<T>(responseType, containerType,
            serdesManager, containerFactoryManager);

    RequestCallback callback = createRequestCallback(deferred);

    dispatch(method, callback);

    return deferred;
}
 
Example 20
Project: turbogwt-http   File: ServerConnectionMock.java   Source Code and License 5 votes vote down vote up
@Override
public void sendRequest(RequestBuilder.Method method, String url, String data, RequestCallback callback)
        throws RequestException {
    ServerStub.setRequestData(url, new RequestMock(method, url, data));
    uri = url;
    requestCallback = (RequestCallbackWithProgress) callback;
}
 
Example 21
Project: turbogwt-http   File: ServerConnectionMock.java   Source Code and License 5 votes vote down vote up
@Override
public void sendRequest(int timeout, String user, String password, Headers headers, RequestBuilder.Method method,
                        String url, String data, RequestCallback callback) throws RequestException {
    ServerStub.setRequestData(url, new RequestMock(method, url, data, headers));
    uri = url;
    requestCallback = (RequestCallbackWithProgress) callback;
}
 
Example 22
Project: socom   File: AudioInfluenceStrategy.java   Source Code and License 5 votes vote down vote up
@Override
public void updateFreeAnswerOnUploadSuccess(
	final InfluenceFreeAnswerViewInterface<AnswerAudio> answer,
	SimpleEntry<String, String>[] sourceParameter, final JSONValue result) {
	final String filePath = result.isObject().get("file").isString().stringValue();
	
	fileDetectionTimer = new Timer() {

		@Override
		public void run() {
			RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, GWT.getHostPageBaseURL() + getDataPath(filePath));

		    try {
		      builder.sendRequest(null, new RequestCallback() {
		        public void onError(Request request, Throwable exception) {
		          AudioInfluenceStrategy.this.presenter.showError(unkownError);
		        }

		        public void onResponseReceived(Request request, Response response) {
		          if(response.getStatusCode() == 404)
		          {
		        	  AudioInfluenceStrategy.this.presenter.showError(notReadyError);
		          }
		          else
		          {
		        	  fileDetectionTimer.cancel();
		        	  onFreeAnswerFileReady(answer, result);
		          }
		        }
		      });
		    } catch (RequestException e) {
		    	AudioInfluenceStrategy.this.presenter.showError(unkownError);
		    }
		}
	};
	
	fileDetectionTimer.scheduleRepeating(500);
}
 
Example 23
Project: opennmszh   File: DefaultChartService.java   Source Code and License 5 votes vote down vote up
private void sendRequest(String url, RequestCallback callback) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    builder.setHeader("Accept", "application/json");
    
    builder.setUser("ipv6Rest");
    builder.setPassword("ipv6Rest");
    try {
        builder.sendRequest(null, callback);
    } catch (RequestException e) {
        e.printStackTrace();
    }
}
 
Example 24
Project: opennmszh   File: DefaultNodeService.java   Source Code and License 5 votes vote down vote up
public void findSnmpInterfacesMatching(int nodeId, String parameter, String value, RequestCallback callback) {
    String url = BASE_URL + nodeId + "/snmpinterfaces?" + parameter + "=" + value;
    if(!parameter.equals("ifIndex") && !parameter.equals("ifSpeed")) {
        url += "&comparator=contains";
    }
    url += "&limit=0";
    sendRequest(callback, url);
    
}
 
Example 25
Project: opennmszh   File: DefaultNodeService.java   Source Code and License 5 votes vote down vote up
private void sendRequest(RequestCallback callback, String url) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    builder.setHeader("accept", "application/json");
    try {
        builder.sendRequest(null, callback);
    } catch (RequestException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
 
Example 26
Project: opennmszh   File: DefaultKscReportService.java   Source Code and License 5 votes vote down vote up
@Override
public void addGraphToReport(final RequestCallback callback, final int kscReportId, final String graphTitle, final String graphName, final String resourceId, final String timeSpan) {
    UrlBuilder builder = new UrlBuilder();
    builder.setPath(BASE_URL + "/" + kscReportId);
    builder.setParameter("title", graphTitle);
    builder.setParameter("reportName", graphName);
    builder.setParameter("resourceId", resourceId);
    builder.setParameter("timespan", timeSpan);

    // we just want a relative URL, so we render it and strip the beginning :)
    final String url = builder.buildString().replace("http:///", "");
    GWT.log("making request: " + url);
    sendRequest(callback, RequestBuilder.PUT, url);
}
 
Example 27
Project: opennmszh   File: DefaultKscReportService.java   Source Code and License 5 votes vote down vote up
private void sendRequest(final RequestCallback callback, final Method method, final String url) {
    final RequestBuilder builder = new RequestBuilder(method, url);
    builder.setHeader("accept", "application/json");
    try {
        builder.sendRequest(null, callback);
    } catch (final RequestException e) {
        e.printStackTrace();
    }
}
 
Example 28
Project: opennmszh   File: DefaultNodeService.java   Source Code and License 5 votes vote down vote up
private void sendRequest(RequestCallback callback, String url) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    builder.setHeader("accept", "application/json");
    try {
        builder.sendRequest(null, callback);
    } catch (RequestException e) {
        e.printStackTrace();
    }
}
 
Example 29
Project: Peergos   File: ContentWidget.java   Source Code and License 5 votes vote down vote up
/**
 * Send a request for source code.
 * 
 * @param callback the {@link RequestCallback} to send
 * @param urlSuffix the URL to target, relative to the Showcase module's base URL.
 */
private void sendSourceRequest(RequestCallback callback, String urlSuffix) {
  // When Super Dev Mode is on, we will load it from the code server, not the original server.
  String url = GWT.getModuleBaseForStaticFiles() + urlSuffix;
  RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
  builder.setCallback(callback);
  try {
    builder.send();
  } catch (RequestException e) {
    callback.onError(null, e);
  }
}
 
Example 30
Project: swarm   File: ContentWidget.java   Source Code and License 5 votes vote down vote up
/**
 * Send a request for source code.
 * 
 * @param callback the {@link RequestCallback} to send
 * @param urlSuffix the URL to target, relative to the Showcase module's base URL.
 */
private void sendSourceRequest(RequestCallback callback, String urlSuffix) {
  // When Super Dev Mode is on, we will load it from the code server, not the original server.
  String url = GWT.getModuleBaseForStaticFiles() + urlSuffix;
  RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
  builder.setCallback(callback);
  try {
    builder.send();
  } catch (RequestException e) {
    callback.onError(null, e);
  }
}
 
Example 31
Project: OpenNMS   File: DefaultChartService.java   Source Code and License 5 votes vote down vote up
private void sendRequest(String url, RequestCallback callback) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    builder.setHeader("Accept", "application/json");
    
    builder.setUser("ipv6Rest");
    builder.setPassword("ipv6Rest");
    try {
        builder.sendRequest(null, callback);
    } catch (RequestException e) {
        e.printStackTrace();
    }
}
 
Example 32
Project: OpenNMS   File: DefaultNodeService.java   Source Code and License 5 votes vote down vote up
public void findSnmpInterfacesMatching(int nodeId, String parameter, String value, RequestCallback callback) {
    String url = BASE_URL + nodeId + "/snmpinterfaces?" + parameter + "=" + value;
    if(!parameter.equals("ifIndex") && !parameter.equals("ifSpeed")) {
        url += "&comparator=contains";
    }
    url += "&limit=0";
    sendRequest(callback, url);
    
}
 
Example 33
Project: OpenNMS   File: DefaultNodeService.java   Source Code and License 5 votes vote down vote up
private void sendRequest(RequestCallback callback, String url) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    builder.setHeader("accept", "application/json");
    try {
        builder.sendRequest(null, callback);
    } catch (RequestException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
 
Example 34
Project: OpenNMS   File: DefaultNodeService.java   Source Code and License 5 votes vote down vote up
public void findSnmpInterfacesMatching(int nodeId, String parameter, String value, RequestCallback callback) {
    String url = BASE_URL + nodeId + "/snmpinterfaces?" + parameter + "=" + value;
    if(!parameter.equals("ifIndex") && !parameter.equals("ifSpeed")) {
        url += "&comparator=contains";
    }
    url += "&limit=0";
    sendRequest(callback, url);
    
}
 
Example 35
Project: OpenNMS   File: DefaultNodeService.java   Source Code and License 5 votes vote down vote up
private void sendRequest(RequestCallback callback, String url) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    builder.setHeader("accept", "application/json");
    try {
        builder.sendRequest(null, callback);
    } catch (RequestException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
 
Example 36
Project: OpenNMS   File: DefaultKscReportService.java   Source Code and License 5 votes vote down vote up
@Override
public void addGraphToReport(final RequestCallback callback, final int kscReportId, final String graphTitle, final String graphName, final String resourceId, final String timeSpan) {
    UrlBuilder builder = new UrlBuilder();
    builder.setPath(BASE_URL + "/" + kscReportId);
    builder.setParameter("title", graphTitle);
    builder.setParameter("reportName", graphName);
    builder.setParameter("resourceId", resourceId);
    builder.setParameter("timespan", timeSpan);

    // we just want a relative URL, so we render it and strip the beginning :)
    final String url = builder.buildString().replace("http:///", "");
    GWT.log("making request: " + url);
    sendRequest(callback, RequestBuilder.PUT, url);
}
 
Example 37
Project: OpenNMS   File: DefaultKscReportService.java   Source Code and License 5 votes vote down vote up
private void sendRequest(final RequestCallback callback, final Method method, final String url) {
    final RequestBuilder builder = new RequestBuilder(method, url);
    builder.setHeader("accept", "application/json");
    try {
        builder.sendRequest(null, callback);
    } catch (final RequestException e) {
        e.printStackTrace();
    }
}
 
Example 38
Project: OpenNMS   File: DefaultKscReportService.java   Source Code and License 5 votes vote down vote up
@Override
public void addGraphToReport(final RequestCallback callback, final int kscReportId, final String graphTitle, final String graphName, final String resourceId, final String timeSpan) {
    UrlBuilder builder = new UrlBuilder();
    builder.setPath(BASE_URL + "/" + kscReportId);
    builder.setParameter("title", graphTitle);
    builder.setParameter("reportName", graphName);
    builder.setParameter("resourceId", resourceId);
    builder.setParameter("timespan", timeSpan);

    // we just want a relative URL, so we render it and strip the beginning :)
    final String url = builder.buildString().replace("http:///", "");
    GWT.log("making request: " + url);
    sendRequest(callback, RequestBuilder.PUT, url);
}
 
Example 39
Project: OpenNMS   File: DefaultKscReportService.java   Source Code and License 5 votes vote down vote up
private void sendRequest(final RequestCallback callback, final Method method, final String url) {
    final RequestBuilder builder = new RequestBuilder(method, url);
    builder.setHeader("accept", "application/json");
    try {
        builder.sendRequest(null, callback);
    } catch (final RequestException e) {
        e.printStackTrace();
    }
}
 
Example 40
Project: OpenNMS   File: DefaultNodeService.java   Source Code and License 5 votes vote down vote up
private void sendRequest(RequestCallback callback, String url) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    builder.setHeader("accept", "application/json");
    try {
        builder.sendRequest(null, callback);
    } catch (RequestException e) {
        e.printStackTrace();
    }
}
 
Example 41
Project: OpenNMS   File: DefaultNodeService.java   Source Code and License 5 votes vote down vote up
private void sendRequest(RequestCallback callback, String url) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    builder.setHeader("accept", "application/json");
    try {
        builder.sendRequest(null, callback);
    } catch (RequestException e) {
        e.printStackTrace();
    }
}
 
Example 42
Project: empiria.player   File: SynchronousScriptsLoader.java   Source Code and License 4 votes vote down vote up
private void injectScript(final Stack<ScriptUrl> scriptsStack, final RequestCallback callback) {
    ScriptUrl script = scriptsStack.pop();
    String correctUrl = urlConverter.getModuleRelativeUrl(script);
    requestWrapper.get(correctUrl, callback);
}
 
Example 43
Project: gwt-syncproxy   File: RemoteServiceServletTest.java   Source Code and License 4 votes vote down vote up
@Override
protected void doSetCallback(RequestBuilder rb, RequestCallback callback) {
	this.doSetCallback = true;
	super.doSetCallback(rb, callback);
}
 
Example 44
Project: gwt-syncproxy   File: RemoteServiceServletTest.java   Source Code and License 4 votes vote down vote up
@Override
protected void doSetCallback(RequestBuilder rb, RequestCallback callback) {
	this.doSetCallback = true;
	super.doSetCallback(rb, callback);
}
 
Example 45
Project: firefly   File: JsonUtils.java   Source Code and License 4 votes vote down vote up
public static void jsonRequest(String cmd,
                               List<Param> paramList,
                               RequestCallback cb) throws RequestException {
    jsonRequest(DEF_BASE_URL, cmd, paramList, cb);
}
 
Example 46
Project: turbogwt-http   File: ServerConnection.java   Source Code and License 4 votes vote down vote up
void sendRequest(RequestBuilder.Method method, String url, String data, RequestCallback callback)
throws RequestException;
 
Example 47
Project: turbogwt-http   File: ServerConnection.java   Source Code and License 4 votes vote down vote up
void sendRequest(int timeout, @Nullable String user, @Nullable String password, @Nullable Headers headers,
         RequestBuilder.Method method, String url, String data, RequestCallback callback)
throws RequestException;
 
Example 48
Project: turbogwt-http   File: ServerConnectionImpl.java   Source Code and License 4 votes vote down vote up
@Override
public void sendRequest(RequestBuilder.Method method, String url, String data, RequestCallback callback)
        throws RequestException {
    new RequestBuilder(method, url).sendRequest(data, callback);
}
 
Example 49
Project: sigmah   File: ServletRequestBuilder.java   Source Code and License 4 votes vote down vote up
/**
 * Sends the request with its optional parameter(s) (including {@code POST} parameters).
 * 
 * @param callback
 *          The {@code RequestCallback}.
 * @throws ServletRequestException
 *           If an error occurs during request call.
 */
public void send(final RequestCallback callback) throws ServletRequestException {

	final RequestBuilder requestBuilder = new RequestBuilder(requestMethod, urlBuilder.toString());

	requestBuilder.setCallback(callback != null ? callback : Void);

	final StringBuilder builder = new StringBuilder();

	if (ClientUtils.isNotEmpty(requestAttributes)) {

		final Iterator<String> iterator = requestAttributes.keySet().iterator();

		while (iterator.hasNext()) {
			final String next = iterator.next();
			final String attribute = requestAttributes.get(next);

			if (attribute != null) {
				builder.append(URL.encodeQueryString(next));
				builder.append('=');
				builder.append(URL.encodeQueryString(attribute));
				if (iterator.hasNext()) {
					builder.append('&');
				}
			}
		}
	}

	if (isPostMethod()) {
		requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded");
		requestBuilder.setRequestData(builder.length() > 0 ? builder.toString() : null);
	}

	try {

		requestBuilder.send();

	} catch (final RequestException e) {
		throw new ServletRequestException("Servlet request '" + builder + "' execution fails.", e);
	}
}
 
Example 50
Project: gwt4e   File: SeMa4gRequestCallbackProxy.java   Source Code and License 4 votes vote down vote up
public SeMa4gRequestCallbackProxy(SeMa4gRcpCommand command,
                                  RequestCallback asyncCallback) {
  super();
  this.command = command;
  this.asyncCallback = asyncCallback;
}
 
Example 51
Project: socom   File: ImageInfluenceStrategy.java   Source Code and License 4 votes vote down vote up
@Override
public void updateFreeAnswerOnUploadSuccess(final InfluenceFreeAnswerViewInterface<AnswerImage> answer,
		SimpleEntry<String, String>[] sourceParameter, final JSONValue result) {

	final String filePath = result.isObject().get("file").isString().stringValue();
	final boolean[] found = new boolean[] { false };
	fileDetectionTimer = new Timer() {

		@Override
		public void run() {
			RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, GWT.getHostPageBaseURL()
					+ getDataPath(filePath));

			try
			{
				builder.sendRequest(null, new RequestCallback() {
					public void onError(Request request, Throwable exception) {
						ImageInfluenceStrategy.this.presenter.showError(unkownError);
					}

					public void onResponseReceived(Request request, Response response) {
						if (found[0])
							return;
						if (response.getStatusCode() == 404)
						{
							ImageInfluenceStrategy.this.presenter.showError(notReadyError);
						} else
						{
							found[0] = true;
							fileDetectionTimer.cancel();
							onFreeAnswerFileReady(answer, result);
						}
					}
				});
			} catch (RequestException e)
			{
				ImageInfluenceStrategy.this.presenter.showError(unkownError);
			}
		}
	};

	fileDetectionTimer.scheduleRepeating(500);
}
 
Example 52
Project: opennmszh   File: DefaultChartService.java   Source Code and License 4 votes vote down vote up
@Override
public void getAllLocationsAvailability(RequestCallback callback) {
    sendRequest(AVAILABILITY_SERVICE_URL, callback);
}
 
Example 53
Project: opennmszh   File: DefaultChartService.java   Source Code and License 4 votes vote down vote up
@Override
public void getAvailabilityByLocation(String location, RequestCallback callback) {
    String url = AVAILABILITY_SERVICE_URL + "/" + location;
    sendRequest(url, callback);
}
 
Example 54
Project: opennmszh   File: DefaultChartService.java   Source Code and License 4 votes vote down vote up
@Override
public void getAvailabilityByParticipant(String participant, RequestCallback callback) {
    String url = AVAILABILITY_SERVICE_URL + "/?host=" + participant;
    sendRequest(url, callback);
    
}
 
Example 55
Project: opennmszh   File: DefaultChartService.java   Source Code and License 4 votes vote down vote up
@Override
public void getAvailabilityByLocationAndParticipant(String location,String participant, RequestCallback callback) {
    String url = AVAILABILITY_SERVICE_URL + "/" + location + "/?host=" + participant;
    sendRequest(url, callback);
    
}
 
Example 56
Project: opennmszh   File: DefaultChartService.java   Source Code and License 4 votes vote down vote up
@Override
public void getAllLocations(RequestCallback callback) {
    String url = LOCATION_LIST_SERVICE_URL;
    sendRequest(url, callback);
    
}
 
Example 57
Project: opennmszh   File: DefaultChartService.java   Source Code and License 4 votes vote down vote up
@Override
public void getAllParticipants(RequestCallback callback) {
    String url = PARTICIPANT_SERVICE_URL;
    sendRequest(url, callback);
    
}
 
Example 58
Project: opennmszh   File: DefaultNodeService.java   Source Code and License 4 votes vote down vote up
public void getAllIpInterfacesForNode(int nodeId, RequestCallback callback) {
    String url = BASE_URL + nodeId + "/ipinterfaces?limit=0";
    sendRequest(callback, url);
}
 
Example 59
Project: opennmszh   File: DefaultNodeService.java   Source Code and License 4 votes vote down vote up
public void getAllSnmpInterfacesForNode(int nodeId, RequestCallback callback) {
    String url = BASE_URL + nodeId + "/snmpinterfaces?limit=0";
    sendRequest(callback, url);
}
 
Example 60
Project: opennmszh   File: DefaultNodeService.java   Source Code and License 4 votes vote down vote up
public void findIpInterfacesMatching(int nodeId, String parameter, String value, RequestCallback callback) {
    String url = BASE_URL + nodeId + "/ipinterfaces?" + parameter + "=" + value + "&comparator=contains&limit=0";
    sendRequest(callback, url);
    
}