[aerogear-dev] [aerogear-controller] Request Parameter support

Daniel Bevenius daniel.bevenius at gmail.com
Thu Jan 3 05:24:44 EST 2013


We've pushed a version of AeroGear Controller with support for request
parameters (AEROGEAR-671 <https://issues.jboss.org/browse/AEROGEAR-671>) to
openshift<http://controllerdemo-danbev.rhcloud.com/aerogear-controller-demo/>
.

This demo has the following new route added to it:

route()
      .from("/cars")
      .on(RequestMethod.GET)
      .produces(MediaType.JSON.toString(), "application/custom")
      .to(Home.class).get(param("color", "pink"), param("brand", "mini"));

The target method for the above route is named get and takes two
parameters, *color*, and *brand*. Both parameters are option and if not
specified the default values will be used (pink is the default value for *
color*, and*mini* is the default value for brand).

Home.class has a new method named get:

public Car get(String color, String brand) {
      return new Car(color, brand);}

You can try these out using the examples below:

Example of specifying both query parameters:

curl -i --header "Accept: application/json"
"http://controllerdemo-danbev.rhcloud.com/aerogear-controller-demo/cars?color=Red&brand=Ferrari"

Example of specifying one query parameter:

curl -i --header "Accept: application/json"
"http://controllerdemo-danbev.rhcloud.com/aerogear-controller-demo/cars?color=Red"

Example of specifying no query parameters:

curl -i --header "Accept: application/json"
"http://controllerdemo-danbev.rhcloud.com/aerogear-controller-demo/cars"

Example of returning a custom media type:

curl -i --header "Accept: application/custom"
"http://controllerdemo-danbev.rhcloud.com/aerogear-controller-demo/cars?color=Gray"

A custom media type is an example of a custom responder in AeroGear
Controller. In this case it only returns a string but could really do
anything needed with the object returned from the target method.

public class CustomMediaTypeResponder extends AbstractRestResponder {

    public static final String MEDIA_TYPE = "application/custom";

    public CustomMediaTypeResponder() {
        super(MEDIA_TYPE);
    }

    public void writeResponse(Object entity, RouteContext routeContext)
        throws Exception {
        routeContext.getResponse().getWriter().write("CustomMediaTypeResponder
returned: " + entity);
    }

    @Override
    public String mediaType() {
        return MEDIA_TYPE;
    }
}

Please try this out, and if you find any issue let us know, or simply
create jira bug reports.

Thanks,

/Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/aerogear-dev/attachments/20130103/5cc7a80d/attachment.html 


More information about the aerogear-dev mailing list