@Scope(value="singleton") @Provider public class BroadleafMessageBodyReaderWriter extends Object implements javax.ws.rs.ext.MessageBodyReader<Object>, javax.ws.rs.ext.MessageBodyWriter<Object>, javax.ws.rs.ext.ContextResolver<JAXBContext>, org.springframework.context.ApplicationContextAware
This custom MessageBodyReaderWriter was written in order to correctly handle any custom extended entities that Broadleaf is aware of. The intent is to replace any paramerterized types with the correct implementations that are defined in the Application Context. Once the correct generic types are replaced, the class then delegates to the default XML or JSON List providers.
JSONListElementProvider,
XMLListElementProvider| Modifier and Type | Class and Description |
|---|---|
protected class |
BroadleafMessageBodyReaderWriter.ParameterizedTypeImpl |
| Modifier and Type | Field and Description |
|---|---|
protected org.springframework.context.ApplicationContext |
applicationContext |
protected JAXBContext |
jaxbContext |
protected com.sun.jersey.json.impl.provider.entity.JSONListElementProvider.App |
jsonListProvider |
protected com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider.App |
jsonRootElementProvider |
protected javax.ws.rs.ext.Providers |
ps |
protected com.sun.jersey.spi.inject.Injectable<SAXParserFactory> |
spf |
protected static HashMap<String,Class<?>> |
typeMap |
protected com.sun.jersey.spi.inject.Injectable<XMLInputFactory> |
xif |
protected com.sun.jersey.core.impl.provider.entity.XMLListElementProvider.App |
xmlListProvider |
protected com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider.App |
xmlRootElementProvider |
| Constructor and Description |
|---|
BroadleafMessageBodyReaderWriter() |
| Modifier and Type | Method and Description |
|---|---|
protected Type |
getApiWrapper(Class<?> type,
Type lookupType)
Via the ApplicationContext we can look up exactly what implementation
corresponds to the parameterized domain interface and determine if that
is annotated with proper JAXB annotations for serialization.
|
JAXBContext |
getContext(Class<?> ignored) |
protected Type |
getLookupType(Class<?> type,
Type genericType) |
long |
getSize(Object t,
Class<?> type,
Type genericType,
Annotation[] annotations,
javax.ws.rs.core.MediaType mediaType) |
protected void |
initializeTypeMap() |
boolean |
isReadable(Class<?> type,
Type genericType,
Annotation[] annotations,
javax.ws.rs.core.MediaType mediaType) |
boolean |
isWriteable(Class<?> type,
Type genericType,
Annotation[] annotations,
javax.ws.rs.core.MediaType mediaType) |
Object |
readFrom(Class<Object> type,
Type genericType,
Annotation[] annotations,
javax.ws.rs.core.MediaType mediaType,
javax.ws.rs.core.MultivaluedMap<String,String> httpHeaders,
InputStream entityStream) |
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
void |
writeTo(Object t,
Class<?> type,
Type genericType,
Annotation[] annotations,
javax.ws.rs.core.MediaType mediaType,
javax.ws.rs.core.MultivaluedMap<String,Object> httpHeaders,
OutputStream entityStream) |
protected org.springframework.context.ApplicationContext applicationContext
@Context protected javax.ws.rs.ext.Providers ps
@Context protected com.sun.jersey.spi.inject.Injectable<XMLInputFactory> xif
@Context protected com.sun.jersey.spi.inject.Injectable<SAXParserFactory> spf
protected JAXBContext jaxbContext
protected com.sun.jersey.core.impl.provider.entity.XMLListElementProvider.App xmlListProvider
protected com.sun.jersey.json.impl.provider.entity.JSONListElementProvider.App jsonListProvider
protected com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider.App xmlRootElementProvider
protected com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider.App jsonRootElementProvider
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
isReadable in interface javax.ws.rs.ext.MessageBodyReader<Object>public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
isWriteable in interface javax.ws.rs.ext.MessageBodyWriter<Object>public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<String,String> httpHeaders, InputStream entityStream) throws IOException, javax.ws.rs.WebApplicationException
readFrom in interface javax.ws.rs.ext.MessageBodyReader<Object>IOExceptionjavax.ws.rs.WebApplicationExceptionpublic long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
getSize in interface javax.ws.rs.ext.MessageBodyWriter<Object>public void writeTo(Object t, Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<String,Object> httpHeaders, OutputStream entityStream) throws IOException
writeTo in interface javax.ws.rs.ext.MessageBodyWriter<Object>IOExceptionprotected Type getApiWrapper(Class<?> type, Type lookupType)
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
throws org.springframework.beans.BeansException
setApplicationContext in interface org.springframework.context.ApplicationContextAwareorg.springframework.beans.BeansExceptionpublic JAXBContext getContext(Class<?> ignored)
getContext in interface javax.ws.rs.ext.ContextResolver<JAXBContext>protected void initializeTypeMap()
Copyright © 2013. All Rights Reserved.