/** * Creates a client/proxy for the provided JAX-RS resource interface. * * @param remoteService * the JAX-RS resource interface. Must not be null. * @param callback * the asynchronous callback to use. Must not be null. * @param successCodes * optional HTTP status codes used to determine whether the request * was successful. If omitted, all 2xx status codes are interpreted * as success for this request. * @return proxy of the specified remote service type */ public static <T, R> T create(final Class<T> remoteService, final RemoteCallback<R> callback, Integer... successCodes) { return create(remoteService, null, callback, null, successCodes); }
/** * If not set explicitly, the base URL is the configured default application * root path {@see RestClient}. * * @return the base URL used to contact the remote service */ public String getBaseUrl() { if (baseUrl != null) { return baseUrl; } else { return RestClient.getApplicationRoot(); } }
private String _fromJSON(final String json) { if (RestClient.isJacksonMarshallingActive()) { return JacksonTransformer.fromJackson(json); } return json; } };
private String _toJSON(final String json) { if (RestClient.isJacksonMarshallingActive()) { return JacksonTransformer.toJackson(json); } return json; }
/** * Creates a client/proxy for the provided JAX-RS resource interface. * * @param remoteService * the JAX-RS resource interface. Must not be null. * @param baseUrl * the base URL overriding the default application root path * @param callback * the asynchronous callback to use. Must not be null. * @param successCodes * optional HTTP status codes used to determine whether the request * was successful. If omitted, all 2xx status codes are interpreted * as success for this request. * @return proxy of the specified remote service type */ public static <T, R> T create(final Class<T> remoteService, String baseUrl, final RemoteCallback<R> callback, Integer... successCodes) { return create(remoteService, baseUrl, callback, null, successCodes); }
/** * Set a cookie for the domain and path returned by * {@link #getApplicationRoot()}. * * @param cookieName * The name of the cookie to set. * @param cookieValue * The value of the cookie to set. */ public static void setCookie(final String cookieName, final String cookieValue) { final AnchorElement anchorElement = Document.get().createAnchorElement(); anchorElement.setHref(RestClient.getApplicationRoot()); final String path = anchorElement.getPropertyString("pathname"); final String domain = anchorElement.getPropertyString("domain"); Cookies.setCookie(cookieName, cookieValue, null, domain, path, false); } }
/** * Creates a client/proxy for the provided JAX-RS resource interface. * * @param remoteService * the JAX-RS resource interface. Must not be null. * @param baseUrl * the base URL overriding the default application root path * @param callback * the asynchronous callback to use. Must not be null. * @param errorCallback * the error callback to use * @param successCodes * optional HTTP status codes used to determine whether the request * was successful. If omitted, all 2xx status codes are interpreted * as success for this request. * @return proxy of the specified remote service type */ public static <T, R> T create(final Class<T> remoteService, String baseUrl, final RemoteCallback<R> callback, final RestErrorCallback errorCallback, Integer... successCodes) { return create(remoteService, baseUrl, callback, errorCallback, null, successCodes); }
/** * Creates a client/proxy for the provided JAX-RS resource interface. * * @param remoteService * the JAX-RS resource interface. Must not be null. * @param callback * the asynchronous callback to use. Must not be null. * @param errorCallback * the error callback to use * @param successCodes * optional HTTP status codes used to determine whether the request * was successful. If omitted, all 2xx status codes are interpreted * as success for this request. * @return proxy of the specified remote service type */ public static <T, R> T create(final Class<T> remoteService, final RemoteCallback<R> callback, final RestErrorCallback errorCallback, Integer... successCodes) { return create(remoteService, null, callback, errorCallback, successCodes); }
/** * Creates a client/proxy for the provided JAX-RS resource interface. * * @param remoteService * the JAX-RS resource interface. Must not be null. * @param callback * the asynchronous callback to use. Must not be null. * @param requestCallback * the request callback that provides access to the * {@link com.google.gwt.http.client.Request}. * @param successCodes * optional HTTP status codes used to determine whether the request * was successful. If omitted, all 2xx status codes are interpreted * as success for this request. * @return proxy of the specified remote service type */ public static <T, R> T create(final Class<T> remoteService, final RemoteCallback<R> callback, final RequestCallback requestCallback, Integer... successCodes) { return create(remoteService, null, callback, null, requestCallback, successCodes); }
/** * Creates a client/proxy for the provided JAX-RS resource interface. * * @param remoteService * the JAX-RS resource interface. Must not be null. * @param callback * the asynchronous callback to use. Must not be null. * @param errorCallback * the error callback to use * @param requestCallback * the request callback that provides access to the * {@link com.google.gwt.http.client.Request}. * @param successCodes * optional HTTP status codes used to determine whether the request * was successful. If omitted, all 2xx status codes are interpreted * as success for this request. * @return proxy of the specified remote service type */ public static <T, R> T create(final Class<T> remoteService, final RemoteCallback<R> callback, final RestErrorCallback errorCallback, final RequestCallback requestCallback, Integer... successCodes) { return create(remoteService, null, callback, errorCallback, requestCallback, successCodes); }
RestClient client = RestClient.builder().build(); String url = ... Person person = ... Header header = client.create(url, person); if (header != null) System.out.println("Location header is:" + header.value());