List of usage examples for com.google.gwt.http.client URL encode
public static String encode(String decodedURL)
From source file:gov.wa.wsdot.search.client.SearchWidget.java
License:Open Source License
private void getSuggestions() { String url = JSON_URL_SUGGESTION; String searchString = SafeHtmlUtils.htmlEscape(searchSuggestBox.getText().trim().replace("'", "")); // Append the name of the callback function to the JSON URL. url += searchString;/*from ww w . ja v a 2 s . co m*/ url = URL.encode(url); getSuggestionData(url); }
From source file:gov.wa.wsdot.search.client.SearchWidget.java
License:Open Source License
/** * This method is called whenever the application's history changes. * //from ww w . j ava2 s . c o m * Calling the History.newItem(historyToken) method causes a new history entry to be * added which results in ValueChangeEvent being called as well. */ @Override public void onValueChange(ValueChangeEvent<String> event) { String url = JSON_URL; String url_flickr = JSON_URL_FLICKR; String url_highway_alerts = JSON_URL_HIGHWAY_ALERTS; String historyToken = event.getValue(); // This handles the initial GET call to the page. Rewrites the ?q= to #q= String queryParameter = Window.Location.getParameter("q"); if (queryParameter != null) { UrlBuilder urlBuilder = Window.Location.createUrlBuilder().removeParameter("q"); urlBuilder.setHash(historyToken); String location = urlBuilder.buildString(); Window.Location.replace(location); } String[] tokens = historyToken.split("&"); // e.g. #q=Ferries&p=2 Map<String, String> map = new HashMap<String, String>(); for (String string : tokens) { try { map.put(string.split("=")[0], string.split("=")[1]); } catch (ArrayIndexOutOfBoundsException e) { // TODO: Need a better way to handle this. } } String query = map.get("q"); String page = map.get("p"); if (page == null) { page = "1"; } searchSuggestBox.setText(query); String searchString = SafeHtmlUtils .htmlEscape(searchSuggestBox.getText().trim().replace("'", "").replace("\"", "")); loadingImage.setVisible(true); searchSuggestBox.setFocus(true); leftNavBoxHTMLPanel.setVisible(false); photosDisclosurePanel.setVisible(false); boostedResultsHTMLPanel.setVisible(false); alertsDisclosurePanel.setVisible(false); if (searchString.isEmpty()) { clearPage(); loadingImage.setVisible(false); bingLogoHTMLPanel.setVisible(false); } else { if (ANALYTICS_ENABLED) { Analytics.trackEvent(EVENT_TRACKING_CATEGORY, "Keywords", searchString.toLowerCase()); } clearPage(); // Append the name of the callback function to the JSON URL. url += searchString; url += "&page=" + page; url = URL.encode(url); // Append search query to Flickr url. url_flickr += searchString; url_flickr = URL.encode(url_flickr); // Send requests to remote servers with calls to JSNI methods. getSearchData(url, searchString, page); getPhotoData(url_flickr, searchString); getHighwayAlertsData(url_highway_alerts, searchString); } }
From source file:gwt.dojo.showcase.client.Showcase.java
License:Apache License
private void loadAndSwitchView(final ListItem listItem) { final RequestCallback requestCallback = new RequestCallback() { @Override// w ww . java 2s.co m public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode()) { try { // Process the response in response.getText() // fillInDemoSource(); DivElement rightPane = Document.get().getElementById("rightPane").cast(); DivElement tmpContainer = Document.get().createDivElement(); tmpContainer.setInnerHTML(response.getText()); rightPane.appendChild(tmpContainer); JsArray ws = MobileParser.parse(tmpContainer); for (int i = 0, n = ws.length(); i < n; i++) { if (ws.getJsObject(i).hasProperty("startup")) { _WidgetBase w = ws.getJsObject(i); w.startup(); } } // reparent rightPane.removeChild(tmpContainer); NodeList<Node> children = tmpContainer.getChildNodes(); for (int i = 0, n = children.getLength(); i < n; i++) { Element elem = tmpContainer.getChild(i).cast(); rightPane.appendChild(elem); } showProgressIndicator(false); Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { initView(listItem); listItem.transitionTo(listItem.getString("viewId")); // triggreTransition(listItem, // listItem.getString("id")); } }); } catch (Exception e) { Window.alert("Error: " + e); } } else { // Handle the error. Can get the status text from // response.getStatusText() onError(request, new RequestException("HTTP Error: " + response.getStatusCode())); } } @Override public void onError(Request request, Throwable exception) { Window.alert("Failed to load demo."); showProgressIndicator(false); inTransitionOrLoading = false; } }; showProgressIndicator(true); String url = listItem.getString("demourl"); RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url)); Request request = null; try { request = builder.sendRequest(null, requestCallback); } catch (RequestException e) { requestCallback.onError(request, e); } }
From source file:io.apiman.manager.ui.client.local.services.ConfigurationService.java
License:Apache License
/** * Starts a timer that will refresh the configuration's bearer token * periodically./*from www .java2s . c om*/ */ private void startTokenRefreshTimer() { Timer timer = new Timer() { @Override public void run() { GWT.log("Refreshing auth token."); //$NON-NLS-1$ final String url = GWT.getHostPageBaseURL() + "rest/tokenRefresh"; //$NON-NLS-1$ RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url)); try { builder.sendRequest(null, new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() != 200) { GWT.log("[001] Authentication token refresh failure: " + url); //$NON-NLS-1$ } else { BearerTokenCredentialsBean bean = new BearerTokenCredentialsBean(); JSONObject root = JSONParser.parseStrict(response.getText()).isObject(); bean.setToken(root.get("token").isString().stringValue()); //$NON-NLS-1$ bean.setRefreshPeriod((int) root.get("refreshPeriod").isNumber().doubleValue()); //$NON-NLS-1$ configuration.getApi().getAuth().setBearerToken(bean); } startTokenRefreshTimer(); } @Override public void onError(Request request, Throwable exception) { GWT.log("[002] Authentication token refresh failure: " + url); //$NON-NLS-1$ } }); } catch (RequestException e) { GWT.log("Authentication token refresh failed!"); //$NON-NLS-1$ } } }; timer.schedule(configuration.getApi().getAuth().getBearerToken().getRefreshPeriod() * 1000); }
From source file:io.reinert.requestor.uri.Uri.java
License:Apache License
@Override public String toString() { if (uriString == null) { StringBuilder uri = new StringBuilder(); if (scheme != null) { uri.append(scheme).append("://"); }/* www . j av a 2 s. c o m*/ if (user != null) { uri.append(URL.encode(user)); if (password != null) { uri.append(':').append(URL.encode(password)); } uri.append('@'); } if (host != null) { uri.append(host); } if (port > 0) { uri.append(':').append(port); } if (path != null) { uri.append(path); } if (query != null && !query.isEmpty()) { uri.append('?').append(query); } if (fragment != null) { uri.append('#').append(URL.encode(fragment)); } uriString = uri.toString(); } return uriString; }
From source file:it.geosdi.era.client.controllo.PrintingController.java
License:Open Source License
private void onSendRequestForPrinting(AppEvent<?> event) { String url = GWT.getHostPageBaseURL() + "pdf/print.pdf?spec=" + URL.encode(((PrintEraBean) event.data).toStringJSON()); Window.open(url, "_blank", ""); }
From source file:it.unical.inf.wsportal.client.controller.Controller.java
License:Open Source License
/** * Passes the method definition to the server side. The server invokes the method * and sends back the result as a string. */// www. j av a2 s. co m private void invokeMethod(Component component) { InputPortlet portlet = (InputPortlet) WSPortal.getInputPortletContainer().getPortlet(component); ListStore<BaseModelData> store = portlet.getInputGrid().getStore(); MethodEnvelope envelope = new MethodEnvelope(); envelope.setServiceUrl(portlet.getServiceUrl()); envelope.setMethodName(portlet.getHeading()); for (int i = 0; i < store.getCount(); i++) { String type = store.getAt(i).get("type").toString(); Object value = store.getAt(i).get("param"); envelope.addParameter(type, value); } XMLSerializer serializer = new XMLSerializer(envelope); String params = "xml=" + URL.encode(serializer.serialize()); AsynchRequest request = new AsynchRequest(AsynchRequest.POST, "../invokeMethod", params); request.setCallback(new InvokeMethod(portlet.getHeading())); try { request.send(); } catch (RequestException ex) { Toolkit.showException(ex); } }
From source file:it.unical.inf.wsportal.client.util.AsynchRequest.java
License:Open Source License
/** * Create an object that performs asynchronous call to the server. * //from ww w . j a v a 2s.c o m * @param method the HTTP method: GET or POST * @param url the URL of the server side component * @param params the query string of the URL */ public AsynchRequest(AsynchRequest.Method method, String url, String params) { super(method, URL.encode(url)); if (method.toString().equals(POST.toString())) { setHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8"); if (params != null) { setHeader("Content-length", String.valueOf(params.length())); } else { setHeader("Content-length", "0"); } setHeader("Connection", "close"); } setRequestData(params); }
From source file:n3phele.client.model.BulkGet.java
License:Open Source License
static void get(BulkGetRequest bulk, RequestCallback callback) { String url = "https://n3phele.appspot.com/resources/"; url = URL.encode(url); // Send request to server and catch any errors. RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.POST, url); builder.setHeader("Content-type", "application/x-www-form-urlencoded"); try {//from w w w. j ava 2 s . co m Request request = builder.sendRequest(bulk.toString(), callback); } catch (RequestException e) { //displayError("Couldn't retrieve JSON "+e.getMessage()); } }
From source file:n3phele.client.presenter.AbstractActivityProgressActivity.java
License:Open Source License
public AbstractActivityProgressActivity(String name, ClientFactory factory, ActivityView activityView) { super();// w w w .j a va2 s . c om this.name = name; this.cacheManager = factory.getCacheManager(); this.placeController = factory.getPlaceController(); this.display = activityView; this.historyMapper = factory.getHistoryMapper(); this.collectionUrl = URL.encode(cacheManager.ServiceAddress + "progress"); }