REST service with "_type=xml"

40 views
Skip to first unread message

dummi...@gmail.com

unread,
Jun 25, 2015, 3:04:10 AM6/25/15
to hippo-c...@googlegroups.com
Hi,
I was wondering how is the "_type" parameter working, in a REST service. Like here, you can switch the output format:

http://www.demo.onehippo.com/restapi/topproducts?_type=xml

I would like to do this in a service of mine; I have checked the "TopProductsResource" class from GoGreen but I couldn't figure it out, I don't see anything about it.
Can you please advise me here ?

Thanks and Best Regards,
Vlad

Jeroen Reijn

unread,
Jun 25, 2015, 5:06:45 AM6/25/15
to hippo-c...@googlegroups.com
Hi Vlad,

it's provided by CXF and the HST Spring support and is added as a CXF interceptor.

You can check out 
hst-jaxrs-2.30.00.jar!/org/hippoecm/hst/site/optional/jaxrs/SpringComponentManager-rest-content-pipeline.xml

Cheers,

Jeroen


--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-c...@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.
Visit this group at http://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.



--
Jeroen Reijn
Hippo

Amsterdam office - Oosteinde 11, 1017 WT Amsterdam
Boston office - 745 Atlantic Ave, Eight Floor, Boston MA 02111, United states of America.

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

http://blog.jeroenreijn.com | @jreijn | http://about.me/jeroenreijn

dummi...@gmail.com

unread,
Jun 25, 2015, 5:45:57 AM6/25/15
to hippo-c...@googlegroups.com, dummi...@gmail.com
Hi Jeroen,

So it should work out-of-the-box ? Because I tried but I get an exception like "...no configured path" or so. Should I do some configure somewhere ?

Best,
Vlad

Jeroen Reijn

unread,
Jun 25, 2015, 7:23:41 AM6/25/15
to hippo-c...@googlegroups.com, dummi...@gmail.com
On Thu, Jun 25, 2015 at 11:45 AM, <dummi...@gmail.com> wrote:
Hi Jeroen,

So it should work out-of-the-box ? Because I tried but I get an exception like "...no configured path" or so. Should I do some configure somewhere ?

Yes it should be out of the box. If not, I hope you can give us some more insights like logs, response codes, etc.
 

Best,
Vlad

--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-c...@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.
Visit this group at http://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.

dummi...@gmail.com

unread,
Jun 25, 2015, 8:19:32 AM6/25/15
to hippo-c...@googlegroups.com, dummi...@gmail.com
I have Hippo 7.9.8 and hst-jaxrs-2.28.11.jar.

In both hst-jaxrs-2.28.11.jar and hst-jaxrs-2.30.00.jar, in /org/hippoecm/hst/site/optional/jaxrs/SpringComponentManager-rest-content-pipeline.xml the entry is commented:

  <bean id="jaxrsRestContentServiceQueryStringReplacingInterceptor" class="org.hippoecm.hst.jaxrs.cxf.QueryStringReplacingInterceptor">
    <property name="paramNameReplaces">
      <map>
        <!-- The following will replace '_format' parameter name with '_type' parameter name before JAX-RS processing.
        <entry key="_format" value="_type" />
        -->
      </map>
    </property>
    <property name="additionalQueryString">
      <value></value>
      <!-- The following will append additional query string before JAX-RS processing
      <value>addparam1=value1&amp;addparam2=value2</value>
      -->
    </property>
  </bean>

Is this OK ?

Woonsan Ko

unread,
Jun 25, 2015, 9:05:52 AM6/25/15
to hippo-c...@googlegroups.com
The _type parameter is documented here (section 3.1):
-
http://www.onehippo.org/library/concepts/rest/restful-jax-rs-component-support-in-hst-2.html

A site webapp project can override those default configurations. So can
gogreen demo.
What's your problem? _type parameter doesn't work in your project?

Regards,

Woonsan
> --
> Hippo Community Group: The place for all discussions and announcements
> about Hippo CMS (and HST, repository etc. etc.)
>
> To post to this group, send email to hippo-c...@googlegroups.com
> RSS:
> https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
> ---
> You received this message because you are subscribed to the Google
> Groups "Hippo Community" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to hippo-communi...@googlegroups.com
> <mailto:hippo-communi...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/hippo-community.
> For more options, visit https://groups.google.com/d/optout.


--
w....@onehippo.com www.onehippo.com
Boston - 745 Atlantic Ave, 8th Floor, Boston MA 02111
Amsterdam - Oosteinde 11, 1017 WT Amsterdam

dummi...@gmail.com

unread,
Jun 25, 2015, 10:57:48 AM6/25/15
to hippo-c...@googlegroups.com, dummi...@gmail.com
OK, I was not aware of that. Now I configured the "_type" parameter correctly.

Now the request:
http://localhost:8080/site/restservices/something?_type=json

works fine, but
http://localhost:8080/site/restservices/something?_type=xml
returns
No message body writer has been found for response class ArrayList.


Actually, to put it more simple, I don't need that "_type" parameter, what I was actually trying was to make one of my REST methods to return XML instead of JSON. I have put @Produces(MediaType.APPLICATION_XML) on the method but I got the same message "no body writer...".

Could it be some additional configuration to "enable" XML ? Or maybe accept/content-type headers ?

Woonsan Ko

unread,
Jun 25, 2015, 11:15:18 AM6/25/15
to hippo-c...@googlegroups.com
If you see "No message body writer has been found for response class
ArrayList.", then it might be unrelated to the format option parameters.
Is your JAX-RS resource operation returning ArrayList object? So, that's
why CXF is complaining?
If so, can you try with a wrapper POJO having the list getter instead?

On 6/25/15 10:57 AM, dummi...@gmail.com wrote:
> OK, I was not aware of that. Now I configured the "_type" parameter
> correctly.
>
> Now the request: *
> http://localhost:8080/site/restservices/something?_type=json*
> works fine, but
> *http://localhost:8080/site/restservices/something?_type=xml*
> returns
>
> No message body writer has been found for response class ArrayList.
>
>
>
> Actually, to put it more simple, I don't need that "_type" parameter,
> what I was actually trying was to make one of my REST methods to return
> XML instead of JSON. I have put *@Produces(MediaType.APPLICATION_XML)*
> on the method but I got the same message "no body writer...".
>
> Could it be some additional configuration to "enable" XML ? Or maybe
> accept/content-type headers ?
>

Bert Leunis

unread,
Jul 6, 2015, 10:19:49 AM7/6/15
to hippo-c...@googlegroups.com
Hi Vlad,

Are you using the Rest service feature of Essentials? I believe that the setup used for that is not built for serving XML. It was originally built for 7.9, and is using HippoBeans instead of Representations. 7.9 had a restriction on using HippoBeans and exposing the output as XML. That has gone in version 10, but I don't know if this feature was updated to now also output XML.

Maybe somebody from the Engineering team can chime in about this.

--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-c...@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.

dummi...@gmail.com

unread,
Jul 8, 2015, 3:08:40 AM7/8/15
to hippo-c...@googlegroups.com
Hi Bert,


Sorry for not following-up on this, here's the latest news :).

I'm not sure what is the Rest service feature of Essentials; I use a normal plain Rest endpoint, as described here: http://www.onehippo.org/library/concepts/rest/restful-jax-rs-component-support-in-hst-2.html

I got it working eventually, Woosan indicated the right direction. I added the @XmlRootElement annotation on my representation class. It seems like is mandatory for producing XML output, but is not needed for JSON.

I still had an error though, the XML processor was complaining about duplicate attributes: "myField" and "getMyField()". I had to remove the getters and to make the fields public. Do you know another way ?


Best regards,
Vlad

Woonsan Ko

unread,
Jul 8, 2015, 7:15:34 AM7/8/15
to hippo-c...@googlegroups.com


   
On Jul 8, 2015 3:08 AM, <dummi...@gmail.com> wrote:
>

> I still had an error though, the XML processor was complaining about duplicate attributes: "myField" and "getMyField()". I had to remove the getters and to make the fields public. Do you know another way ?

Maybe did you have JAXB annotations on both the field and getter method? If so, you could've removed that on the field.
Otherwise, could you copy and paste code snippet?

Woonsan

>
>
> Best regards,
> Vlad

dummi...@gmail.com

unread,
Jul 10, 2015, 7:32:56 AM7/10/15
to hippo-c...@googlegroups.com, dummi...@gmail.com
No, I don't have JAXB annotations on both the field and gette. Here's snippet:

@XmlRootElement(name="coupon")
public class VoucherXMLRepresentation {

   
@XmlElement
   
public String brandLogo;

   
..........

   
public String getBrandLogo() {
       
return brandLogo;
   
}
   
public void setBrandLogo(String brandLogo) {
       
this.brandLogo = brandLogo;
   
}
   
.............
}


And the Exception is:

[INFO] [talledLocalContainer] 10.07.2015 14:25:47 WARN  http-bio-8080-exec-2 [AbstractJAXBProvider.handleExceptionStart:660] com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 22 counts of IllegalAnnotationExceptions
[INFO] [talledLocalContainer] Class has two properties of the same name "brandLogo"
[INFO] [talledLocalContainer]     this problem is related to the following location:
[INFO] [talledLocalContainer]         at public java.lang.String de.einsundeins.hippo.rest.sparclub.VoucherXMLRepresentation.getBrandLogo()
[INFO] [talledLocalContainer]         at de.einsundeins.hippo.rest.sparclub.VoucherXMLRepresentation
[INFO] [talledLocalContainer]     this problem is related to the following location:
[INFO] [talledLocalContainer]         at public java.lang.String de.einsundeins.hippo.rest.sparclub.VoucherXMLRepresentation.brandLogo
[INFO] [talledLocalContainer]         at de.einsundeins.hippo.rest.sparclub.VoucherXMLRepresentation

marijan milicevic

unread,
Jul 10, 2015, 7:40:17 AM7/10/15
to hippo-c...@googlegroups.com, dummi...@gmail.com
just annotate your classes with: 
@XmlAccessorType(XmlAccessType.FIELD)

cheers
marijan

dummi...@gmail.com

unread,
Jul 10, 2015, 8:30:22 AM7/10/15
to hippo-c...@googlegroups.com, dummi...@gmail.com
Yeah, damn it, I forgot about that :).

It's fine now. Thanks !

Cheers,
Vlad
Reply all
Reply to author
Forward
0 new messages