Hi
On 23/04/14 11:27, Maxim Solodovnik wrote:
Hello Sergey,

using the following calls
wget --header="Accept: application/json"
http://localhost:5080/openmeetings/services/rest/user/session
wget
http://localhost:5080/openmeetings/services/rest/user/session?_type=json

I'm able to get json answer

Thanks for the hint

Is it possible to create endpoint returning "json-only" based on bean able
to serve both xml and json

So I can have butyful URL like
http://localhost:5080/openmeetings/services/json/user/session
To get json in browser

You will probably need to restrict it at the filter level, example, introduce ContainerRequestFilter, call getAcceptableMediaTypes on the context parameter passed to the filter, if you have XML coming before JSON then abort the request or, if both XML & JSON are accepted then update Accept header to make sure JSON is selected...

Cheers, Sergey

Thanks in advance






On Tue, Apr 22, 2014 at 4:14 PM, Sergey Beryozkin <[email protected]>wrote:

Hi

Generally speaking you do noty have to set up multiple endpoints to get
multiple formats supported.

Can you confirm please you have

Accept: application/json

as part of

http://localhost:8080/app/json/user

Sergey


On 22/04/14 04:24, Maxim Solodovnik wrote:

Additional info: CXF version 2.7.11


On Sun, Apr 20, 2014 at 11:27 AM, Maxim Solodovnik <[email protected]
wrote:

  Hello All,

I would like to set output format based on URL i.e. if request received
at
http://localhost:8080/app/json/user the response should be in JSON
format
I have tried to set up 2 jaxrs:server

<bean id="jsonProvider"
class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
   <!-- (writeXsiType=false) -->
<property name="ignoreNamespaces" value="true" />
   </bean>
<bean id="jaxbProvider"
class="org.apache.cxf.jaxrs.provider.JAXBElementProvider"/>
   <jaxrs:server id="serverRest" address="/rest">
<jaxrs:serviceBeans>
<ref bean="userWebService"/>
   </jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jaxbProvider"/>
   </jaxrs:providers>
</jaxrs:server>
<jaxrs:server id="serverJson" address="/json">
   <jaxrs:serviceBeans>
<ref bean="userWebService"/>
</jaxrs:serviceBeans>
   <jaxrs:providers>
<ref bean="jsonProvider"/>
</jaxrs:providers>
   </jaxrs:server>

Unfortunately no matter what URL am I accessing I get XML response :(

userWebService bean id annotated as follows:

@WebService
@Features(features = "org.apache.cxf.feature.LoggingFeature")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Path("/user")
public class UserWebService {
}

Thanks in advance


--
WBR
Maxim aka solomax











--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Reply via email to