aerogear-controller 1.0.0.M1

org.jboss.aerogear.controller.router.rest
Class AbstractRestResponder

java.lang.Object
  extended by org.jboss.aerogear.controller.router.rest.AbstractRestResponder
All Implemented Interfaces:
Responder
Direct Known Subclasses:
JsonResponder

public abstract class AbstractRestResponder
extends Object
implements Responder

AbstractRestResponder is a Responder capable of returning a response to a request.

This class handles common task such as implementing accepts(String) and making sure that certain HTTP headers are always set on the HttpServletResponse, for example that the 'Content-Type' header is set to the media type that this Responder accepts.


Field Summary
private  String mediaType
           
 
Constructor Summary
AbstractRestResponder(String mediaType)
          Sole constructor that subclasses should call from tier no-args constructor
 
Method Summary
 boolean accepts(String mediaType)
          Determines whether this responder can respond to the passed-in @{code mediaType}
 void respond(Object entity, RouteContext routeContext)
          Responds to the current request in a why appropriate to the type of Responder (forward, return).
abstract  void writeResponse(Object entity, RouteContext routeContext)
          Writes the passed-in entity to the HttpServletResponse enabling concrete implementation to add additional headers of in other ways process the response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mediaType

private final String mediaType
Constructor Detail

AbstractRestResponder

public AbstractRestResponder(String mediaType)
Sole constructor that subclasses should call from tier no-args constructor

Parameters:
mediaType - the media type that this responder accepts.
Method Detail

writeResponse

public abstract void writeResponse(Object entity,
                                   RouteContext routeContext)
                            throws Exception
Writes the passed-in entity to the HttpServletResponse enabling concrete implementation to add additional headers of in other ways process the response.

Parameters:
entity - the entity returned from a Route endpoint.
routeContext - the current RouteContext.
Throws:
Exception - if an error occurs while responding.

accepts

public boolean accepts(String mediaType)
Description copied from interface: Responder
Determines whether this responder can respond to the passed-in @{code mediaType}

Specified by:
accepts in interface Responder
Parameters:
mediaType - the mediaType that this responder supports.
Returns:
@{code true} if this responder can handle the media type passed in, false otherwise.

respond

public void respond(Object entity,
                    RouteContext routeContext)
             throws Exception
Description copied from interface: Responder
Responds to the current request in a why appropriate to the type of Responder (forward, return).

Specified by:
respond in interface Responder
Parameters:
entity - the entity returned from a Route endpoint.
routeContext - the current RouteContext.
Throws:
Exception - if an error occurs while responding.

aerogear-controller 1.0.0.M1

Copyright © 2012 JBoss, a division of Red Hat, Inc.. All Rights Reserved.