List of usage examples for com.google.gwt.http.client RequestBuilder POST
Method POST
To view the source code for com.google.gwt.http.client RequestBuilder POST.
Click Source Link
From source file:org.jboss.errai.enterprise.jaxrs.client.shared.interceptor.RestCallCustomTypeResultManipulatingInterceptor.java
License:Apache License
@Override public void aroundInvoke(final RestCallContext context) { final User user = new User(11l, "first", "last", 20, Gender.MALE, null); final String userJackson = MarshallingWrapper.toJSON(user); final String url = context.getRequestBuilder().getUrl(); final RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, url); requestBuilder.setRequestData(userJackson); context.setRequestBuilder(requestBuilder); context.proceed(new RemoteCallback<User>() { @Override//from w w w . j a va 2 s . co m public void callback(final User response) { final String userAsJackson = response.getJacksonRep(); final User returnedUser = (User) MarshallingWrapper.fromJSON(userAsJackson, context.getReturnType()); returnedUser.setFirstName("intercepted"); context.setResult(returnedUser); } }); }
From source file:org.jboss.errai.enterprise.jaxrs.client.shared.interceptor.RestCallErrorInterceptor.java
License:Apache License
@Override public void aroundInvoke(final RestCallContext context) { RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, "invalid-url"); context.setRequestBuilder(requestBuilder); context.proceed(new RemoteCallback<String>() { @Override//from ww w .j a va 2s .c om public void callback(String response) { } }, new RestErrorCallback() { @Override public boolean error(Request message, Throwable throwable) { context.setResult("success"); return false; } }); }
From source file:org.jboss.hal.dmr.dispatch.impl.DMRHandler.java
License:Open Source License
@Inject public DMRHandler(Endpoints endpoints) { this.endpoints = endpoints; postRequestBuilder = new RequestBuilder(RequestBuilder.POST, endpoints.dmr()); postRequestBuilder.setHeader(HEADER_ACCEPT, DMR_ENCODED); postRequestBuilder.setHeader(HEADER_CONTENT_TYPE, DMR_ENCODED); postRequestBuilder.setIncludeCredentials(true); }
From source file:org.jboss.uberfire.dmr.poc.client.local.dmr.DMRRequest.java
License:Open Source License
private static RequestBuilder makeRequest(ModelNode requestData) { RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, "http://127.0.0.1:9990/management"); //RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, GWT.getHostPageBaseURL() + "index.jsp"); rb.setHeader("Content-type", "application/dmr-encoded"); rb.setHeader("Accept", "application/dmr-encoded"); rb.setIncludeCredentials(true);// w ww.ja v a 2s . co m rb.setRequestData(requestData.toBase64String()); return rb; }
From source file:org.kaaproject.kaa.server.admin.client.KaaAdmin.java
License:Apache License
public static void signOut() { RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, GWT.getModuleBaseURL() + "j_spring_security_logout"); try {//from www.j a v a 2s. c o m builder.sendRequest(null, new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { redirectToModule(".."); } @Override public void onError(Request request, Throwable exception) { redirectToModule(".."); } }); } catch (RequestException e) { } }
From source file:org.kaaproject.kaa.server.admin.client.Login.java
License:Apache License
private void login(final String userName, String password) { String postData = preparePostData("j_username=" + userName, "j_password=" + password); RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, GWT.getModuleBaseURL() + "j_spring_security_check?" + postData); try {//from w w w . ja va 2 s . c om builder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable exception) { Utils.handleException(exception, view); } public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == 0) { Utils.handleNetworkConnectionError(); } else { String error = response.getHeader("Error"); String errorType = response.getHeader("ErrorType"); if (!isEmpty(errorType) && "TempCredentials".equals(errorType)) { //change password ChangePasswordDialog.Listener listener = new ChangePasswordDialog.Listener() { @Override public void onChangePassword() { view.clearMessages(); } @Override public void onCancel() { } }; ChangePasswordDialog.showChangePasswordDialog(listener, userName, Utils.messages.tempCredentials()); } else if (!isEmpty(error)) { view.setErrorMessage(error); } else { view.clearMessages(); redirectToModule("kaaAdmin"); } } } }); } catch (RequestException e) { Utils.handleException(e, view); } }
From source file:org.kuali.student.common.ui.client.security.SpringSecurityLoginDialogHandler.java
License:Educational Community License
private void createLoginPanel() { lightbox = new KSLightBox(); VerticalPanel panel = new VerticalPanel(); FlexTable table = new FlexTable(); errorLabel = new Label(); errorLabel.setText(TIMEOUT_MSG); errorLabel.setStyleName("KSError"); username = new TextBox(); username.setName("j_username"); password = new PasswordTextBox(); password.setName("j_password"); table.setText(0, 0, "Username"); table.setWidget(0, 1, username);/*ww w .j a v a2 s .co m*/ table.setText(1, 0, "Password"); table.setWidget(1, 1, password); table.setWidget(2, 0, (new Button("Login", new ClickHandler() { public void onClick(ClickEvent event) { //JIRA FIX : KSENROLL-8731 - Replaced StringBuffer with StringBuilder StringBuilder postData = new StringBuilder(); postData.append(URL.encode("j_username")).append("=").append(username.getText()); postData.append("&").append(URL.encode("j_password")).append("=").append(password.getText()); RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, context.getApplicationContextUrl() + "/j_spring_security_check"); builder.setHeader("Content-type", "application/x-www-form-urlencoded"); try { builder.sendRequest(postData.toString(), new RequestCallback() { @Override public void onError(Request req, Throwable caught) { lightbox.hide(); KSErrorDialog.show(caught); } @Override public void onResponseReceived(Request req, Response res) { if (res.getStatusCode() == Response.SC_OK && !res.getText().contains("Bad credentials")) { lightbox.hide(); } else { errorLabel.setText("Your login attempt was not successful, try again."); } } }); } catch (RequestException e) { KSErrorDialog.show(e); } } }))); panel.add(errorLabel); panel.add(table); panel.setStyleName("KSLoginPanel"); lightbox.setWidget(panel); }
From source file:org.mindinformatics.gwt.domeo.plugins.resource.pmcimages.service.impl.JsonPmcImagesConnector.java
License:Apache License
@Override public void retrievePmcImagesData(final IPmcImagesRequestCompleted completionCallback, String pmid, String pmcid, String doi) throws IllegalArgumentException { if (_application.isHostedMode()) { String response = "[{\"uysie:hasCaption\": \"Representative self-terminating radical reactions.\"," + "\"uysie:hasFullText\": \"Most organic radical reactions occur through a cascade of two or more individual steps [1,2]. Knowledge of the nature and rates of these steps in other words, the mechanism of the reaction is of fundamental interest and is also important in synthetic planning. In synthesis, both the generation of the initial radical of the cascade and the removal of the final radical are crucial events [3]. Many useful radical reactions occur through chains that provide a naturally coupled regulation of radical generation and removal. Among the non-chain methods, generation and removal of radicals by oxidation and reduction are important, as is the\"," + "\"uysie:hasFileName\": \"nihms28314f1\"," + "\"uysie:hasTitle\": \"Do alpha-acyloxy and alpha-alkoxycarbonyloxy radicals fragment to form acyl and alkoxycarbonyl radicals?\"}]"; @SuppressWarnings("unchecked") JsArray<JsPmcImage> responseOnSets = (JsArray<JsPmcImage>) parseJson(response); HashMap<String, JsPmcImage> images = new HashMap<String, JsPmcImage>(); for (int i = 0; i < responseOnSets.length(); i++) { images.put(responseOnSets.get(i).getName(), responseOnSets.get(i)); }/*w w w . j a v a2 s .c om*/ completionCallback.returnPmcImagesData(images); return; } String requestUrl = ApplicationUtils.getUrlBase(GWT.getModuleBaseURL()) + "yaleImageFinder/retrievePmcImagesData?format=json"; try { RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, requestUrl); builder.setHeader("Content-Type", "application/json"); JSONObject request = new JSONObject(); if (pmid != null) request.put("pmid", new JSONString(pmid)); if (pmcid != null) request.put("pmcid", new JSONString(pmcid)); if (doi != null) request.put("doi", new JSONString(doi)); JSONArray messages = new JSONArray(); messages.set(0, request); builder.setTimeoutMillis(20000); builder.setRequestData(messages.toString()); builder.setCallback(new RequestCallback() { public void onError(Request request, Throwable exception) { if (exception instanceof RequestTimeoutException) { _application.getLogger().exception(this, "Couldn't load images metadata (timeout) " + exception.getMessage()); completionCallback.pmcImagesDataNotFound(); // ((ProgressMessagePanel)((DialogGlassPanel)_application.getDialogPanel()).getPanel()).addErrorMessage("Could not load images metadata (timeout)"); // handler.bibliographySetListNotCreated("Could not load existing bibliography (timeout)"); } else { _application.getLogger().exception(this, "Couldn't load images metadata"); completionCallback.pmcImagesDataNotFound(); // ((ProgressMessagePanel)((DialogGlassPanel)_application.getDialogPanel()).getPanel()).addErrorMessage("Could not load existing bibliography (onError)"); // handler.bibliographySetListNotCreated("Could not load existing bibliography (onError)"); } } public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode()) { try { _application.getLogger().debug(this, response.getText()); @SuppressWarnings("unchecked") JsArray<JsPmcImage> responseOnSets = (JsArray<JsPmcImage>) parseJson( response.getText()); HashMap<String, JsPmcImage> images = new HashMap<String, JsPmcImage>(); for (int i = 0; i < responseOnSets.length(); i++) { images.put(responseOnSets.get(i).getName(), responseOnSets.get(i)); } completionCallback.returnPmcImagesData(images); } catch (Exception e) { _application.getLogger().exception(this, "Could not parse images metadata " + e.getMessage()); completionCallback.pmcImagesDataNotFound(); // ((ProgressMessagePanel)((DialogGlassPanel)_application.getDialogPanel()).getPanel()).addErrorMessage("Could not parse existing bibliography " + e.getMessage()); // handler.bibliographySetListNotCreated("Could not parse existing bibliography " + e.getMessage() + " - "+ response.getText()); } } else if (503 == response.getStatusCode()) { _application.getLogger().exception(this, "Existing bibliography by url 503: " + response.getText()); completionCallback.pmcImagesDataNotFound(); // ((ProgressMessagePanel)((DialogGlassPanel)_application.getDialogPanel()).getPanel()).addErrorMessage("Could not retrieve existing bibliography " + response.getStatusCode()); // handler.bibliographySetListNotCreated("Could not retrieve existing bibliography " + response.getStatusCode() + " - "+ response.getText()); //completionCallback.textMiningNotCompleted(response.getText()); } else { _application.getLogger().exception(this, "Load images metadata " + response.getStatusCode() + ": " + response.getText()); // ((ProgressMessagePanel)((DialogGlassPanel)_application.getDialogPanel()).getPanel()).addErrorMessage("Could not retrieve existing bibliography " + response.getStatusCode()); // handler.bibliographySetListNotCreated("Could not retrieve existing bibliography " + response.getStatusCode() + " - "+ response.getText()); //handler.setExistingBibliographySetList(new JsArray(), true); //completionCallback.textMiningNotCompleted(response.getText()); completionCallback.pmcImagesDataNotFound(); } } }); builder.send(); } catch (RequestException e) { _application.getLogger().exception(this, "Couldn't save annotation"); completionCallback.pmcImagesDataNotFound(); } }
From source file:org.mindinformatics.gwt.framework.component.profiles.src.testing.JsonProfileManager.java
License:Apache License
@Override public MProfile saveUserProfile(MProfile newProfile, final IUpdateProfileCallback callback) { String url = GWT.getModuleBaseURL() + "profile/" + _application.getUserManager().getUser().getUserName() + "/info?format=json"; RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url); builder.setHeader("Content-type", "application/json"); HashMap<String, String> pluginsStatus = callback.getPluginsStatus(); HashMap<String, String> featuresStatus = callback.getFeaturesStatus(); StringBuffer postData = new StringBuffer(); postData.append("["); postData.append(" {"); postData.append(" \"uuid\": \""); postData.append(newProfile.getUuid()); postData.append("\","); postData.append(" \"name\": \""); postData.append(newProfile.getName()); postData.append("\","); postData.append(" \"description\": \""); postData.append(newProfile.getDescription()); postData.append("\","); postData.append(" \"createdon\": \""); DateTimeFormat fmt = DateTimeFormat.getFormat("MM/dd/yyyy HH:mm:ss Z"); postData.append(fmt.format(new Date())); postData.append("\","); postData.append(" \"createdby\": ["); postData.append(" {"); postData.append(" \"@id\": \""); postData.append(_application.getAgentManager().getUserPerson().getUri()); postData.append("\","); postData.append(" \"@type\": \""); postData.append("foafx:Person"); postData.append("\","); postData.append(" \"foafx:name\": \""); postData.append(_application.getAgentManager().getUserPerson().getName()); postData.append("\""); postData.append(" }"); postData.append(" ],"); postData.append(" \"statusplugins\": ["); for (String key : pluginsStatus.keySet()) { postData.append(" {"); postData.append(" \"uuid\": \""); postData.append(key);/*w ww. ja v a2 s .c om*/ postData.append("\","); postData.append(" \"status\": \""); postData.append(pluginsStatus.get(key)); postData.append("\""); postData.append(" },"); } postData.append(" ],"); postData.append(" \"statusfeatures\": ["); for (String key : featuresStatus.keySet()) { postData.append(" {"); postData.append(" \"uuid\": \""); postData.append(key); postData.append("\","); postData.append(" \"status\": \""); postData.append(featuresStatus.get(key)); postData.append("\""); postData.append(" },"); } postData.append(" ]"); postData.append(" }"); postData.append("]"); try { Request request = builder.sendRequest(postData.toString(), new RequestCallback() { public void onError(Request request, Throwable exception) { _application.getInitializer().addException("Couldn't retrieve User Profile JSON"); } public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode()) { JsoProfile jsoProfile = (JsoProfile) ((JsArray) parseJson(response.getText())).get(0); MProfile profile = new MProfile(); profile.setUuid(jsoProfile.getUuid()); profile.setName(jsoProfile.getName()); profile.setDescription(jsoProfile.getDescription()); profile.setLastSavedOn(jsoProfile.getCreatedOn()); AgentsFactory factory = new AgentsFactory(); JsArray<JavaScriptObject> creators = jsoProfile.getCreatedBy(); if (getObjectType(creators.get(0)).equals(IPerson.TYPE)) { JsoAgent person = (JsoAgent) creators.get(0); profile.setLastSavedBy((IPerson) factory.createAgent(person)); } JsArray<JsoProfileEntry> plugins = jsoProfile.getStatusPlugins(); for (int i = 0; i < plugins.length(); i++) { JsoProfileEntry entry = plugins.get(i); profile.getPlugins().put(entry.getName(), entry.getStatus()); } JsArray<JsoProfileEntry> features = jsoProfile.getStatusFeatures(); for (int i = 0; i < features.length(); i++) { JsoProfileEntry entry = features.get(i); profile.getFeatures().put(entry.getName(), entry.getStatus()); } setCurrentProfile(profile); callback.updateCurrentProfile(); } else { _application.getInitializer().addException( "Couldn't retrieve User Profile JSON (" + response.getStatusText() + ")"); } } }); } catch (RequestException e) { _application.getInitializer().addException("Couldn't retrieve User Profile JSON"); } return newProfile; }
From source file:org.mindinformatics.gwt.framework.component.profiles.src.testing.JsonProfileManager.java
License:Apache License
@Override public void saveCurrentProfile(MProfile currentProfile, final IUpdateProfileCallback callback) { String url = GWT.getModuleBaseURL() + "profile/" + _application.getUserManager().getUser().getUserName() + "/save?format=json"; if (!_application.isHostedMode()) url = ApplicationUtils.getUrlBase(GWT.getModuleBaseURL()) + "profile/" + _application.getUserManager().getUser().getUserName() + "/save?format=json"; RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url); builder.setHeader("Content-type", "application/json"); HashMap<String, String> pluginsStatus = callback.getPluginsStatus(); HashMap<String, String> featuresStatus = callback.getFeaturesStatus(); StringBuffer postData = new StringBuffer(); postData.append("["); postData.append(" {"); postData.append(" \"uuid\": \""); postData.append(currentProfile.getUuid()); postData.append("\","); postData.append(" \"name\": \""); postData.append(currentProfile.getName()); postData.append("\","); postData.append(" \"description\": \""); postData.append(currentProfile.getDescription()); postData.append("\","); postData.append(" \"createdOn\": \""); DateTimeFormat fmt = DateTimeFormat.getFormat("MM/dd/yyyy HH:mm:ss Z"); postData.append(fmt.format(new Date())); postData.append("\","); postData.append(" \"createdBy\": ["); postData.append(" {"); postData.append(" \"@id\": \""); //Window.alert(""+currentProfile.getLastSavedBy()); postData.append(currentProfile.getLastSavedBy().getUri()); postData.append("\","); postData.append(" \"@type\": \""); postData.append("foafx:Person"); postData.append("\","); postData.append(" \"foafx:name\": \""); postData.append(currentProfile.getLastSavedBy().getName()); postData.append("\""); postData.append(" }"); postData.append(" ],"); postData.append(" \"plugins\": ["); for (String key : pluginsStatus.keySet()) { postData.append(" {"); postData.append(" \"uuid\": \""); postData.append(key);//from w w w . j av a 2 s.com postData.append("\","); postData.append(" \"status\": \""); postData.append(pluginsStatus.get(key)); postData.append("\""); postData.append(" },"); } postData.append(" ],"); postData.append(" \"statusfeatures\": ["); for (String key : featuresStatus.keySet()) { postData.append(" {"); postData.append(" \"uuid\": \""); postData.append(key); postData.append("\","); postData.append(" \"status\": \""); postData.append(featuresStatus.get(key)); postData.append("\""); postData.append(" },"); } postData.append(" ]"); postData.append(" }"); postData.append("]"); try { Request request = builder.sendRequest(postData.toString(), new RequestCallback() { public void onError(Request request, Throwable exception) { _application.getInitializer().addException("Couldn't retrieve User Profile JSON"); } public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode()) { /* JsoProfile jsoProfile = (JsoProfile)((JsArray) parseJson(response.getText())).get(0); MProfile profile = new MProfile(); profile.setUuid(jsoProfile.getUuid()); profile.setName(jsoProfile.getName()); profile.setDescription(jsoProfile.getDescription()); profile.setLastSavedOn(jsoProfile.getCreatedOn()); AgentsFactory factory = new AgentsFactory(); JsArray<JavaScriptObject> creators = jsoProfile.getCreatedBy(); if(getObjectType(creators.get(0)).equals(IPerson.TYPE)) { JsoAgent person = (JsoAgent) creators.get(0); profile.setLastSavedBy((IPerson) factory.createAgent(person)); } JsArray<JsoProfileEntry> plugins = jsoProfile.getStatusPlugins(); for(int i=0; i<plugins.length(); i++) { JsoProfileEntry entry = plugins.get(i); profile.getPlugins().put(entry.getName(), entry.getStatus()); } setCurrentProfile(profile); */ callback.updateCurrentProfile(); } else { _application.getInitializer().addException( "Couldn't retrieve User Profile JSON (" + response.getStatusText() + ")"); } } }); } catch (RequestException e) { _application.getInitializer().addException("Couldn't retrieve User Profile JSON"); callback.updateCurrentProfile(); } }