org.broadleafcommerce.core.web.api
Class BroadleafRestExceptionMapper

java.lang.Object
  extended by org.broadleafcommerce.core.web.api.BroadleafRestExceptionMapper
All Implemented Interfaces:
javax.ws.rs.ext.ExceptionMapper<Throwable>, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, org.springframework.context.MessageSourceAware

@Scope(value="singleton")
@Provider
public class BroadleafRestExceptionMapper
extends Object
implements javax.ws.rs.ext.ExceptionMapper<Throwable>, org.springframework.context.MessageSourceAware, org.springframework.context.ApplicationContextAware

This is a generic JAX-RS ExceptionMapper. This can be registered as a Spring Bean to catch exceptions, log them, and return reasonable responses to the client. Alternatively, you can extend this or implement your own, more granular, mapper(s). This class does not return internationalized messages. But for convenience, this class provides a protected Spring MessageSource to allow for internationalization if one chose to go that route.

Author:
Kelly Tisdell

Field Summary
protected  org.springframework.context.ApplicationContext context
           
protected  javax.ws.rs.core.HttpHeaders headers
           
protected  String messageKeyPrefix
           
protected  org.springframework.context.MessageSource messageSource
           
 
Constructor Summary
BroadleafRestExceptionMapper()
           
 
Method Summary
protected  String resolveClientMessageKey(String key)
           
protected  javax.ws.rs.core.MediaType resolveResponseMediaType(Throwable t)
           
protected  int resolveResponseStatusCode(Throwable t, ErrorWrapper error)
           
 void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
           
 void setMessageKeyPrefix(String prefix)
          This key is the prefix that will be stripped off of all message keys that are returned to a client.
 void setMessageSource(org.springframework.context.MessageSource messageSource)
           
 javax.ws.rs.core.Response toResponse(Throwable t)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

messageKeyPrefix

protected String messageKeyPrefix

headers

@Context
protected javax.ws.rs.core.HttpHeaders headers

messageSource

protected org.springframework.context.MessageSource messageSource

context

protected org.springframework.context.ApplicationContext context
Constructor Detail

BroadleafRestExceptionMapper

public BroadleafRestExceptionMapper()
Method Detail

toResponse

public javax.ws.rs.core.Response toResponse(Throwable t)
Specified by:
toResponse in interface javax.ws.rs.ext.ExceptionMapper<Throwable>

setMessageSource

public void setMessageSource(org.springframework.context.MessageSource messageSource)
Specified by:
setMessageSource in interface org.springframework.context.MessageSourceAware

setApplicationContext

public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
                           throws org.springframework.beans.BeansException
Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware
Throws:
org.springframework.beans.BeansException

setMessageKeyPrefix

public void setMessageKeyPrefix(String prefix)
This key is the prefix that will be stripped off of all message keys that are returned to a client. The default is "org.broadleafcommerce.core.web.api.BroadleafWebServicesException.". So, if a message key contained in a BroadleafWebServicesException is org.broadleafcommerce.core.web.api.BroadleafWebServicesException.unknownError, just "unknownError" will be returned to the client. This behavior can be changed by overriding the resolveClientMessageKey method.

Parameters:
prefix -

resolveResponseStatusCode

protected int resolveResponseStatusCode(Throwable t,
                                        ErrorWrapper error)

resolveResponseMediaType

protected javax.ws.rs.core.MediaType resolveResponseMediaType(Throwable t)

resolveClientMessageKey

protected String resolveClientMessageKey(String key)


Copyright © 2013. All Rights Reserved.