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.jahia.ajax.gwt.client.widget.toolbar.action.ExecuteActionItem.java
License:Open Source License
protected void doAction() { final List<GWTJahiaNode> gwtJahiaNodes = linker.getSelectionContext().getMultipleSelection(); for (GWTJahiaNode gwtJahiaNode : gwtJahiaNodes) { String baseURL = org.jahia.ajax.gwt.client.util.URL .getAbsoluteURL(JahiaGWTParameters.getContextPath() + "/cms/render"); String localURL = baseURL + "/default/" + JahiaGWTParameters.getLanguage() + URL.encode(gwtJahiaNode.getPath()); linker.loading(Messages.get("label.executing", "Executing action ...")); RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, localURL.replaceAll("#", "%23") + "." + action + ".do"); try {/* w w w . j ava2 s .c o m*/ String requestData = getRequestData(); // Add parameters values to the request data to be sent. if (parameterData != null) { requestData = requestData != null && requestData.length() > 0 ? (requestData + "&" + parameterData) : parameterData; } if (requestData != null) { builder.setHeader("Content-type", "application/x-www-form-urlencoded"); } builder.setHeader("accept", "application/json"); builder.sendRequest(requestData, new RequestCallback() { public void onError(Request request, Throwable exception) { com.google.gwt.user.client.Window.alert("Cannot create connection"); linker.loaded(); actionExecuted(500); } @SuppressWarnings("unchecked") public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() != 200) { com.google.gwt.user.client.Window .alert("Cannot contact remote server : error " + response.getStatusCode()); } try { JSONObject jsondata = JSONParser.parseStrict(response.getText()).isObject(); if (jsondata.get("refreshData") != null) { JSONObject refreshData = jsondata.get("refreshData").isObject(); @SuppressWarnings("rawtypes") Map data = new HashMap(); for (String s : refreshData.keySet()) { data.put(s, refreshData.get(s)); } linker.refresh(data); } if (jsondata.get("messageDisplay") != null) { JSONObject object = jsondata.get("messageDisplay").isObject(); String title = object.get("title").isString().stringValue(); String text = object.get("text").isString().stringValue(); String type = object.get("messageBoxType").isString().stringValue(); if ("alert".equals(type)) { MessageBox.alert(title, text, null); } else { MessageBox.info(title, text, null); } } } catch (Exception e) { // Ignore } linker.loaded(); actionExecuted(response.getStatusCode()); } }); } catch (RequestException e) { // Code omitted for clarity } } }
From source file:org.jboss.as.console.client.shared.deployment.NewDeploymentWizard.java
License:Open Source License
private void assignDeploymentName(final DeploymentReference deployment) { String requestJSO;// w w w.j a v a 2 s . com if (isUpdate) { requestJSO = makeFullReplaceJSO(deployment); } else { requestJSO = makeAddJSO(deployment); } //System.out.println("requestJSO=" + requestJSO); RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, Console.getBootstrapContext().getProperty(BootstrapContext.DOMAIN_API)); rb.setHeader(HEADER_CONTENT_TYPE, APPLICATION_JSON); try { final PopupPanel loading = Feedback.loading(Console.CONSTANTS.common_label_plaseWait(), Console.CONSTANTS.common_label_requestProcessed(), new Feedback.LoadingCallback() { @Override public void onCancel() { } }); rb.sendRequest(requestJSO, new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { //System.out.println("response="); //System.out.println(response.getText()); if (200 != response.getStatusCode()) { onDeploymentFailed(deployment, response); return; } loading.hide(); window.hide(); presenter.refreshDeployments(); String operation = Console.CONSTANTS.common_label_addContent(); if (isUpdate) operation = Console.CONSTANTS.common_label_updateContent(); Console.info(Console.CONSTANTS.common_label_success() + ": " + operation + ": " + deployment.getName()); } @Override public void onError(Request request, Throwable exception) { Console.error( Console.CONSTANTS.common_error_deploymentFailed() + ": " + exception.getMessage()); Log.error(Console.CONSTANTS.common_error_deploymentFailed() + ": ", exception); } }); } catch (RequestException e) { Console.error(Console.CONSTANTS.common_error_deploymentFailed() + ": " + e.getMessage()); Log.error(Console.CONSTANTS.common_error_unknownError(), e); } }
From source file:org.jboss.as.console.client.shared.dispatch.impl.DMRHandler.java
License:Open Source License
@Inject public DMRHandler(BootstrapContext bootstrap, UIConstants constants) { this.constants = constants; requestBuilder = new RequestBuilder(RequestBuilder.POST, bootstrap.getProperty(BootstrapContext.DOMAIN_API)); requestBuilder.setHeader(HEADER_ACCEPT, DMR_ENCODED); requestBuilder.setHeader(HEADER_CONTENT_TYPE, DMR_ENCODED); }
From source file:org.jboss.bpm.console.client.Authentication.java
License:Open Source License
public void login(String user, String pass) { this.username = user; this.password = pass; String formAction = config.getConsoleServerUrl() + "/rs/identity/secure/j_security_check"; RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, formAction); rb.setHeader("Content-Type", "application/x-www-form-urlencoded"); try {/*from ww w . jav a2s .com*/ rb.sendRequest("j_username=" + user + "&j_password=" + pass, new RequestCallback() { public void onResponseReceived(Request request, Response response) { ConsoleLog.debug("postLoginCredentials() HTTP " + response.getStatusCode()); if (response.getText().indexOf("HTTP 401") != -1) // HACK { if (callback != null) callback.onLoginFailed(request, new Exception("Authentication failed")); else throw new RuntimeException("Unknown exception upon login attempt"); } else if (response.getStatusCode() == 200) // it's always 200, even when the authentication fails { DeferredCommand.addCommand(new Command() { public void execute() { requestAssignedRoles(); } }); } } public void onError(Request request, Throwable t) { if (callback != null) callback.onLoginFailed(request, new Exception("Authentication failed")); else throw new RuntimeException("Unknown exception upon login attempt"); } }); } catch (RequestException e) { ConsoleLog.error("Request error", e); } }
From source file:org.jboss.bpm.console.client.Authentication.java
License:Open Source License
public static void logout(final ConsoleConfig conf) { RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, conf.getConsoleServerUrl() + "/rs/identity/sid/invalidate"); try {// ww w .j av a2 s . c o m rb.sendRequest(null, new RequestCallback() { public void onResponseReceived(Request request, Response response) { ConsoleLog.debug("logout() HTTP " + response.getStatusCode()); if (response.getStatusCode() != 200) { ConsoleLog.error(response.getText()); } } public void onError(Request request, Throwable t) { ConsoleLog.error("Failed to invalidate session", t); } }); } catch (RequestException e) { ConsoleLog.error("Request error", e); } }
From source file:org.jboss.bpm.console.client.Authentication.java
License:Open Source License
public void logoutAndReload() { RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, config.getConsoleServerUrl() + "/rs/identity/sid/invalidate"); try {//from www.jav a 2 s . c o m rb.sendRequest(null, new RequestCallback() { public void onResponseReceived(Request request, Response response) { ConsoleLog.debug("logoutAndReload() HTTP " + response.getStatusCode()); resetState(); reload(); } public void onError(Request request, Throwable t) { ConsoleLog.error("Failed to invalidate session", t); } }); } catch (RequestException e) { ConsoleLog.error("Request error", e); } }
From source file:org.jboss.bpm.console.client.engine.DeleteDeploymentAction.java
License:Open Source License
public RequestBuilder.Method getRequestMethod() { return RequestBuilder.POST; }
From source file:org.jboss.bpm.console.client.report.RenderReportAction.java
License:Open Source License
public void execute(final Controller controller, Object object) { final RenderDispatchEvent event = (RenderDispatchEvent) object; final String url = event.getDispatchUrl(); RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url); ConsoleLog.debug(RequestBuilder.POST + ": " + url); final ReportLaunchPadView view = (ReportLaunchPadView) controller.getView(ReportLaunchPadView.ID); view.reset();/*w w w .j av a2s . c o m*/ view.setLoading(true); try { controller.handleEvent(LoadingStatusAction.ON); //view.setLoading(true); String parameters = event.getParameters(); final Request request = builder.sendRequest(parameters, new RequestCallback() { public void onError(Request request, Throwable exception) { // Couldn't connect to server (could be timeout, SOP violation, etc.) handleError(controller, url, exception); controller.handleEvent(LoadingStatusAction.OFF); } public void onResponseReceived(Request request, Response response) { try { if (response.getText().indexOf("HTTP 401") != -1) // HACK { appContext.getAuthentication().handleSessionTimeout(); } else if (200 == response.getStatusCode()) { // update view view.displayReport(event.getTitle(), event.getDispatchUrl()); } else { final String msg = response.getText().equals("") ? "Unknown error" : response.getText(); handleError(controller, url, new RequestException("HTTP " + response.getStatusCode() + ": " + msg)); } } finally { controller.handleEvent(LoadingStatusAction.OFF); view.setLoading(false); } } }); // Timer to handle pending request Timer t = new Timer() { public void run() { if (request.isPending()) { request.cancel(); handleError(controller, url, new IOException("Request timeout")); } } }; t.schedule(20000); } catch (Throwable e) { // Couldn't connect to server controller.handleEvent(LoadingStatusAction.OFF); handleError(controller, url, e); view.setLoading(false); } }
From source file:org.jboss.dmr.client.dispatch.impl.DMRHandler.java
License:Open Source License
private RequestBuilder postRequestBuilder() { // lazy init, because endpointConfig.getUrl() is not initialized at construction time if (prb == null) { prb = new RequestBuilder(RequestBuilder.POST, endpointConfig.getUrl()); prb.setHeader(HEADER_ACCEPT, DMR_ENCODED); prb.setHeader(HEADER_CONTENT_TYPE, DMR_ENCODED); prb.setIncludeCredentials(true); }//w w w . j a va 2s. com return prb; }
From source file:org.jboss.errai.bus.client.framework.transports.HttpPollingHandler.java
License:Apache License
/** * Sends the given string oon the outbound communication channel (as a POST * request to the server).// w w w . j a va 2 s. co m * * @param payload * The message to send. It is sent verbatim. * @param callback * The callback to receive success or error notification. Note that * this callback IS NOT CALLED if the request is cancelled. * @param extraParameters * Extra paramets to include in the HTTP request (key is parameter name; * value is parameter value). * * @throws com.google.gwt.http.client.RequestException * if the request cannot be sent at all. */ public Request sendPollingRequest(final String payload, final Map<String, String> extraParameters, final RequestCallback callback) throws RequestException { // LogUtil.log("[bus] sendPollingRequest(" + payload + ")"); final String serviceEntryPoint; final Map<String, String> parmsMap; final boolean waitChannel; boolean activeWaitChannel = false; final Iterator<RxInfo> iterator = pendingRequests.iterator(); while (iterator.hasNext()) { final RxInfo pendingRx = iterator.next(); if (pendingRx.getRequest().isPending() && pendingRx.isWaiting()) { // LogUtil.log("[bus] ABORT SEND: " + pendingRx + " is waiting" ); // return null; activeWaitChannel = true; } if (!pendingRx.getRequest().isPending()) { iterator.remove(); } } if (!activeWaitChannel && receiveCommCallback.canWait() && !rxActive) { parmsMap = new HashMap<String, String>(extraParameters); parmsMap.put("wait", "1"); serviceEntryPoint = messageBus.getInServiceEntryPoint(); waitChannel = true; } else { parmsMap = extraParameters; serviceEntryPoint = messageBus.getOutServiceEntryPoint(); waitChannel = false; } rxActive = true; final StringBuilder extraParmsString = new StringBuilder(); for (final Map.Entry<String, String> entry : parmsMap.entrySet()) { extraParmsString.append("&").append(URL.encodePathSegment(entry.getKey())).append("=") .append(URL.encodePathSegment(entry.getValue())); } final long latencyTime = System.currentTimeMillis(); final RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(messageBus.getApplicationLocation(serviceEntryPoint)) + "?z=" + getNextRequestNumber() + "&clientId=" + URL.encodePathSegment(messageBus.getClientId()) + extraParmsString.toString()); builder.setHeader("Content-Type", "application/json; charset=utf-8"); final RxInfo rxInfo = new RxInfo(System.currentTimeMillis(), waitChannel); try { // LogUtil.log("[bus] TX: " + payload); final Request request = builder.sendRequest(payload, new RequestCallback() { @Override public void onResponseReceived(final Request request, final Response response) { if (!waitChannel) { measuredLatency = (int) (System.currentTimeMillis() - latencyTime); } pendingRequests.remove(rxInfo); callback.onResponseReceived(request, response); rxNumber++; rxActive = false; } @Override public void onError(final Request request, final Throwable exception) { pendingRequests.remove(rxInfo); callback.onError(request, exception); rxActive = false; } }); rxInfo.setRequest(request); pendingRequests.add(rxInfo); return request; } catch (RequestException e) { throw e; } }