List of usage examples for com.google.gwt.http.client RequestBuilder setTimeoutMillis
public void setTimeoutMillis(int timeoutMillis)
From source file:com.github.nmorel.gwtjackson.rest.api.RestRequestBuilder.java
License:Apache License
public Request send() { if (null == method) { throw new IllegalArgumentException("The method is required"); }/* ww w. ja v a 2 s . c om*/ if (null == url) { throw new IllegalArgumentException("The url is required"); } String urlWithParams = url; if (null != pathParams && !pathParams.isEmpty()) { for (Entry<String, Object> pathParam : pathParams.entrySet()) { urlWithParams = urlWithParams.replace("{" + pathParam.getKey() + "}", pathParam.getValue() == null ? "" : pathParam.getValue().toString()); } } StringBuilder urlBuilder = new StringBuilder(applicationPath); if (!applicationPath.endsWith("/") && !urlWithParams.startsWith("/")) { urlBuilder.append('/'); } urlBuilder.append(urlWithParams); if (null != queryParams && !queryParams.isEmpty()) { boolean first = true; for (Entry<String, List<Object>> params : queryParams.entrySet()) { String name = URL.encodeQueryString(params.getKey()); if (null != params.getValue() && !params.getValue().isEmpty()) { for (Object param : params.getValue()) { if (first) { urlBuilder.append('?'); first = false; } else { urlBuilder.append('&'); } urlBuilder.append(name); if (null != param) { urlBuilder.append('='); urlBuilder.append(URL.encodeQueryString(param.toString())); } } } } } RequestBuilder builder = new RequestBuilder(method, urlBuilder.toString()); builder.setHeader("Content-Type", "application/json; charset=utf-8"); builder.setHeader("Accept", "application/json"); if (null != headers && !headers.isEmpty()) { for (Entry<String, String> header : headers.entrySet()) { builder.setHeader(header.getKey(), header.getValue()); } } if (null != user) { builder.setUser(user); } if (null != password) { builder.setPassword(password); } if (null != includeCredentials) { builder.setIncludeCredentials(includeCredentials); } if (null != timeoutMillis) { builder.setTimeoutMillis(timeoutMillis); } if (null != body) { if (null != bodyConverter) { builder.setRequestData(bodyConverter.write(body)); } else { builder.setRequestData(body.toString()); } } builder.setCallback(new RestRequestCallback<R>(responseConverter, callback)); try { return builder.send(); } catch (RequestException e) { throw new RestException(e); } }
From source file:com.google.gwt.examples.http.client.TimeoutExample.java
public static void doGetWithTimeout(String url) { RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url); try {// w w w . j a v a 2s . c o m /* * wait 2000 milliseconds for the request to complete */ builder.setTimeoutMillis(2000); Request response = builder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable exception) { if (exception instanceof RequestTimeoutException) { // handle a request timeout } else { // handle other request errors } } public void onResponseReceived(Request request, Response response) { // code omitted for clarity } }); } catch (RequestException e) { Window.alert("Failed to send the request: " + e.getMessage()); } }
From source file:com.gwtplatform.dispatch.rest.client.core.DefaultRequestBuilderFactory.java
License:Apache License
@Override public <A extends RestAction<?>> RequestBuilder build(A action, String securityToken) throws ActionException { Method httpMethod = HTTP_METHOD_TO_REQUEST_BUILDER.get(action.getHttpMethod()); String url = uriFactory.buildUrl(action); RequestBuilder requestBuilder = httpRequestBuilderFactory.create(httpMethod, url); requestBuilder.setTimeoutMillis(requestTimeoutMs); headerFactory.buildHeaders(requestBuilder, action, securityToken); bodyFactory.buildBody(requestBuilder, action); return requestBuilder; }
From source file:com.gwtplatform.dispatch.rest.client.DefaultRestRequestBuilderFactory.java
License:Apache License
@Override public <A extends RestAction<?>> RequestBuilder build(A action, String securityToken) throws ActionException { Method httpMethod = HTTP_METHOD_TO_REQUEST_BUILDER.get(action.getHttpMethod()); String url = buildUrl(action); String xsrfToken = action.isSecured() ? securityToken : ""; RequestBuilder requestBuilder = httpRequestBuilderFactory.create(httpMethod, url); requestBuilder.setTimeoutMillis(requestTimeoutMs); buildHeaders(requestBuilder, xsrfToken, action); buildBody(requestBuilder, action);// w w w. ja v a 2 s. c o m return requestBuilder; }
From source file:com.mecatran.otp.gwt.client.utils.HttpUtils.java
License:Open Source License
public static <T> void downloadData(String url, String contentType, final DownloadListener<T> listener, final DataConverter<T> converter, int timeoutMs) { try {// w w w . ja va 2s . c o m RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url); builder.setTimeoutMillis(timeoutMs); builder.setHeader("Accept", contentType); builder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable exception) { listener.onFailure(exception.getLocalizedMessage()); } public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode()) { try { T t = converter.convert(response.getText()); listener.onSuccess(t); } catch (Exception e) { listener.onFailure(e.getLocalizedMessage()); } } else { listener.onFailure(response.getStatusText()); } } }); } catch (RequestException e1) { listener.onFailure(e1.getLocalizedMessage()); } }
From source file:com.oracle.wci.user.registration.client.AsyncCall.java
License:Apache License
/** * Do post information via AJAX call to the server. * //from ww w.j ava 2 s . co m * @param url * @param requestData */ public static void doPost(String url, String requestData) { RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url); try { builder.setTimeoutMillis(MAX_TIMEOUT); // Request response = builder.sendRequest(requestData, new RequestCallback() { public void onResponseReceived(Request request, Response response) { } public void onError(Request request, Throwable exception) { if (exception instanceof RequestTimeoutException) { Window.alert(((RequestTimeoutException) exception).getMessage()); } else { Window.alert(exception.getMessage()); } } }); } catch (com.google.gwt.http.client.RequestException e) { Window.alert("Unable to send the request: " + e.getMessage()); } }
From source file:com.seanchenxi.gwt.wordpress.json.core.request.JRequestBuilderImpl.java
License:Apache License
@Override public <M extends JModel> JRequest requestObject(JRequestURL url, AsyncCallback<M> callback) { RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url.setPrefix(jServicePath)); builder.setTimeoutMillis(timeout); try {/* w w w . j av a 2 s. c om*/ Log.finest("call " + url.getMethodName() + " by: " + builder.getUrl()); Request request = builder.sendRequest(null, new JAsyncCallback<M>(callback)); return new JRequestImpl(request); } catch (RequestException e) { if (callback != null) callback.onFailure(e); } return null; }
From source file:com.smartgwt.mobile.client.data.DataSource.java
License:Open Source License
@SGWTInternal protected void _sendGWTRequest(DSRequest dsRequest) { final int transactionNum = com.smartgwt.mobile.client.rpc.RPCManager._getNextTransactionNum(); dsRequest._setTransactionNum(transactionNum); // For the time being, the request ID and transactionNum are the same. dsRequest.setRequestId(Integer.toString(transactionNum)); final boolean strictJSON = Canvas._booleanValue(getStrictJSON(), false); final DSOperationType opType = dsRequest.getOperationType(); final OperationBinding opBinding = getOperationBinding(dsRequest); final DSDataFormat dataFormat; if (opBinding == null) dataFormat = DSDataFormat.JSON;//from w ww . j a va2 s . com else if (opBinding.getDataFormat() != null) dataFormat = opBinding.getDataFormat(); else dataFormat = DSDataFormat.JSON; assert dataFormat != null; DSProtocol protocol; if (opBinding != null && opBinding.getDataProtocol() != null) { protocol = opBinding.getDataProtocol(); } else { protocol = getDataProtocol(); if (protocol == null) { protocol = (opType == null || opType == DSOperationType.FETCH) ? null : DSProtocol.POSTMESSAGE; } } final Object originalData = dsRequest.getData(); Object transformedData; switch (protocol == null ? DSProtocol.GETPARAMS : protocol) { case GETPARAMS: case POSTPARAMS: transformedData = transformRequest(dsRequest); if (transformedData == null) transformedData = Collections.EMPTY_MAP; else if (!(transformedData instanceof Map)) { // TODO Issue a warning. transformedData = Collections.EMPTY_MAP; } break; case POSTMESSAGE: transformedData = transformRequest(dsRequest); if (!(transformedData instanceof String)) { if (dataFormat != DSDataFormat.JSON) { throw new UnsupportedOperationException( "Only serialization of DSRequests in JSON format is supported."); } transformedData = dsRequest._serialize(strictJSON); if (dsRequest.getContentType() == null) { // For best interoperability with ASP.NET AJAX services, send Content-Type:application/json. // http://weblogs.asp.net/scottgu/archive/2007/04/04/json-hijacking-and-how-asp-net-ajax-1-0-mitigates-these-attacks.aspx dsRequest.setContentType("application/json;charset=UTF-8"); } } break; default: assert protocol != null; throw new UnsupportedOperationException( "In transforming the DSRequest, failed to handle case: protocol:" + protocol.getValue()); } if (transformedData != dsRequest) { dsRequest.setData(transformedData); } dsRequest.setOriginalData(originalData); if (dsRequest.getDataSource() == null) dsRequest.setDataSource(getID()); final DSRequest finalDSRequest = dsRequest; assert finalDSRequest.getOperationType() == opType; if (protocol == null) { assert opType == DSOperationType.FETCH; if (transformedData == null || (transformedData instanceof Map && ((Map<?, ?>) transformedData).isEmpty())) { protocol = DSProtocol.GETPARAMS; } else { protocol = DSProtocol.POSTMESSAGE; transformedData = dsRequest._serialize(strictJSON); if (dsRequest.getContentType() == null) { dsRequest.setContentType("application/json;charset=UTF-8"); } } } URIBuilder workBuilder; { String work = finalDSRequest.getDataURL(); if (work == null) { if (opType != null) { switch (opType) { case FETCH: work = getFetchDataURL(); break; case ADD: work = getAddDataURL(); break; case UPDATE: work = getUpdateDataURL(); break; case REMOVE: work = getRemoveDataURL(); break; case VALIDATE: work = getValidateDataURL(); break; case CUSTOM: work = getCustomDataURL(); break; } } // common url if (work == null) { work = getDataURL(); // construct default url if (work == null) { work = RPCManager.getActionURL(); if (work.endsWith("/")) { work = work.substring(0, work.length() - 1); } } } } workBuilder = new URIBuilder(work); } // build up the query string final DateTimeFormat datetimeFormat = finalDSRequest._getDatetimeFormat(); { Map<String, Object> params = finalDSRequest.getParams(); if (protocol == DSProtocol.GETPARAMS || protocol == DSProtocol.POSTPARAMS) { if (params == null) params = new LinkedHashMap<String, Object>(); if (protocol == DSProtocol.GETPARAMS) { assert transformedData instanceof Map; @SuppressWarnings("unchecked") final Map<String, Object> m = (Map<String, Object>) transformedData; params.putAll(m); } if (getSendMetaData()) { String metaDataPrefix = getMetaDataPrefix(); if (metaDataPrefix == null) metaDataPrefix = "_"; params.put(metaDataPrefix + "operationType", opType); params.put(metaDataPrefix + "operationId", finalDSRequest.getOperationId()); params.put(metaDataPrefix + "startRow", finalDSRequest.getStartRow()); params.put(metaDataPrefix + "endRow", finalDSRequest.getEndRow()); params.put(metaDataPrefix + "sortBy", finalDSRequest._getSortByString()); params.put(metaDataPrefix + "useStrictJSON", Boolean.TRUE); params.put(metaDataPrefix + "textMatchStyle", finalDSRequest.getTextMatchStyle()); params.put(metaDataPrefix + "oldValues", finalDSRequest.getOldValues()); params.put(metaDataPrefix + "componentId", finalDSRequest.getComponentId()); params.put(metaDataPrefix + "dataSource", dsRequest.getDataSource()); params.put("isc_metaDataPrefix", metaDataPrefix); } params.put("isc_dataFormat", dataFormat.getValue()); } if (params != null) { for (final Map.Entry<String, Object> e : params.entrySet()) { workBuilder.setQueryParam(e.getKey(), e.getValue(), strictJSON, false, datetimeFormat); } } } // automatically add the data format even to user-provided dataURLs unless they contain the param already if (!workBuilder.containsQueryParam("isc_dataFormat")) { workBuilder.appendQueryParam("isc_dataFormat", dataFormat.getValue()); } if (protocol == DSProtocol.POSTPARAMS) { assert transformedData instanceof Map; @SuppressWarnings("unchecked") final Map<String, Object> m = (Map<String, Object>) transformedData; String requestContentType = finalDSRequest.getContentType(); if (requestContentType != null) requestContentType = requestContentType.trim(); if (requestContentType == null || requestContentType.startsWith("application/x-www-form-urlencoded")) { URIBuilder postBodyBuilder = new URIBuilder(""); for (final Map.Entry<String, Object> e : m.entrySet()) { postBodyBuilder.setQueryParam(e.getKey(), e.getValue(), strictJSON, false, datetimeFormat); } // Exclude the '?'. transformedData = postBodyBuilder.toString().substring(1); } //else if (requestContentType.startsWith("multipart/form-data")) {} // TODO else { throw new IllegalArgumentException( "Request content type '" + requestContentType + "' is not supported."); } } RequestBuilder.Method httpMethod = getHttpMethod(finalDSRequest.getHttpMethod()); if (httpMethod == null) { if (protocol == DSProtocol.GETPARAMS) httpMethod = RequestBuilder.GET; else if (protocol == DSProtocol.POSTPARAMS || protocol == DSProtocol.POSTMESSAGE) { httpMethod = RequestBuilder.POST; } else { if (opType == null || opType == DSOperationType.FETCH) { httpMethod = RequestBuilder.GET; } else { httpMethod = RequestBuilder.POST; } } } else if (httpMethod == RequestBuilder.GET) { if (protocol == DSProtocol.POSTPARAMS || //protocol == DSProtocol.POSTXML protocol == DSProtocol.POSTMESSAGE) { // TODO Warn that GET requests do not support bodies. httpMethod = RequestBuilder.POST; } } String requestContentType = finalDSRequest.getContentType(); if (requestContentType != null) { if (httpMethod == RequestBuilder.GET) { // TODO Warn that GET requests do not support bodies. requestContentType = null; } } else { if (protocol == DSProtocol.POSTPARAMS) requestContentType = "application/x-www-form-urlencoded"; //else if (protocol == DSProtocol.POSTXML) requestContentType = "text/xml"; } final RequestBuilder rb = new RequestBuilder(httpMethod, workBuilder.toString()); final Integer timeoutMillis = finalDSRequest.getTimeout(); rb.setTimeoutMillis(timeoutMillis == null ? RPCManager._getDefaultTimeoutMillis() : Math.max(1, timeoutMillis.intValue())); final String authorization = finalDSRequest.getAuthorization(); if (authorization != null) rb.setHeader("Authorization", authorization); final Map<String, String> httpHeaders = finalDSRequest.getHttpHeaders(); if (httpHeaders != null) { for (Map.Entry<String, String> entry : httpHeaders.entrySet()) { rb.setHeader(entry.getKey(), entry.getValue()); } } if (dataFormat == DSDataFormat.XML) { rb.setHeader("Accept", "application/xml,text/xml,*/*"); } else if (dataFormat == DSDataFormat.JSON) { rb.setHeader("Accept", "application/json,*/*"); } if (requestContentType != null) { rb.setHeader("Content-Type", requestContentType); } if (httpMethod != RequestBuilder.GET) { switch (protocol) { case POSTPARAMS: // `transformedData` has already been created and is now a String. case POSTMESSAGE: rb.setRequestData((String) transformedData); break; case GETPARAMS: // Already handled earlier when the query params were appended to `workBuilder'. break; default: throw new UnsupportedOperationException( "In setting the request data, failed to handle case protocol:" + protocol); } } rb.setCallback(new RequestCallback() { @Override public void onError(Request request, Throwable exception) { final DSResponse dsResponse = new DSResponse(finalDSRequest); final int status; if (exception instanceof RequestTimeoutException) status = RPCResponse.STATUS_SERVER_TIMEOUT; else status = RPCResponse.STATUS_FAILURE; dsResponse.setStatus(status); onError(dsResponse); } private void onError(DSResponse dsResponse) { final DSRequest dsRequest = finalDSRequest; final boolean errorEventCancelled = ErrorEvent._fire(DataSource.this, dsRequest, dsResponse); if (!errorEventCancelled) RPCManager._handleError(dsResponse, dsRequest); } @Override public void onResponseReceived(Request request, Response response) { assert response != null; String responseText = response.getText(); if (responseText == null) responseText = ""; assert responseText != null; int httpResponseCode = response.getStatusCode(); final HTTPHeadersMap responseHTTPHeaders = new HTTPHeadersMap(); for (final Header h : response.getHeaders()) { if (h != null) { responseHTTPHeaders.put(h.getName(), h.getValue()); } } int status = 0; if (0 == httpResponseCode || // file:// requests (e.g. if Showcase is packaged with PhoneGap.) (200 <= httpResponseCode && httpResponseCode < 300) || httpResponseCode == 304) // 304 Not Modified { status = RPCResponse.STATUS_SUCCESS; } else { status = RPCResponse.STATUS_FAILURE; final DSResponse errorResponse = new DSResponse(finalDSRequest); errorResponse.setStatus(RPCResponse.STATUS_FAILURE); errorResponse.setHttpResponseCode(httpResponseCode); errorResponse._setHttpHeaders(responseHTTPHeaders); onError(errorResponse); return; } Object rawResponse; final DSResponse dsResponse; String origResponseContentType = responseHTTPHeaders.get("Content-Type"); if (origResponseContentType == null || (origResponseContentType = origResponseContentType.trim()).length() == 0) { origResponseContentType = "application/octet-stream"; } String responseContentType = origResponseContentType; // remove the media type parameter if present // http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7 final int semicolonPos = responseContentType.indexOf(';'); if (semicolonPos != -1) { responseContentType = responseContentType.substring(0, semicolonPos).trim(); if (responseContentType.length() == 0) responseContentType = "application/octet-stream"; } if (dataFormat == DSDataFormat.CUSTOM) { rawResponse = responseText; dsResponse = new DSResponse(finalDSRequest, status); dsResponse.setHttpResponseCode(httpResponseCode); dsResponse._setHttpHeaders(responseHTTPHeaders); dsResponse.setContentType(origResponseContentType); transformResponse(dsResponse, finalDSRequest, responseText); } else { if (dataFormat == DSDataFormat.XML) { final Element rootEl; if (responseText.isEmpty()) { rawResponse = rootEl = null; dsResponse = new DSResponse(finalDSRequest, status); } else { final Document document; try { document = XMLParser.parse(responseText); } catch (DOMParseException ex) { onError(request, ex); return; } rootEl = document.getDocumentElement(); rawResponse = rootEl; dsResponse = new DSResponse(finalDSRequest, status, rootEl); String dataTagName, recordName; if (opBinding == null) { dataTagName = _getDataTagName(); recordName = null; } else { dataTagName = opBinding._getDataTagName(_getDataTagName()); recordName = opBinding.getRecordName(); } if (recordName == null) recordName = _getRecordName(); final Element dataEl = extractDataElement(rootEl, dataTagName); final List<Element> recordNodes = extractRecordElements(dataEl, recordName); if (recordNodes != null && !recordNodes.isEmpty()) { final RecordList records = extractRecordList(recordNodes); dsResponse.setData(records); } else if (rootEl.equals(dataEl)) { dsResponse._setData(XMLUtil.getTextContent(dataEl)); } } dsResponse.setHttpResponseCode(httpResponseCode); dsResponse._setHttpHeaders(responseHTTPHeaders); transformResponse(dsResponse, finalDSRequest, rootEl); } else { String jsonPrefix = getJsonPrefix(); if (jsonPrefix == null) jsonPrefix = ""; String jsonSuffix = getJsonSuffix(); if (jsonSuffix == null) jsonSuffix = ""; // auto-detect default wrapper text returned by RestHandler if (responseText.startsWith(jsonPrefix) && responseText.endsWith(jsonSuffix)) { responseText = responseText.substring(jsonPrefix.length(), responseText.length() - jsonSuffix.length()); responseContentType = "application/json"; } if (dataFormat == DSDataFormat.JSON) { if (responseText.isEmpty()) { rawResponse = null; dsResponse = new DSResponse(finalDSRequest, status); } else { JSONObject responseObj; try { responseObj = JSONParser.parseLenient(responseText).isObject(); } catch (JSONException ex) { onError(request, ex); return; } if (responseObj != null && responseObj.containsKey("response")) { JSONValue val = responseObj.get("response"); responseObj = (val == null ? null : val.isObject()); } rawResponse = responseObj; dsResponse = new DSResponse(finalDSRequest, status, responseObj); if (responseObj != null && responseObj.containsKey("data")) { final JSONValue dataVal = responseObj.get("data"); assert dataVal != null; final JSONString dataStr = dataVal.isString(); if (dataStr != null) { dsResponse._setData(dataStr.stringValue()); } else { JSONArray dataArr = dataVal.isArray(); if (dataArr == null) { JSONObject datumObj = dataVal.isObject(); if (datumObj != null) { dataArr = new JSONArray(); dataArr.set(0, datumObj); } } if (dataArr != null) { final RecordList records = extractRecordList(dataArr); dsResponse.setData(records); } } } } dsResponse.setHttpResponseCode(httpResponseCode); dsResponse._setHttpHeaders(responseHTTPHeaders); transformResponse(dsResponse, finalDSRequest, rawResponse); } else { throw new UnsupportedOperationException("Unhandled dataFormat:" + dataFormat); } } } if (dsResponse.getInvalidateCache()) { //invalidateDataSourceDataChangedHandlers(finalDSRequest, dsResponse); } status = dsResponse.getStatus(); if (status >= 0) { DSDataChangedEvent.fire(DataSource.this, dsResponse, finalDSRequest); } else { // Unless it was a validation error, or the request specified willHandleError, // go through centralized error handling (if alerting the failure string // can be dignified with such a name!) if (status != -4 && !finalDSRequest._getWillHandleError()) { onError(dsResponse); return; } } // fireResponseCallbacks final DSCallback callback = finalDSRequest.getCallback(), afterFlowCallback = finalDSRequest._getAfterFlowCallback(); if (callback != null) { callback.execute(dsResponse, rawResponse, finalDSRequest); } if (afterFlowCallback != null && afterFlowCallback != callback) { afterFlowCallback.execute(dsResponse, rawResponse, finalDSRequest); } } }); try { rb.send(); } catch (RequestException re) { re.printStackTrace(); } ++_numDSRequestsSent; }
From source file:com.square.client.gwt.client.presenter.personne.PersonneRelationsModePresenter.java
License:Open Source License
@Override public void onBind() { view.getBtAjouterRelationGenerale().addClickHandler(new ClickHandler() { @Override//from w w w . j av a2 s .com public void onClick(ClickEvent event) { if (idNaturePersonne != null && (constantes.getIdNaturePersonneVivier().equals(idNaturePersonne) || constantes.getIdNaturePersonneBeneficiaireVivier().equals(idNaturePersonne))) { view.afficherPopupErreur( new ErrorPopupConfiguration(presenterConstants.ajoutRelationVivierImpossible())); } else { if (filtreGroupements != null) { if (personneRelationsFamillePopupPresenter == null) { personneRelationsFamillePopupPresenter = addChildPresenter( new PersonneRelationsPopupPresenter(eventBus, personneRpcService, personnePhysiqueRpcService, personneMoraleRpcService, dimensionRpcService, new PersonneRelationPopupViewImpl(constantes.isHasRoleAdmin()), constantes, idPersonne, nomPersonne, filtreGroupements, filtrePasDansGroupements, typePersonneSource, deskBar, aideService)); personneRelationsFamillePopupPresenter.addEventHandlerToLocalBus( SimpleValueChangeEvent.TYPE, new SimpleValueChangeEventHandler<String>() { @Override public void onValueChange(SimpleValueChangeEvent<String> event) { switchModeEdition(modeCourant); } }); personneRelationsFamillePopupPresenter.showPresenter(null); } else { personneRelationsFamillePopupPresenter.afficherPopupAjoutRelation(); } } if (filtrePasDansGroupements != null) { if (personneRelationsPopupPresenter == null) { personneRelationsPopupPresenter = addChildPresenter(new PersonneRelationsPopupPresenter( eventBus, personneRpcService, personnePhysiqueRpcService, personneMoraleRpcService, dimensionRpcService, new PersonneRelationPopupViewImpl(constantes.isHasRoleAdmin()), constantes, idPersonne, nomPersonne, filtreGroupements, filtrePasDansGroupements, typePersonneSource, deskBar, aideService)); personneRelationsPopupPresenter.addEventHandlerToLocalBus(SimpleValueChangeEvent.TYPE, new SimpleValueChangeEventHandler<String>() { @Override public void onValueChange(SimpleValueChangeEvent<String> event) { switchModeEdition(modeCourant); } }); personneRelationsPopupPresenter.showPresenter(null); } else { personneRelationsPopupPresenter.afficherPopupAjoutRelation(); } } } } }); view.getBtEnregistrerRelationGenerale().addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (personneRelationsPresenter.isDatesValides()) { personneRelationsPresenter.modifierRelations(); } } }); view.btChangementDeMode().addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (modeCourant == AppControllerConstants.MODE_RELATION_EDITION) { switchModeEdition(AppControllerConstants.MODE_RELATION_GRAPHIQUE); } else { switchModeEdition(AppControllerConstants.MODE_RELATION_EDITION); } } }); // Tentative de connexion a internet pour dterminer si la visualisation est disponible. view.afficherChangementMode(false); final RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, "http://www.google.fr"); rb.setHeader("Access-Control-Allow-Origin", "http://www.google.fr"); final int timeout = 15000; rb.setTimeoutMillis(timeout); rb.setCallback(new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { if (response != null) { final Runnable onLoadCallback = new Runnable() { public void run() { view.afficherChangementMode(true); } }; VisualizationUtils.loadVisualizationApi(onLoadCallback, OrgChart.PACKAGE); } } @Override public void onError(Request request, Throwable exception) { } }); try { rb.send(); } catch (RequestException e) { GWT.log("", e); } }
From source file:com.square.composant.contrat.personne.morale.square.client.presenter.ContratsPersonneMoralePresenter.java
License:Open Source License
/** Charge les infos des contrats. */ private void chargerInfosContrat() { // Chargement des contrats de la personne view.afficherLoadingPopup(new LoadingPopupConfiguration(presenterConstants.chargementListeContrats())); // Cration du callback final AsyncCallback<InfosContratsPersonneMoraleModel> asyncCallback = new AsyncCallback<InfosContratsPersonneMoraleModel>() { @Override// ww w . jav a2 s.c o m public void onSuccess(final InfosContratsPersonneMoraleModel result) { view.onRpcServiceSuccess(); // Tentative de connexion a internet pour dterminer si la visualisation est disponible. final RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, "http://www.google.fr"); rb.setHeader("Access-Control-Allow-Origin", "http://www.google.fr"); final int timeout = 15000; rb.setTimeoutMillis(timeout); rb.setCallback(new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { GWT.log("response : " + response); if (response != null) { final Runnable onLoadCallback = new Runnable() { public void run() { // Construction du camembert reprsentant les populations construireDonneesPopulation(result.getSyntheseContrat().getPopulation()); } }; VisualizationUtils.loadVisualizationApi(onLoadCallback, "corechart"); } } @Override public void onError(Request request, Throwable exception) { } }); try { rb.send(); } catch (RequestException e) { GWT.log("", e); } // Chargement des infos initInfosContrats(result); final int nbContratsCharges = result.getListeContrats().size(); fireEventLocalBus(new ContratsPersonneMoraleChargesEvent(nbContratsCharges)); } @Override public void onFailure(Throwable caught) { view.onRpcServiceFailure(new ErrorPopupConfiguration(caught)); } }; contratServiceRpc.getInfosContratPersonneMorale(idPersonneMorale, asyncCallback); }