use of com.google.gwt.http.client.RequestBuilder in project kie-wb-common by kiegroup.
the class FooterPresenterTest method testSetupUrlWhenRequestIsValid.
@Test
public void testSetupUrlWhenRequestIsValid() throws RequestException {
final String url = "http://localhost:8080/kie-server/services/rest/server";
final RequestBuilder builder = mock(RequestBuilder.class);
doReturn(builder).when(presenter).makeRequest(url, onSuccess, onError);
presenter.setupUrl(url);
verify(builder).send();
}
use of com.google.gwt.http.client.RequestBuilder in project kie-wb-common by kiegroup.
the class FooterPresenterTest method testMakeRequest.
@Test
public void testMakeRequest() {
final String url = "http://localhost:8080/kie-server/services/rest/server";
final String none = "none";
final RequestCallback callback = mock(RequestCallback.class);
final String expectedHTTPMethod = RequestBuilder.GET.toString();
doReturn(callback).when(presenter).makeCallback(onSuccess, onError);
final RequestBuilder builder = presenter.makeRequest(url, onSuccess, onError);
assertEquals(expectedHTTPMethod, builder.getHTTPMethod());
assertEquals(url, builder.getUrl());
assertEquals(none, builder.getUser());
assertEquals(none, builder.getPassword());
assertEquals(callback, builder.getCallback());
assertEquals("*/*", builder.getHeader("Accept"));
}
use of com.google.gwt.http.client.RequestBuilder in project activityinfo by bedatadriven.
the class AdminGeometryProvider method fetchGeometry.
private void fetchGeometry(final int levelId, final AsyncCallback<AdminGeometry> callback) {
RequestBuilder request = new RequestBuilder(RequestBuilder.GET, "/resources/adminLevel/" + levelId + "/entities/polylines");
request.setCallback(new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
try {
AdminGeometry geometry = AdminGeometry.fromJson(response.getText());
cache.put(levelId, geometry);
callback.onSuccess(geometry);
} catch (Exception e) {
callback.onFailure(e);
}
}
@Override
public void onError(Request request, Throwable exception) {
callback.onFailure(exception);
}
});
try {
request.send();
} catch (RequestException e) {
callback.onFailure(e);
}
}
use of com.google.gwt.http.client.RequestBuilder in project pentaho-platform by pentaho.
the class UserRolesAdminPanelController method getRolesForUser.
private void getRolesForUser(String user) {
final String url = GWT.getHostPageBaseURL() + "api/userroledao/userRoles?userName=" + encodeUri(user);
RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.GET, url);
executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
executableTypesRequestBuilder.setHeader("accept", "application/xml");
try {
executableTypesRequestBuilder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
displayErrorInMessageBox(Messages.getString("Error"), exception.getLocalizedMessage());
}
public void onResponseReceived(Request request, Response response) {
selectedRolesListBox.clear();
for (String role : getSortedItems("roles", response)) {
selectedRolesListBox.addItem(role);
}
updateHelperDiv(HorizontalScrollWrapper.getListBoxWrapperUIId(selectedRolesListBox));
Timer t = new Timer() {
public void run() {
if (rolesListBox.getItemCount() > 0) {
cancel();
// availableRolesListBox = rolesListBox - selectedRolesListBox
availableRolesListBox.clear();
for (int i = 0; i < rolesListBox.getItemCount(); i++) {
String role = rolesListBox.getValue(i);
boolean isSelected = false;
for (int j = 0; j < selectedRolesListBox.getItemCount(); j++) {
if (selectedRolesListBox.getValue(j).equals(role)) {
isSelected = true;
}
}
if (!isSelected) {
availableRolesListBox.addItem(role);
}
}
updateHelperDiv(HorizontalScrollWrapper.getListBoxWrapperUIId(availableRolesListBox));
}
}
};
t.scheduleRepeating(100);
}
});
} catch (RequestException e) {
displayErrorInMessageBox(Messages.getString("Error"), e.getLocalizedMessage());
}
}
use of com.google.gwt.http.client.RequestBuilder in project pentaho-platform by pentaho.
the class UserRolesAdminPanelController method modifyUserRoles.
private void modifyUserRoles(final String userName, String serviceUrl) {
RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.PUT, serviceUrl);
try {
executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
executableTypesRequestBuilder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
displayErrorInMessageBox(Messages.getString("Error"), exception.getLocalizedMessage());
}
public void onResponseReceived(Request request, Response response) {
checkForError(Messages.getString("Error"), response);
getRolesForUser(userName);
initializeRoles(rolesListBox.getValue(rolesListBox.getSelectedIndex()), "api/userroledao/roles", rolesListBox);
}
});
} catch (RequestException e) {
displayErrorInMessageBox(Messages.getString("Error"), e.getLocalizedMessage());
}
}
Aggregations