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 java.util.List;
 
 
API for executing HTTP calls based on a JAX-RS interface.

Author(s):
Christian Sadilek <csadilek@redhat.com>
 
 public class RestClient {
   static {
     // ensure that the marshalling framework has been initialized
     MarshallerFramework.initializeDefaultSessionProvider();
   }
   
   private static ProxyFactory proxyProvider = new RemoteServiceProxyFactory();

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

Parameters:
remoteService the JAX-RS interface
callback the asynchronous callback to use
successCodes optional HTTP status codes used to determine if the request was successful
Returns:
proxy of the specified remote service type
 
   public static <T, R> T create(final Class<T> remoteServicefinal RemoteCallback<R> callback,
       int... successCodes) {
     return create(remoteServicenullcallbacknullsuccessCodes);
   }

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

Parameters:
remoteService the JAX-RS interface
baseUrl the base url overriding the default application root path
callback the asynchronous callback to use
successCodes optional HTTP status codes used to determine if the request was successful
Returns:
proxy of the specified remote service type
 
   public static <T, R> T create(final Class<T> remoteServiceString baseUrlfinal RemoteCallback<R> callback
       int... successCodes) {
     return create(remoteServicebaseUrlcallbacknullsuccessCodes);
   }
  
  
Creates a client/proxy for the provided JAX-RS resource interface.

Parameters:
remoteService the JAX-RS interface
callback the asynchronous callback to use
errorCallback the error callback to use
successCodes optional HTTP status codes used to determine if the request was successful
Returns:
proxy of the specified remote service type
 
   public static <T, R> T create(final Class<T> remoteServicefinal RemoteCallback<R> callback,
       final ErrorCallback errorCallbackint... successCodes) {
     return create(remoteServicenullcallbackerrorCallbacksuccessCodes);
   }
  
  
Creates a client/proxy for the provided JAX-RS resource interface.

Parameters:
remoteService the JAX-RS interface
baseUrl the base url overriding the default application root path
callback the asynchronous callback to use
errorCallback the error callback to use
successCodes optional HTTP status codes used to determine if the request was successful
Returns:
proxy of the specified remote service type
 
   public static <T, R> T create(final Class<T> remoteServiceString baseUrlfinal RemoteCallback<R> callback
       final ErrorCallback errorCallbackint... successCodes) {
 
     if (baseUrl != null && !baseUrl.endsWith("/")) 
      baseUrl += "/";
    
    T proxy = .getRemoteProxy(remoteService);
    if (proxy == null || !(proxy instanceof JaxrsProxy)) {
      JaxrsProxyLoader loader = GWT.create(JaxrsProxyLoader.class);
      loader.loadProxies();
      proxy = .getRemoteProxy(remoteService); 
      if (proxy == null || !(proxy instanceof JaxrsProxy))
        throw new RuntimeException("No proxy found for JAX-RS interface: " + remoteService.getName());
    }
    // Can't use ArrayUtils (class has to be translatable).
    if (successCodes.length > 0) {
      List<Integercodes = new ArrayList<Integer>();
      for (int code : successCodes) {
        codes.add(code);
      }
      ((JaxrsProxyproxy).setSuccessCodes(codes);
    }
    
    ((JaxrsProxyproxy).setRemoteCallback(callback);
    ((JaxrsProxyproxy).setErrorCallback(errorCallback);
    ((JaxrsProxyproxy).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:
root 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;
    }
  }-*/;
New to GrepCode? Check out our FAQ X