@Override public String getHeader (String name) { return response.getHeader(name); } }
@Override public String getResultAsString () { return response.getText(); }
try { validateRequest(request); // Do stuff with a valid request. } catch (RequestException e) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); }
/** * Sign out. */ public static void signOut() { RequestBuilder builder = new RequestBuilder( RequestBuilder.POST, GWT.getModuleBaseURL() + "j_spring_security_logout"); try { 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 ex) { GWT.log("Exception: " + ex.getMessage()); } }
public HttpClientResponse (Response response) { this.response = response; this.status = new HttpStatus(response.getStatusCode()); }
/** * Generate token. * * @return the token */ public static String generateToken() { StringBuilder paramsUrl = new StringBuilder(); for (String key : paramsMap.keySet()) { String val = paramsMap.get(key); if (paramsUrl.length() > 0) { paramsUrl.append(PARAMS_SEPARATOR); } paramsUrl.append(key).append("=").append(URL.encodeQueryString(val)); } return paramsUrl.toString(); }
@Override public Map<String, List<String>> getHeaders () { Map<String, List<String>> headers = new HashMap<String, List<String>>(); Header[] responseHeaders = response.getHeaders(); for (int i = 0; i < responseHeaders.length; i++) { Header header = responseHeaders[i]; if (header != null) { String headerName = responseHeaders[i].getName(); List<String> headerValues = headers.get(headerName); if (headerValues == null) { headerValues = new ArrayList<String>(); headers.put(headerName, headerValues); } headerValues.add(responseHeaders[i].getValue()); } } return headers; }
@Override public void cancelHttpRequest (HttpRequest httpRequest) { HttpResponseListener httpResponseListener = listeners.get(httpRequest); Request request = requests.get(httpRequest); if (httpResponseListener != null && request != null) { request.cancel(); httpResponseListener.cancelled(); requests.remove(httpRequest); listeners.remove(httpRequest); } }
private void redirectToModule(String module) { String path = Window.Location.getPath(); if (!path.endsWith("/")) { if (path.endsWith(".html") || path.endsWith(".htm")) { int index = path.lastIndexOf('/'); path = path.substring(0, index + 1); } else { path += "/"; } } String target = path + module + "/"; Window.Location.assign(Window.Location.createUrlBuilder().setPath(target).buildString()); }
/** * Get request params from URL string and put them in map. * * @param paramsMap the params map */ public static void updateParamsFromUrl(Map<String, String> paramsMap, String paramsUrl) { if (paramsUrl != null && paramsUrl.trim().length() > 0) { String[] params = paramsUrl.split(PARAMS_SEPARATOR); for (String param : params) { String[] keyVal = param.split("="); if (keyVal != null && keyVal.length == 2) { paramsMap.put(keyVal[0], URL.decodeQueryString(keyVal[1])); } } } }
public HttpClientResponse (Response response) { this.response = response; this.status = new HttpStatus(response.getStatusCode()); }
@Override public String getResultAsString () { return response.getText(); }
/** * Download the SDK. * * @param key the SDK key */ public static void downloadSdk(String key) { String getUrl = composeUrl(KAA_SDK_SERVLET_PATH, SDK_KEY_PARAMETER + "=" + URL.encodeQueryString(key)); String url = GWT.getModuleBaseURL() + getUrl; Window.open(url, "_self", "enabled"); }
@Override public Map<String, List<String>> getHeaders () { Map<String, List<String>> headers = new HashMap<String, List<String>>(); Header[] responseHeaders = response.getHeaders(); for (int i = 0; i < responseHeaders.length; i++) { Header header = responseHeaders[i]; if (header != null) { String headerName = responseHeaders[i].getName(); List<String> headerValues = headers.get(headerName); if (headerValues == null) { headerValues = new ArrayList<String>(); headers.put(headerName, headerValues); } headerValues.add(responseHeaders[i].getValue()); } } return headers; }
@Override public void cancelHttpRequest (HttpRequest httpRequest) { HttpResponseListener httpResponseListener = listeners.get(httpRequest); Request request = requests.get(httpRequest); if (httpResponseListener != null && request != null) { request.cancel(); httpResponseListener.cancelled(); requests.remove(httpRequest); listeners.remove(httpRequest); } }
@Override public String getHeader (String name) { return response.getHeader(name); } }
/** * Params from token. * * @param token the token */ public static void paramsFromToken(String token) { paramsMap.clear(); if (token != null && token.trim().length() > 0) { String[] params = token.split(PARAMS_SEPARATOR); for (String param : params) { String[] keyVal = param.split("="); if (keyVal != null && keyVal.length == 2) { paramsMap.put(keyVal[0], URL.decodeQueryString(keyVal[1])); } } } }
/** * Export CTL schema. * * @param key the CTL export key */ public static void exportCtlSchema(String key) { String getUrl = composeUrl(KAA_CTL_EXPORT_SERVLET_PATH, CTL_EXPORT_KEY_PARAMETER + "=" + URL.encodeQueryString(key)); String url = GWT.getModuleBaseURL() + getUrl; Window.open(url, "_self", "enabled"); }
/** * Download record library. * * @param key the record library key */ public static void downloadRecordLibrary(String key) { String getUrl = composeUrl(KAA_RECORD_LIBRARY_SERVLET_PATH, RECORD_KEY_PARAMETER + "=" + URL.encodeQueryString(key)); String url = GWT.getModuleBaseURL() + getUrl; Window.open(url, "_self", "enabled"); }
/** * Download endpoint configuration. * * @param endpointKeyHash the endpoint key hash */ public static void downloadEndpointConfiguration(String endpointKeyHash) { String getUrl = composeUrl(EP_CONF_SERVLET_PATH, ENDPOINT_KEY_PARAMETER + "=" + URL.encodeQueryString(endpointKeyHash)); String url = GWT.getModuleBaseURL() + getUrl; Window.open(url, "_self", "enabled"); }