Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2011 JBoss, by Red Hat, Inc
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *    http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.jboss.errai.enterprise.client.jaxrs.api;
 
 import  org.jboss.errai.common.client.api.Assert;
 import  org.jboss.errai.common.client.api.RemoteCallback;
 import  org.jboss.errai.common.client.framework.ProxyFactory;
 import  org.jboss.errai.common.client.framework.RemoteServiceProxyFactory;
 
 import  com.google.common.collect.Lists;
 import  com.google.gwt.dom.client.AnchorElement;
 import  com.google.gwt.dom.client.Document;
 import  com.google.gwt.user.client.Cookies;

API for communicating with REST endpoints based on JAX-RS interfaces.

Author(s):
Christian Sadilek <csadilek@redhat.com>
 
 public class RestClient {
   private static ProxyFactory proxyProvider = new RemoteServiceProxyFactory();

  
Creates a client/proxy for the provided JAX-RS resource interface.

Parameters:
remoteService the JAX-RS resource interface. Must not be null.
callback the asynchronous callback to use. Must not be null.
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.
Returns:
proxy of the specified remote service type
 
   public static <T, R> T create(final Class<T> remoteServicefinal RemoteCallback<R> callback,
       Integer... successCodes) {
     return create(remoteServicenullcallbacknullsuccessCodes);
   }

  
Creates a client/proxy for the provided JAX-RS resource interface.

Parameters:
remoteService the JAX-RS resource interface. Must not be null.
baseUrl the base URL overriding the default application root path
callback the asynchronous callback to use. Must not be null.
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.
Returns:
proxy of the specified remote service type
 
   public static <T, R> T create(final Class<T> remoteServiceString baseUrlfinal RemoteCallback<R> callback,
       Integer... successCodes) {
     return create(remoteServicebaseUrlcallbacknullsuccessCodes);
   }

  
Creates a client/proxy for the provided JAX-RS resource interface.

Parameters:
remoteService the JAX-RS resource interface. Must not be null.
callback the asynchronous callback to use. Must not be null.
errorCallback the error callback to use
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.
Returns:
proxy of the specified remote service type
 
   public static <T, R> T create(final Class<T> remoteServicefinal RemoteCallback<R> callback,
       final RestErrorCallback errorCallbackInteger... successCodes) {
     return create(remoteServicenullcallbackerrorCallbacksuccessCodes);
   }

  
Creates a client/proxy for the provided JAX-RS resource interface.

Parameters:
remoteService the JAX-RS resource interface. Must not be null.
baseUrl the base URL overriding the default application root path
callback the asynchronous callback to use. Must not be null.
errorCallback the error callback to use
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.
Returns:
proxy of the specified remote service type
  public static <T, R> T create(final Class<T> remoteServiceString baseUrlfinal RemoteCallback<R> callback,
      final RestErrorCallback errorCallbackInteger... successCodes) {
    Assert.notNull(remoteService);
    Assert.notNull(callback);
    if (baseUrl != null && !baseUrl.endsWith("/"))
      baseUrl += "/";
    T proxy = .getRemoteProxy(remoteService);
    if (successCodes.length > 0) {
      ((AbstractJaxrsProxyproxy).setSuccessCodes(Lists.newArrayList(successCodes));
    }
    ((AbstractJaxrsProxyproxy).setRemoteCallback(callback);
    ((AbstractJaxrsProxyproxy).setErrorCallback(errorCallback);
    ((AbstractJaxrsProxyproxy).setBaseUrl(baseUrl);
    return proxy;
  }

  
Returns the configured JAX-RS default application root path.

Returns:
path with trailing slash, or empty string if undefined or explicitly set to empty
  public static native String getApplicationRoot() /*-{
    if ($wnd.erraiJaxRsApplicationRoot === undefined || $wnd.erraiJaxRsApplicationRoot.length === 0) {
      return ""; 
     } 
     else {
       if ($wnd.erraiJaxRsApplicationRoot.substr(-1) !== "/") {
         return $wnd.erraiJaxRsApplicationRoot + "/";
       }
       return $wnd.erraiJaxRsApplicationRoot;
     }  
   }-*/;

  
Configures the JAX-RS default application root path.

Parameters:
path path to use when sending requests to the JAX-RS endpoint
  public static native void setApplicationRoot(String path/*-{
    if (path == null) {
      $wnd.erraiJaxRsApplicationRoot = undefined;
    }
    else {
      $wnd.erraiJaxRsApplicationRoot = path;
    }
  }-*/;

  
Checks if a jackson compatible JSON format should be used instead of Errai JSON.

Returns:
true, if jackson marshalling should be used, otherwise false.
  public static native boolean isJacksonMarshallingActive() /*-{
    if ($wnd.erraiJaxRsJacksonMarshallingActive === undefined) {
      return false; 
    } 
    else {
      return $wnd.erraiJaxRsJacksonMarshallingActive;
    }
  }-*/;

  
Activates/Deactivates jackson conform JSON marshalling.

Parameters:
active true if jackson marshalling should be activated, otherwise false.
  public static native void setJacksonMarshallingActive(boolean active/*-{
    $wnd.erraiJaxRsJacksonMarshallingActive = active;
  }-*/;

  
Set a cookie for the domain and path returned by getApplicationRoot().

Parameters:
cookieName The name of the cookie to set.
cookieValue The value of the cookie to set.
  public static void setCookie(final String cookieNamefinal 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(cookieNamecookieValuenulldomainpathfalse);
  }
New to GrepCode? Check out our FAQ X