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;
 
 import  com.google.gwt.core.client.GWT;
 import  com.google.gwt.http.client.*;
 import  org.jboss.errai.common.client.api.ErrorCallback;
 import  org.jboss.errai.common.client.api.RemoteCallback;
 import  org.jboss.errai.common.client.framework.RpcBatch;
 import  org.jboss.errai.common.client.framework.RpcStub;
 
 import java.util.List;

JAX-RS proxies are RpcStubs managed by the shared RemoteServiceProxyFactory. The implementations of this class are generated at compile time.

Author(s):
Christian Sadilek <csadilek@redhat.com>
 
 public abstract class AbstractJaxrsProxy implements RpcStub {
   private String baseUrl;
   private List<IntegersuccessCodes;
   private RemoteCallback<Request> requestCallback;

  
Returns the remote callback used by this proxy.

Returns:
the remote callback, never null.
 
   public abstract RemoteCallback<?> getRemoteCallback();

  
Returns the error callback used by this proxy.

Returns:
the error callback, null if no error callback was provided.
 
   public abstract ErrorCallback<?> getErrorCallback();

  
If not set explicitly, the base URL is the configured default application root path RestClient.

Returns:
the base URL used to contact the remote service
 
   public String getBaseUrl() {
     if ( != null) {
       return ;
     }
     else {
       return RestClient.getApplicationRoot();
     }
   }

  
Sets the base URL of the remote service and overrides the configured default application root path.

Parameters:
baseUrl the base URL used to contact the remote service
 
   public void setBaseUrl(String baseUrl) {
     this. = baseUrl;
   }

  
Returns the list of success codes used by this proxy.

Returns:
list of success codes, null if no custom success codes were provided.
 
   public List<IntegergetSuccessCodes() {
     return ;
   }

  
Sets a list of HTTP status codes that will be used to determine whether a request was successful or not.

Parameters:
successCodes list of HTTP status codes
  public void setSuccessCodes(List<IntegersuccessCodes) {
    this. = successCodes;
  }
  @SuppressWarnings({ "rawtypes""unchecked" })
  protected void sendRequest(final RequestBuilder requestBuilderfinal String body,
          final ResponseDemarshallingCallback demarshallingCallback) {
    final RemoteCallback remoteCallback = getRemoteCallback();
    try {
      // Allow overriding of request body in client-side interceptors
      String requestBody = (requestBuilder.getRequestData() != null) ? requestBuilder.getRequestData() : body;
      Request request = requestBuilder.sendRequest(requestBodynew RequestCallback() {
        @Override
        public void onError(Request requestThrowable throwable) {
          handleError(throwablerequestnull);
        }
        @Override
        public void onResponseReceived(Request request, Response response) {
          int statusCode = response.getStatusCode();
          if (( == null || .contains(statusCode)) && (statusCode >= 200 && statusCode < 300)) {
            if (remoteCallback instanceof ResponseCallback) {
              ((ResponseCallbackgetRemoteCallback()).callback(response);
            }
            else if (response.getStatusCode() == 204) {
              remoteCallback.callback(null);
            }
            else {
              remoteCallback.callback(demarshallingCallback.demarshallResponse(response.getText()));
            }
          }
          else {
            Throwable throwable = null;
            ErrorCallback<?> errorCallback = getErrorCallback();
            if (errorCallback instanceof RestErrorCallback && hasExceptionMapper()) {
              throwable = unmarshallException(response);
            }
            else if (response.getText() != null && !response.getStatusText().equals("")) {
              throwable = new ResponseException(response.getStatusText(), response);
            }
            else {
              throwable = new ResponseException("Response returned with status=" + response.getStatusCode(), response);
            }
            handleError(throwablerequestresponse);
          }
        }
      });
      if ( != null) {
        .callback(request);
      }
    } catch (RequestException throwable) {
      handleError(throwablenullnull);
    }
  }

  
Uses the configured ClientExceptionMapper to unmarshal the Response into a Throwable.

Parameters:
response
  protected Throwable unmarshallException(Response response) {
    return getExceptionMapper().fromResponse(response);
  }
  protected void handleError(Throwable throwable, Request request, Response response) {
    ErrorCallback<?> errorCallback = getErrorCallback();
    if (errorCallback != null) {
      if (errorCallback instanceof RestErrorCallback) {
        ((RestErrorCallbackerrorCallback).error(requestthrowable);
      }
      else {
        errorCallback.error(nullthrowable);
      }
    }
    else if ((getRemoteCallback() instanceof ResponseCallback) && (response != null)) {
      ((ResponseCallbackgetRemoteCallback()).callback(response);
    }
    else {
      GWT.log(throwable.getMessage(), throwable);
    }
  }
  public void setQualifiers(Annotation[] annos) {
    // do nothing (no use for qualifiers on injected JAX-RS proxies yet)
  }
  public void setBatch(@SuppressWarnings("rawtypes") RpcBatch batch) {
    throw new UnsupportedOperationException("Batching of remote calls is not supported in errai jax-rs!");
  }
  public void setRequestCallback(RemoteCallback<Request> requestCallback) {
    this. = requestCallback;
  }

  

Returns:
true if this proxy has a configured exception mapper
  public boolean hasExceptionMapper() {
    return getExceptionMapper() != null;
  }

  

Returns:
the exceptionMapper
    return ;
  }

  

Parameters:
exceptionMapper the exceptionMapper to set
  public void setExceptionMapper(ClientExceptionMapper exceptionMapper) {
    this. = exceptionMapper;
  }
New to GrepCode? Check out our FAQ X