Hi Milan,
I created a bean class as you suggested and tried to get the json parsed
using JAX-RS, but i keep on encountering a
unsupported media type error when i use CURL to send the request.
my bean class
*public class UmaRptRequestPayloadBean {*
* private String ticket;*
* private String rpt;*
* public UmaRptRequestPayloadBean() {*
* }*
* public String getTicket() {*
* return ticket;*
* }*
* public void setTicket(String ticket) {*
* this.ticket = ticket;*
* }*
* public String getRpt() {*
* return rpt;*
* }*
* public void setRpt(String rpt) {*
* this.rpt = rpt;*
* }*
*}*
my service class
*@Path("/rpt")*
*public class UmaAuthorizationEndpoint {*
* private static final Log log =
LogFactory.getLog(UmaAuthorizationEndpoint.class);*
* @POST*
* @Path("/")*
* @Consumes("application/json")*
* @Produces("application/json")*
* public Response issueRPT(@Context HttpServletRequest
request,UmaRptRequestPayloadBean payloadBean){*
* // rest of the code*
* }*
*}*
CURL command
curl -H "Accept:application/json" -H "Content-type:application/json" -X
POST -d '{"rpt":"dsafsdfs","ticket":"adffsdfsdfds"}'
https://localhost:9443/uma/rpt -k -v
Do i have to use any mapping or configuration parameter to get JAX-RS to
parse the JSON to the bean?
On Mon, Jun 15, 2015 at 2:01 PM, Farazath Ahamed <[email protected]>
wrote:
> Thanks Milan.
> I will try out your suggestion.
>
> On Mon, Jun 15, 2015 at 8:27 AM, Milan Perera <[email protected]> wrote:
>
>> Hi Farazath,
>>
>> Instead of parsing the string manually, you can create a java bean class
>> so that JAX-RS will parse it for you.
>> For an example, let's say you have a json payload like this.
>>
>> {
>> "fname": "Farazath",
>> "lname": "Ahamed"
>> }
>>
>> So you can create a java bean like this.
>>
>> class User {
>> private String fname;
>> private String lname;
>>
>> // getters and setters for above attributes
>> }
>>
>> Then your method signature has to be changed to,
>>
>> *public Response issueRPT(@Context HttpServletRequest request, User user)*
>>
>> Hope this would help you.
>>
>> Regards,
>>
>> On Mon, Jun 15, 2015 at 4:35 AM, Farazath Ahamed <[email protected]>
>> wrote:
>>
>>> Hi,
>>>
>>> I am in the process of developing a REST API using JAX-RS.
>>> The incoming request to the endpoint contains a JSON payload which needs
>>> to be processed.
>>>
>>> Currently I am using the following approach to access the payload
>>>
>>> @Path("/rpt")
>>> public class UmaAuthorizationEndpoint {
>>>
>>> private static final Log log =
>>> LogFactory.getLog(UmaAuthorizationEndpoint.class);
>>>
>>> @POST
>>> @Path("/")
>>> @Consumes("application/json")
>>> @Produces("application/json")
>>> *public Response issueRPT(@Context HttpServletRequest
>>> request,@Multipart(value="application/json") String jsonPayload){*
>>>
>>> *// rest of the code*
>>> *}*
>>>
>>> I am using the @Multipart annotation to get the payload as a String and
>>> continue with parsing the JSON.
>>>
>>>
>>> Is this the usual approach? If not, Is there an alternative approach to
>>> do this?
>>>
>>>
>>> --
>>> *A.Farasath Ahamed*
>>> Undergraduate | Department of Computer Science and
>>> Engineering,University of Moratuwa
>>> Article Writer | MoraSpirit
>>> Mobile: +94 777 603 866
>>> Blog: http://thepseudocode.blogspot.com
>>> E-Mail: [email protected]
>>>
>>> _______________________________________________
>>> Dev mailing list
>>> [email protected]
>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>
>>>
>>
>>
>> --
>> Milan Harindu Perera
>> Software Engineer
>> *WSO2, Inc*
>> (+94) 77 309 7088
>> lean . enterprise . middleware
>> <http://lk.linkedin.com/in/milanharinduperera>
>>
>
>
>
> --
> *A.Farasath Ahamed*
> Undergraduate | Department of Computer Science and Engineering,University
> of Moratuwa
> Article Writer | MoraSpirit
> Mobile: +94 777 603 866
> Blog: http://thepseudocode.blogspot.com
> E-Mail: [email protected]
>
--
*A.Farasath Ahamed*
Undergraduate | Department of Computer Science and Engineering,University
of Moratuwa
Article Writer | MoraSpirit
Mobile: +94 777 603 866
Blog: http://thepseudocode.blogspot.com
E-Mail: [email protected]
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev