[Hippo-cms7-user] RESTful API Support - Plain JAX-RS Services

Jeroen Reijn j.reijn at onehippo.com
Wed Sep 26 09:58:33 CEST 2012


Hi,

the GoGreen demo has an example of this. See:

http://svn.onehippo.org/viewvc/hippo-demos/hippo-go-green/tags/hippogogreen-3.05.06/site/src/main/java/com/onehippo/gogreen/jaxrs/model/ProductRepresentation.java?revision=34780&view=markup

There is a method that shows an example of how to create the REST URL
for the image.

Let us know if that helps.

Jeroen

On Tue, Sep 25, 2012 at 6:42 PM, Chandan AGARWAL
<chandan.agarwal at smile-benelux.com> wrote:
> Hello everyone,
> I am using spring Rest template to extract the data from hippo using plain
> JAX-RS Services and displaying this data in the frontend using the rest
> client, I followed these tutorials
> http://blog.jeroenreijn.com/2011/02/hippos-restful-jax-rs-component-support.html
> http://www.onehippo.org/7_7/library/concepts/rest/restful-api-support---plain-jax-rs-services.html
>
> I have a document type called ContentBlock which has one String and a image.
>
> This is the code which extracts all the documents of ContentBlock and
> converts it to a list of ContentBlockRepresentation
> @Path("/contentBlocks/")
> public class ContentBlockResource extends AbstractContentResource {
>
>     @GET
>     @Path("/")
>     @Produces("text/xml")
>     public CollectionContentBlockRepresentation getAllContentBlocks(@Context
> HttpServletRequest servletRequest,
>             @Context HttpServletResponse servletResponse) {
>
>         CollectionContentBlockRepresentation contentBlocks = new
> CollectionContentBlockRepresentation();
>
>         HstRequestContext requestContext =
> getRequestContext(servletRequest);
>
>         try {
>
>             String mountContentPath =
> requestContext.getResolvedMount().getMount().getContentPath();
>             Node mountContentNode =
> requestContext.getSession().getRootNode().getNode(PathUtils.normalizePath(mountContentPath));
>
>             HstQueryManager manager =
> getHstQueryManager(requestContext.getSession(), requestContext);
>             HstQuery hstQuery = manager.createQuery(mountContentNode,
> ContentBlock.class, true);
>             HstQueryResult result = hstQuery.execute();
>             HippoBeanIterator iterator = result.getHippoBeans();
>
>             while (iterator.hasNext()) {
>                 ContentBlock contentBlock = (ContentBlock)
> iterator.nextHippoBean();
>
>                 if (contentBlock != null) {
>                     ContentBlockRepresentation contentBlockRep = new
> ContentBlockRepresentation(contentBlock.getTitle(),
>                             contentBlock.getDescription(),
> getImage(contentBlock.getImage()));
>                     contentBlocks.getContentBlocks().add(contentBlockRep);
>                 }
>             }
>
>         } catch (Exception e) {
>         }
>
>         return contentBlocks;
>     }
>
> private ImageRepresentation getImage(HippoGalleryImageSetBean image) {
>         if (image != null) {
>             ImageRepresentation imageRepresentation = new
> ImageRepresentation();
>             imageRepresentation.setPath(image.getOriginal().getPath());
>             imageRepresentation.setFileName(image.getFileName());
>             return imageRepresentation;
>         } else
>             return null;
>
>     }
>
>    }
>
> @XmlRootElement(name = "contentBlock")
> public class ContentBlockRepresentation {
>
>     private String title;
>     private String description;
>     private ImageRepresentation image;
>
>     public ContentBlockRepresentation() {
>     }
>
>     public ContentBlockRepresentation(String title, String description,
> ImageRepresentation image) {
>         this.title = title;
>         this.description = description;
>         this.image = image;
>     }
>
>     public String getTitle() {
>         return title;
>     }
>
>     public void setTitle(String title) {
>         this.title = title;
>     }
>
>     public String getDescription() {
>         return description;
>     }
>
>     public void setDescription(String description) {
>         this.description = description;
>     }
>
>     @XmlElement(name = "image")
>     public ImageRepresentation getImage() {
>         return image;
>     }
>
>     public void setImage(ImageRepresentation image) {
>         this.image = image;
>     }
>
> }
>
> @XmlRootElement(name = "image")
> public class ImageRepresentation {
>
>     private String path;
>     private String fileName;
>
>     public String getPath() {
>         return path;
>     }
>
>     public void setPath(String path) {
>         this.path = path;
>     }
>
>     public String getFileName() {
>         return fileName;
>     }
>
>     public void setFileName(String fileName) {
>         this.fileName = fileName;
>     }
>
> }
>
> I am using JAX-B to map the ContentBlock object to
> ContentBlockRepresentation object. This object is returned by the restClient
> to the frontend of my site
>  In my ImageRepresentation object I have a variable called path in which i
> want to store the path of the image. The problem is that which path should i
> store so that i can display it in the jsp. I was able to display the
> variables like title and description as they are of string type but image is
> of type HippoGalleryImageSetBean.
>
> Could you suggest me the mapping for the  image type inorder to display it
> in the Jsp.
>
>
>
> Cdt,
> Chandan AGARWAL
> IED
> Smile Benelux
> Brussels
> Mb - (+32) 0492101358
>
>
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/forums.html



-- 
Jeroen Reijn
Solution Architect
Hippo

Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com

http://about.me/jeroenreijn



More information about the Hippo-cms7-user mailing list