@Override public void addAll(K key, V... newValues) { for (V value : newValues) { add(key, value); } }
@Override public String toString() { return getEncodedPathWithParameters(); } }
/** * 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(); } }
/** * 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); }
@Override public Throwable fromResponse(final Response response) { if (response.getStatusCode() == 403) { SecurityException securityException = null; try { securityException = fromJSON(response, SecurityException.class); } catch (RuntimeException e) { } if (securityException != null) { return securityException; } } return new ResponseException(response.getStatusText(), response); }
@Override @SuppressWarnings("Duplicates") public boolean error(final Request message, final Throwable caught) throws MissingPageRoleException { return wrapped.error(message, caught) && handler.handleException(caught); }
private String _fromJSON(final String json) { if (RestClient.isJacksonMarshallingActive()) { return JacksonTransformer.fromJackson(json); } return json; } };
@Override public V getFirst(K key) { List<V> values = get(key); if (values != null && !values.isEmpty()) { return values.get(0); } return null; }
/** * 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); }
@Override public Throwable fromResponse(final Response response) { if (response.getStatusCode() == 403) { SecurityException securityException = null; try { securityException = fromJSON(response, SecurityException.class); } catch (RuntimeException e) { } if (securityException != null) { return securityException; } } return new ResponseException(response.getStatusText(), response); }
@Override @SuppressWarnings("Duplicates") public boolean error(final Request message, final Throwable caught) throws MissingPageRoleException { return wrapped.error(message, caught) && handler.handleException(caught); }
@Override public void addAll(K key, List<V> valueList) { for (V value : valueList) { add(key, value); } }
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 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 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 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());