private void postyRequest(String url, String data) { final RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, url); rb.setHeader("Content-type", "application/x-www-form-urlencoded"); try { rb.sendRequest( data, new RequestCallback() { public void onError(final Request request, final Throwable exception) { Window.alert(exception.getMessage()); } public void onResponseReceived(final Request request, final Response response) { // Window.alert(response.getText()); int id = Integer.parseInt(response.getText()); if (id == 1) { String url = "http://localhost:3000/workers.json"; getRequest(url); } else if (id > 1) { Frame frame = new Frame("http://localhost:3000/workshops/summary"); RootPanel.get().add(frame); mainPanel.clear(); mainPanel.add(frame); // Window.alert("" + id); } else { userBox.setText(""); passBox.setText(""); } } }); } catch (final Exception e) { Window.alert(e.getMessage()); } }
/** @param node */ public void makePublic(final FileNode node, boolean isPublic) { String url = node.getRepository() + "/permissions"; RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.POST, url); builder.setHeader("Content-type", "application/x-www-form-urlencoded"); StringBuilder args = new StringBuilder(); args.append("isPublic="); args.append(URL.encodeQueryString(Boolean.toString(isPublic))); args.append("&filename="); args.append(URL.encodeQueryString(getCanonicalName(node))); try { Request request = builder.sendRequest( args.toString(), new RequestCallback() { public void onError(Request request, Throwable exception) { // displayError("Couldn't retrieve JSON "+exception.getMessage()); } public void onResponseReceived(Request request, Response response) { GWT.log("Got reply"); if (200 == response.getStatusCode()) { GWT.log("Reply is" + response.getText()); GWT.log("Headers is " + response.getHeadersAsString()); GWT.log("Status Text " + response.getStatusText()); fetchFiles(repositoryUri, node.getPath()); } else { Window.alert( "Update failure: " + response.getStatusText() + " " + response.getText()); } } }); } catch (RequestException e) { Window.alert("Update exception: " + e.toString()); } }
public void deleteFolder(final FileNode object) { String filename = getCanonicalName(object); String url = this.repo.getUri() + "/folder?filename=" + URL.encodeQueryString(filename); // Send request to server and catch any errors. RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.DELETE, url); try { Request request = builder.sendRequest( null, new RequestCallback() { public void onError(Request request, Throwable exception) { // displayError("Couldn't retrieve JSON "+exception.getMessage()); } public void onResponseReceived(Request request, Response response) { GWT.log(response.getStatusCode() + " " + response.getText()); if (200 != response.getStatusCode()) { Window.alert( "Delete failure: " + response.getStatusText() + " " + response.getText()); } } }); } catch (RequestException e) { Window.alert("Delete exception: " + e.toString()); } }
public void activate() { processLDAPmode(); initializeActionBaseSecurityElements(); initializeAvailableUsers(null); final String url = GWT.getHostPageBaseURL() + "api/system/authentication-provider"; RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.GET, url); executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); executableTypesRequestBuilder.setHeader("accept", "application/json"); try { executableTypesRequestBuilder.sendRequest( null, new RequestCallback() { public void onError(Request request, Throwable exception) {} public void onResponseReceived(Request request, Response response) { boolean usingLDAP = response.getText().contains("ldap"); if (usingLDAP) { initializeRoles(null, "api/userrolelist/roles", rolesListBox); } else { initializeRoles(null, "api/userroledao/roles", rolesListBox); } initializeRoles(null, "api/userrolelist/extraRoles", systemRolesListBox); } }); } catch (RequestException e) { // ignored } }
protected void performOperation() { final String url = GWT.getHostPageBaseURL() + "plugin/reporting/api/cache/clear"; // $NON-NLS-1$ RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, url); requestBuilder.setHeader("accept", "text/text"); requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); try { requestBuilder.sendRequest( null, new RequestCallback() { public void onError(Request request, Throwable exception) { // showError(exception); } public void onResponseReceived(Request request, Response response) { MessageDialogBox dialogBox = new MessageDialogBox( Messages.getString("info"), Messages.getString("reportingDataCacheFlushedSuccessfully"), false, false, true); //$NON-NLS-1$ //$NON-NLS-2$ dialogBox.center(); } }); } catch (RequestException e) { Window.alert(e.getMessage()); // showError(e); } }
public <T extends JavaScriptObject> void send(final OverlayCallback<T> callback) { defaultAcceptType(Resource.CONTENT_TYPE_JSON); try { send( new AbstractRequestCallback<T>(this, callback) { protected T parseResult() throws Exception { try { JSONValue val = JSONParser.parse(response.getText()); if (val.isObject() != null) { return (T) val.isObject().getJavaScriptObject(); } else if (val.isArray() != null) { return (T) val.isArray().getJavaScriptObject(); } else { throw new ResponseFormatException("Response was NOT a JSON object"); } } catch (JSONException e) { throw new ResponseFormatException("Response was NOT a valid JSON document", e); } catch (IllegalArgumentException e) { throw new ResponseFormatException("Response was NOT a valid JSON document", e); } } }); } catch (Throwable e) { GWT.log("Received http error for: " + builder.getHTTPMethod() + " " + builder.getUrl(), e); callback.onFailure(this, e); } }
private void processLDAPmode() { final String url = GWT.getHostPageBaseURL() + "api/system/authentication-provider"; RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.GET, url); executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); executableTypesRequestBuilder.setHeader("accept", "application/json"); try { executableTypesRequestBuilder.sendRequest( null, new RequestCallback() { public void onError(Request request, Throwable exception) {} public void onResponseReceived(Request request, Response response) { boolean usingLDAP = !response.getText().contains("ldap"); usersLabelPanel.setVisible(usingLDAP); usersPanel.setVisible(usingLDAP); newRoleButton.setVisible(usingLDAP); deleteRoleButton.setVisible(usingLDAP); if (!usingLDAP) { mainTabPanel.getTab(0).setVisible(false); mainTabPanel.selectTab(1); } else { mainTabPanel.getTab(0).setVisible(true); mainTabPanel.selectTab(0); } } }); } catch (RequestException e) { // ignored } }
public List<TaskRef> getExistingTasks(final String filter) { final List<TaskRef> retval = new ArrayList<TaskRef>(); String url = GWT.getModuleBaseURL() + this.contextPath + "/tasks/package/defaultPackage/"; if (filter != null && !"".equals(filter)) { url = url + "q=" + URL.encodeQueryString(filter); } RequestBuilder request = new RequestBuilder(RequestBuilder.GET, url); request.setCallback( new RequestCallback() { public void onResponseReceived(Request request, Response response) { retval.addAll(helper.readTasks(response.getText())); bus.fireEvent(new ExistingTasksResponseEvent(retval, filter)); } public void onError(Request request, Throwable exception) { bus.fireEvent(new NotificationEvent(Level.ERROR, "Couldn't read tasks", exception)); } }); try { request.send(); } catch (RequestException e) { bus.fireEvent(new NotificationEvent(Level.ERROR, "Couldn't read tasks", e)); } return retval; }
protected void initializeExecutableFileTypes() { final String moduleBaseURL = GWT.getModuleBaseURL(); final String moduleName = GWT.getModuleName(); final String contextURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf(moduleName)); final String url = contextURL + "api/repos/executableTypes"; // $NON-NLS-1$ RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.GET, url); executableTypesRequestBuilder.setHeader("accept", "application/json"); try { executableTypesRequestBuilder.sendRequest( null, new RequestCallback() { public void onError(Request request, Throwable exception) { // showError(exception); } public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == Response.SC_OK) { JSONObject jsonObject = (JSONObject) JSONParser.parse(response.getText()); JSONArray jsonList = (JSONArray) jsonObject.get("executableFileTypeDto"); for (int i = 0; i < jsonList.size(); i++) { JSONObject executableType = (JSONObject) jsonList.get(i); executableFileExtensions.add( executableType.get("extension").isString().stringValue()); } } else { // showServerError(response); } } }); } catch (RequestException e) { // showError(e); } }
public void generateForm(FormRepresentation form, String language, Map<String, Object> inputs) { RequestBuilder request = new RequestBuilder( RequestBuilder.POST, GWT.getModuleBaseURL() + this.contextPath + "/formPreview/lang/" + language); request.setCallback( new RequestCallback() { public void onResponseReceived(Request request, Response response) { String html = response.getText(); bus.fireEvent(new PreviewFormResponseEvent(html)); } public void onError(Request request, Throwable exception) { bus.fireEvent(new NotificationEvent(Level.ERROR, "Couldn't preview form", exception)); } }); try { request.setRequestData(helper.asXml(form, inputs)); request.send(); } catch (RequestException e) { bus.fireEvent(new NotificationEvent(Level.ERROR, "Couldn't send form to server", e)); } catch (FormEncodingException e) { bus.fireEvent(new NotificationEvent(Level.ERROR, "Couldn't decode form", e)); } }
public void deleteMenuItem(String groupName, FBMenuItem item) { RequestBuilder request = new RequestBuilder( RequestBuilder.DELETE, GWT.getModuleBaseURL() + this.contextPath + "/menuItems/"); request.setCallback( new RequestCallback() { public void onResponseReceived(Request request, Response response) { int code = response.getStatusCode(); if (code != Response.SC_ACCEPTED && code != Response.SC_NO_CONTENT && code != Response.SC_OK) { bus.fireEvent( new NotificationEvent( Level.WARN, "Error deleting menu item on server (code = " + code + ")")); } else { bus.fireEvent(new NotificationEvent(Level.INFO, "menu item deleted successfully")); } } public void onError(Request request, Throwable exception) { bus.fireEvent( new NotificationEvent( Level.ERROR, "Error deleting menu item on server", exception)); } }); try { request.setRequestData(helper.asXml(groupName, item)); request.send(); } catch (RequestException e) { bus.fireEvent(new NotificationEvent(Level.ERROR, "Error deleting menu item on server", e)); } }
public List<MainMenuOption> getMenuOptions() { final List<MainMenuOption> currentOptions = new ArrayList<MainMenuOption>(); RequestBuilder request = new RequestBuilder( RequestBuilder.GET, GWT.getModuleBaseURL() + this.contextPath + "/menuOptions/"); request.setCallback( new RequestCallback() { public void onResponseReceived(Request request, Response response) { currentOptions.addAll(helper.readMenuOptions(response.getText())); for (MainMenuOption option : currentOptions) { bus.fireEvent(new MenuOptionAddedEvent(option)); } } public void onError(Request request, Throwable exception) { bus.fireEvent( new NotificationEvent(Level.ERROR, "Couldn't find menu options", exception)); } }); try { request.send(); } catch (RequestException e) { bus.fireEvent(new NotificationEvent(Level.ERROR, "Couldn't read menuOptions", e)); } return currentOptions; }
public Map<String, List<FBMenuItem>> getMenuItems() { final Map<String, List<FBMenuItem>> menuItems = new HashMap<String, List<FBMenuItem>>(); RequestBuilder request = new RequestBuilder( RequestBuilder.GET, GWT.getModuleBaseURL() + this.contextPath + "/menuItems/"); request.setCallback( new RequestCallback() { public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == Response.SC_OK) { menuItems.putAll(helper.readMenuMap(response.getText())); for (String groupName : menuItems.keySet()) { for (FBMenuItem menuItem : menuItems.get(groupName)) { bus.fireEvent(new MenuItemFromServerEvent(menuItem, groupName)); } } } else { bus.fireEvent( new NotificationEvent( Level.ERROR, "Couldn't find menu items: response status 404")); } } public void onError(Request request, Throwable exception) { bus.fireEvent( new NotificationEvent(Level.ERROR, "Couldn't find menu items", exception)); } }); try { request.send(); } catch (RequestException e) { bus.fireEvent(new NotificationEvent(Level.ERROR, "Couldn't read menuItems", e)); } return menuItems; }
public List<FormRepresentation> getForms() throws FormBuilderException { String url = new StringBuilder(GWT.getModuleBaseURL()) .append(this.contextPath) .append("/formDefinitions/package/defaultPackage/") .toString(); RequestBuilder request = new RequestBuilder(RequestBuilder.GET, url); final List<FormRepresentation> list = new ArrayList<FormRepresentation>(); request.setCallback( new RequestCallback() { public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == Response.SC_OK) { list.addAll(helper.readForms(response.getText())); bus.fireEvent(new LoadServerFormResponseEvent(list)); } else { bus.fireEvent( new NotificationEvent(Level.ERROR, "Couldn't find forms: response status 404")); } } public void onError(Request request, Throwable exception) { bus.fireEvent(new NotificationEvent(Level.ERROR, "Couldn't find forms", exception)); } }); try { request.send(); } catch (RequestException e) { throw new FormBuilderException(e); } return list; }
public void deleteAnnotation(String annotates, final Annotation annotation) { if (annotates.contains("?")) { annotates = annotates.substring(0, annotates.indexOf('?')); } String url = controller.getAnnoteaServerUrl() + "/" + annotation.getUUID(); url += "?document_url=" + annotates; RequestBuilder req = new RequestBuilder("DELETE", url) { // nothing to override... used to make a *real* HTTP DELETE request }; try { req.sendRequest( null, new RequestCallback() { public void onError(Request arg0, Throwable arg1) {} public void onResponseReceived(Request arg0, Response arg1) { getAnnotationList(Window.Location.getHref(), true); controller.reloadAnnotations(); } }); } catch (RequestException e) { GWT.log("Error while deleting an annotation: " + url, e); Log.debug("Error while deleting an annotation: " + url, e); } }
private RequestBuilder buildRequest(RequestBuilder.Method httpMethod) { String resourceId = idField.getText(); String resourceUrl = "/resources/customers/"; if (httpMethod != RequestBuilder.POST) { resourceUrl += URL.encode(resourceId); } RequestBuilder request = new RequestBuilder(httpMethod, resourceUrl); if (httpMethod == RequestBuilder.PUT || httpMethod == RequestBuilder.POST) { if (resourceId.equals("")) { resourceId = "0"; } request.setRequestData( "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><customer id=\"" + resourceId + "\"><fullname>" + nameField.getText() + "</fullname>" + "<address><street>" + streetField.getText() + "</street><city>" + cityField.getText() + "</city><state>" + stateField.getText() + "</state><zip>" + zipField.getText() + "</zip></address></customer>"); request.setHeader("Content-Type", "application/xml; charset=utf-8"); } return request; }
public void getAnnotationList(String annotates, final boolean forceDecorate) { if (annotates.contains("?")) { annotates = annotates.substring(0, annotates.indexOf('?')); } String url = controller.getAnnoteaServerUrl() + "?w3c_annotates=" + annotates; RequestBuilder getRequest = new RequestBuilder(RequestBuilder.GET, URL.encode(url)); try { getRequest.sendRequest( null, new RequestCallback() { public void onError(Request request, Throwable exception) {} public void onResponseReceived(Request request, Response response) { responseManager.processAnnotationListResponse(response.getText()); if (forceDecorate) { // Force all the annotations to be redecorated controller.updateAnnotations(true); } } }); } catch (RequestException e) { GWT.log("Error while requesting annotations: " + url, e); Log.debug("Error while requesting annotations: " + url, e); Window.alert(e.toString()); } }
public void getMessages() { RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(URLGET)); try { Request request = builder.sendRequest( null, new RequestCallback() { public void onError(Request request, Throwable exception) {} public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode()) { IResponse serverResponse = decodeJSON(response.getText()); processResponse(serverResponse); } else { Window.alert("Messages couldn't been recieved"); } } }); } catch (RequestException e) { // Couldn't connect to server } }
public void deleteRoles() { String selectedRoles = ""; for (int i = 0; i < rolesListBox.getItemCount(); i++) { if (rolesListBox.isItemSelected(i)) { selectedRoles = selectedRoles + encodeUri(rolesListBox.getValue(i)) + "|"; } } String serviceUrl = GWT.getHostPageBaseURL() + "api/userroledao/deleteRoles?roleNames=" + selectedRoles; 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); availableMembersListBox.clear(); selectedMembersListBox.clear(); initializeRoles(null, "api/userroledao/roles", rolesListBox); initializeAvailableUsers(usersListBox.getValue(usersListBox.getSelectedIndex())); } }); } catch (RequestException e) { displayErrorInMessageBox(Messages.getString("Error"), e.getLocalizedMessage()); } }
protected <T extends JavaScriptObject> void requestObject( final RequestBuilder builder, final AsyncCallback<T> callback) { builder.setUser(DEFAULT_USER); builder.setPassword(DEFAULT_PASSWORD); builder.setCallback( new RequestCallback() { @SuppressWarnings("unchecked") @Override public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode()) { callback.onSuccess((T) JsonUtils.safeEval(response.getText())); } else { final StatusCodeException exception = new StatusCodeException(response.getStatusCode(), response.getStatusText()); callback.onFailure(exception); } } @Override public void onError(Request request, Throwable exception) { callback.onFailure(exception); } }); try { builder.send(); } catch (RequestException exception) { callback.onFailure(exception); } }
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()); } }
public static void performLogin(final AsyncCallback<Boolean> callback) { // let's only login if we are not actually logged in try { final String url = GWT.getHostPageBaseURL() + "api/mantle/isAuthenticated"; // $NON-NLS-1$ RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url); requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); requestBuilder.setHeader("accept", "text/plain"); requestBuilder.sendRequest( null, new RequestCallback() { public void onError(Request request, Throwable caught) { MantleLoginDialog dialog = new MantleLoginDialog(callback, false); dialog.show(); } public void onResponseReceived(Request request, Response response) { if (!"true".equalsIgnoreCase(response.getText())) { MantleLoginDialog dialog = new MantleLoginDialog(callback, false); dialog.show(); } } }); } catch (RequestException e) { MantleLoginDialog dialog = new MantleLoginDialog(callback, false); dialog.show(); } }
public void saveUser(final String name, final String password) { String serviceUrl = GWT.getHostPageBaseURL() + "api/userroledao/createUser"; RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.PUT, serviceUrl); try { executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); executableTypesRequestBuilder.setHeader("Content-Type", "application/json"); String json = "{\"userName\": \"" + encodeUri(name) + "\", \"password\": \"" + encodeUri(password) + "\"}"; executableTypesRequestBuilder.sendRequest( json, new RequestCallback() { public void onError(Request request, Throwable exception) { displayErrorInMessageBox( Messages.getString("Error"), exception.getLocalizedMessage()); } public void onResponseReceived(Request request, Response response) { initializeAvailableUsers(name); initializeRoles( rolesListBox.getValue(rolesListBox.getSelectedIndex()), "api/userroledao/roles", rolesListBox); } }); } catch (RequestException e) { displayErrorInMessageBox(Messages.getString("Error"), e.getLocalizedMessage()); } }
@Override public void sendAnalytics(String event, HashMap<String, String> params) { if (analyticsId == null) { return; } String url = "http://www.bluenotepad.com/api/log?" + "notepad=" + analyticsId + "&session=" + sessionId + "&event=" + event; if (params != null) { for (String key : params.keySet()) { url += "&" + key + "=" + params.get(key).replace(" ", " "); } } String encodedUrl = URL.encode(url); RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, encodedUrl); try { builder.sendRequest( null, new RequestCallback() { public void onError(Request request, Throwable exception) {} public void onResponseReceived(Request request, Response response) {} }); } catch (RequestException e) { } }
@Override void send(String message, final AsyncCallback<Void> callback) { RequestBuilder request = new RequestBuilder(RequestBuilder.POST, serviceUrl()); try { request.sendRequest( message, new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { // when a connection is abruptly closed (for instance when a user presses F5 // the statuscode seems to be 0, the call could have arrived at the server though if (response.getStatusCode() != Response.SC_OK && response.getStatusCode() != 0) { logger.log( Level.SEVERE, "Failed to send server message: [" + response.getStatusText() + "," + response.getStatusCode() + "]"); callback.onFailure( new StatusCodeException(response.getStatusCode(), response.getStatusText())); } else { callback.onSuccess(null); } } @Override public void onError(Request request, Throwable exception) { callback.onFailure(exception); } }); } catch (RequestException ex) { callback.onFailure(ex); } }
public boolean creatBarPloterPDF(String username, String fileName, String theData) { RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, "FileSavePlotServlet"); StringBuffer postData = new StringBuffer(); postData.append(URL.encode("username")).append("=").append(URL.encode(username)); postData.append(URL.encode("&")); postData.append(URL.encode("plotFileName")).append("=").append(URL.encode(fileName)); postData.append(URL.encode("&")); postData.append(URL.encode("theData")).append("=").append(URL.encode(theData)); builder.setHeader("Content-type", "application/x-www-form-urlencoded"); try { builder.setRequestData(postData.toString()); /* or other RequestCallback impl*/ builder.setCallback(this); com.google.gwt.http.client.Request res = builder.send(); } catch (Exception e) { // handle this Window.alert("Exception..." + e.getMessage()); } return true; }
public void getRepo(String repoUri) { // Send request to server and catch any errors. this.lastRepoURI = repoUri; // this.lastPrefix = null; RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, repoUri); try { Request request = builder.sendRequest( null, new RequestCallback() { public void onError(Request request, Throwable exception) { // displayError("Couldn't retrieve JSON "+exception.getMessage()); } public void onResponseReceived(Request request, Response response) { GWT.log(response.getStatusCode() + " " + response.getText()); if (200 == response.getStatusCode()) { Repository repo = Repository.asRepository(response.getText()); updateRepo(repo); } else { Window.alert( "Update failure: " + response.getStatusText() + " " + response.getText()); } } }); } catch (RequestException e) { Window.alert("Update exception: " + e.toString()); } }
public static void retrieveAncestors(final Event event, final PathHandler handler) { String url = "/ReactomeRESTfulAPI/RESTfulWS/queryEventAncestors/" + event.getDbId(); RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url); requestBuilder.setHeader("Accept", "application/json"); try { requestBuilder.sendRequest( null, new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { try { JSONArray list = JSONParser.parseStrict(response.getText()).isArray(); Ancestors ancestors = new Ancestors(list); List<Path> paths = getPathsWithoutOrphanPathways(ancestors.getPathsContaining(event)); handler.onPathsRetrieved(paths); } catch (Exception ex) { // ToDo: Look into new Error Handling } } @Override public void onError(Request request, Throwable exception) { // ToDo: Look into new Error Handling } }); } catch (RequestException ex) { // ToDo: Look into new Error Handling } }
/* * This method is currently not called by the RPC framework. When it is, we can remove the sessionId * logic from the GWTServiceLookup class. * * For background information, please see http://code.google.com/p/google-web-toolkit/issues/detail?id=5668 */ @Override protected <T> RequestBuilder doPrepareRequestBuilder( ResponseReader responseReader, String methodName, RpcStatsContext statsContext, String requestData, AsyncCallback<T> callback) { RequestBuilder rb = super.doPrepareRequestBuilder( responseReader, methodName, statsContext, requestData, callback); String sessionId = UserSessionManager.getSessionId(); if (sessionId != null) { if (Log.isDebugEnabled()) { Log.debug( "SessionRpcRequestBuilder is adding sessionId to request for (" + methodName + ")"); } rb.setHeader(UserSessionManager.SESSION_NAME, sessionId); } else { Log.error("SessionRpcRequestBuilder missing sessionId for request (" + methodName + ")"); } return rb; }
private void initializeSystemRoles() { final String url = GWT.getHostPageBaseURL() + "api/userrole/systemRoles"; // $NON-NLS-1$ RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.GET, url); executableTypesRequestBuilder.setHeader("accept", "application/json"); try { executableTypesRequestBuilder.sendRequest( null, new RequestCallback() { public void onError(Request request, Throwable exception) {} public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == Response.SC_OK) { JsUserRoleList roleList = (JsUserRoleList) parseRoleList(JsonUtils.escapeJsonForEval(response.getText())); JsArrayString jsRoleNames = roleList.getRoles(); for (int i = 0; i < jsRoleNames.length(); i++) { systemRoles.add(jsRoleNames.get(i)); } Collections.sort(systemRoles); } else { } } }); } catch (RequestException e) { } }