List of usage examples for com.google.gwt.http.client RequestBuilder setRequestData
public void setRequestData(String requestData)
From source file:org.bonitasoft.web.toolkit.client.data.api.request.HttpRequest.java
License:Open Source License
/** * Send the HTTP request with data/* w w w. j a v a2s . c o m*/ * * @param method * The method to use between RequestBuilder.GET, RequestBuilder.POST, RequestBuilder.PUT, RequestBuilder.DELETE * @param callback * The APICallback to call onSuccess or onError. * @param url * The URL of the API * @param datas * The data to send */ public void send(final Method method, final String url, final String datas, final String contentType, final HttpCallback callback) { final RequestBuilder builder = new RequestBuilder(method, url); if (datas != null) { builder.setRequestData(datas); } if (contentType != null) { builder.setHeader("Content-Type", (contentType != null ? contentType : "text/plain") + ";charset=UTF-8"); } if (UserSessionVariables.getUserVariable(UserSessionVariables.API_TOKEN) != null) { builder.setHeader("X-Bonita-API-Token", UserSessionVariables.getUserVariable(UserSessionVariables.API_TOKEN)); } builder.setTimeoutMillis(30000); builder.setCallback(callback); Request request = null; try { request = builder.send(); } catch (final RequestException e) { callback.onError(request, e); } }
From source file:org.cleanlogic.ol4gwt.showcase.examples.VectorWFSGetFeature.java
License:Apache License
@Override public void buildPanel() { StyleOptions styleOptions = new StyleOptions(); styleOptions.stroke = StrokeStyle.create(Color.create(0, 0, 255, 1.0), 2); VectorLayerOptions vectorLayerOptions = new VectorLayerOptions(); vectorLayerOptions.source = vectorSource; // vectorLayerOptions.style = new Style[] {new Style(styleOptions)}; VectorLayer vectorLayer = new VectorLayer(vectorLayerOptions); BingMapsSourceOptions bingMapsSourceOptions = new BingMapsSourceOptions(); bingMapsSourceOptions.imagerySet = "Aerial"; bingMapsSourceOptions.key = "AkGbxXx6tDWf1swIhPJyoAVp06H0s0gDTYslNWWHZ6RoPqMpB9ld5FY1WutX8UoF"; TileLayer raster = TileLayer.create(new BingMapsSource(bingMapsSourceOptions)); ViewOptions viewOptions = new ViewOptions(); viewOptions.center = Coordinate.create(-8908887.277395891, 5381918.072437216); viewOptions.maxZoom = 19;/* w w w. j ava 2 s . c om*/ viewOptions.zoom = 12; MapOptions mapOptions = new MapOptions(); mapOptions.layers = new Collection<>(new BaseLayer[] { raster, vectorLayer }); mapOptions.view = new View(viewOptions); final MapPanel mapPanel = new MapPanel(mapOptions); mapPanel.setHeight("400px"); Filter filter = FilterUtils.and(new IsLikeFilter("name", "Mississippi*"), new EqualToFilter("waterway", "riverbank")); GetFeatureOptions getFeatureOptions = new GetFeatureOptions(); getFeatureOptions.srsName = "EPSG:3857"; getFeatureOptions.featureNS = "http://openstreemap.org"; getFeatureOptions.featurePrefix = "osm"; getFeatureOptions.featureTypes = new String[] { "water_areas" }; getFeatureOptions.outputFormat = "application/json"; getFeatureOptions.filter = filter; WFSFormat wfsFormat = new WFSFormat(); Node node = wfsFormat.writeGetFeature(getFeatureOptions); RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, "https://ahocevar.com/geoserver/wfs"); requestBuilder.setRequestData(new XMLSerializer().serializeToString(node)); requestBuilder.setCallback(new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { GeoJSONFormat format = new GeoJSONFormat(); Feature[] features = format.readFeatures(response.getText()); vectorSource.addFeatures(features); mapPanel.getMap().getView().fit(vectorSource.getExtent()); } @Override public void onError(Request request, Throwable throwable) { GWT.log(throwable.toString()); } }); contentPanel.add(new HTML( "<p>This example generates a GetFeature request which uses a PropertyIsEqualTo and a PropertyIsLike filter, and then posts the request to load the features that match the query.</p>")); contentPanel.add(mapPanel); initWidget(contentPanel); try { requestBuilder.send(); } catch (RequestException ex) { GWT.log(ex.getLocalizedMessage()); } }
From source file:org.emfjson.gwt.handlers.HttpHandler.java
License:Open Source License
@Override public void store(URI uri, byte[] bytes, Map<?, ?> options, final Callback<Map<?, ?>> callback) { RequestBuilder builder = new RequestBuilder(RequestBuilder.PUT, URL.encode(uri.toString())); builder.setHeader("Content-Type", "application/json"); builder.setRequestData(new String(bytes)); builder.setCallback(new RequestCallback() { @Override/*from w w w. j a va 2 s . c o m*/ public void onResponseReceived(Request request, Response response) { Map<String, Object> resultMap = new HashMap<String, Object>(); Map<String, Object> responseMap = new HashMap<String, Object>(); resultMap.put(URIConverter.OPTION_RESPONSE, responseMap); int code = response.getStatusCode(); if (code >= 200 && code < 300) { responseMap.put(URIConverter.RESPONSE_RESULT, new ByteArrayInputStream(response.getText().getBytes())); responseMap.put(URIConverter.RESPONSE_TIME_STAMP_PROPERTY, null); responseMap.put(URIConverter.RESPONSE_URI, null); callback.onSuccess(resultMap); } else { callback.onFailure(new Exception("Error " + response.getStatusCode())); } } @Override public void onError(Request request, Throwable exception) { callback.onFailure(exception); } }); try { builder.send(); } catch (RequestException e) { callback.onFailure(e); } }
From source file:org.idwebmail.client.IDRequest.java
public static String getAjaxData(String param) { final String result = "-"; RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, MainEntryPoint.getURL()); builder.setRequestData(param); //final SynchronousQueue resultQueue = new SynchronousQueue(); try {//from w w w.j av a2 s . com builder.sendRequest(null, new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { JSONObject json = (JSONObject) JSONParser.parse(response.getText()); if (MainEntryPoint.getString(json.get("data")).toLowerCase().compareTo("exito") == 0) { rs = MainEntryPoint.getString(json.get("modo")); } } @Override public void onError(Request request, Throwable exception) { } }); return rs; } catch (RequestException ex) { } return result; }
From source file:org.idwebmail.client.IDRequest.java
public static void getAjaxData(String param, final String campo, final Callback<String, String> callback) { RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, MainEntryPoint.getURL()); builder.setHeader("Content-Type", "application/x-www-form-urlencoded"); builder.setRequestData(param); try {/* w w w . j a va2 s. co m*/ builder.sendRequest(param, new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { JSONObject json = (JSONObject) JSONParser.parse(response.getText()); if (campo.isEmpty()) callback.onSuccess(response.getText()); else callback.onSuccess(MainEntryPoint.getString(json.get(campo))); } @Override public void onError(Request request, Throwable exception) { } }); } catch (RequestException e) { } }
From source file:org.jboss.dmr.client.dispatch.impl.DMRHandler.java
License:Open Source License
private RequestBuilder chooseRequestBuilder(final ModelNode operation) { RequestBuilder requestBuilder; final String op = operation.get(OP).asString(); if (READ_RESOURCE_DESCRIPTION_OPERATION.equals(op)) { String endpoint = endpointConfig.getUrl(); if (endpoint.endsWith("/")) { endpoint = endpoint.substring(0, endpoint.length() - 1); }//from w w w .ja v a 2s. c o m String descriptionUrl = endpoint + descriptionOperationToUrl(operation); requestBuilder = new RequestBuilder(RequestBuilder.GET, com.google.gwt.http.client.URL.encode(descriptionUrl)); requestBuilder.setHeader(HEADER_ACCEPT, DMR_ENCODED); requestBuilder.setHeader(HEADER_CONTENT_TYPE, DMR_ENCODED); requestBuilder.setIncludeCredentials(true); requestBuilder.setRequestData(null); } else { requestBuilder = postRequestBuilder(); requestBuilder.setRequestData(operation.toBase64String()); } // obtain the bearer token and use it to set an Authorization "Bearer" header String bearerToken = getBearerToken(); if (bearerToken != null) { requestBuilder.setHeader("Authorization", "Bearer " + bearerToken); } return requestBuilder; }
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 v a2 s.c o 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.hal.dmr.dispatch.impl.DMRHandler.java
License:Open Source License
private RequestBuilder chooseRequestBuilder(final ModelNode operation) { RequestBuilder requestBuilder; final String op = operation.get(OP).asString(); if (READ_RESOURCE_DESCRIPTION_OPERATION.equals(op)) { String endpoint = endpoints.dmr(); if (endpoint.endsWith("/")) { endpoint = endpoint.substring(0, endpoint.length() - 1); }//from ww w . j a v a 2 s . co m String descriptionUrl = endpoint + descriptionOperationToUrl(operation); requestBuilder = new RequestBuilder(RequestBuilder.GET, com.google.gwt.http.client.URL.encode(descriptionUrl)); requestBuilder.setHeader(HEADER_ACCEPT, DMR_ENCODED); requestBuilder.setHeader(HEADER_CONTENT_TYPE, DMR_ENCODED); requestBuilder.setIncludeCredentials(true); requestBuilder.setRequestData(null); } else { requestBuilder = postRequestBuilder; requestBuilder.setRequestData(operation.toBase64String()); } return requestBuilder; }
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);/*from w ww .ja v a2 s . c om*/ rb.setRequestData(requestData.toBase64String()); return rb; }
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)); }/*from ww w .j ava 2s . c o m*/ 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(); } }