Re: get all form parameters programmatic

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: get all form parameters programmatic

miroslav fuksa
Hi,

If you speak about Jersey2/JAX-RS 2.0, you can use "javax.ws.rs.core.Form" and define it as an entity.

For example:
        @POST
        public String post(Form form) {
            ...
        }

Form is an entity parameter. You can then call "form.asMap()" to get map or form params.

Mira




On 6.5.2013 4:34, Hingarajiya,Ravi wrote:
I am looking Is there any way to get all form parameters programmatic way instead of @FormParam annotation.
I may not know all Form Parameter key during developing JAXRS REST Service. We can't use @FormParam in this situation APIk.
I can retrieve all query parameters using @Context. I am looking similar way to get all form parameters.
  
    @POST
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    @Produces(MediaType.APPLICATION_JSON)
    public String post(@Context UriInfo uriinfo) {
        MultivaluedMap<String, String> params = uriinfo.getQueryParameters();
    
    }


Thanks,
Ravi Hingarajiya

Reply | Threaded
Open this post in threaded view
|

Re: get all form parameters programmatic

Hingarajiya,Ravi
Hi Mira, 

Thanks for the prompt response. 

I am using Jersey 1.8.1 library. It is difficult to move from 1.8.1 to 2.0. 
Is there any option in Jersey 1.8.1 ? 

Thanks,
Ravi



On Mon, May 6, 2013 at 4:43 AM, miroslav fuksa <[hidden email]> wrote:
Hi,

If you speak about Jersey2/JAX-RS 2.0, you can use "javax.ws.rs.core.Form" and define it as an entity.

For example:
        @POST
        public String post(Form form) {
            ...
        }

Form is an entity parameter. You can then call "form.asMap()" to get map or form params.

Mira





On 6.5.2013 4:34, Hingarajiya,Ravi wrote:
I am looking Is there any way to get all form parameters programmatic way instead of @FormParam annotation.
I may not know all Form Parameter key during developing JAXRS REST Service. We can't use @FormParam in this situation APIk.
I can retrieve all query parameters using @Context. I am looking similar way to get all form parameters.
  
    @POST
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    @Produces(MediaType.APPLICATION_JSON)
    public String post(@Context UriInfo uriinfo) {
        MultivaluedMap<String, String> params = uriinfo.getQueryParameters();
    
    }


Thanks,
Ravi Hingarajiya


Reply | Threaded
Open this post in threaded view
|

Re: get all form parameters programmatic

miroslav fuksa
Hi Ravi,

in Jersey 1 you can use

com.sun.jersey.api.representation.Form

in the similar way.

Jersey 2 has not yet been finally released but you can use latest not final release to play with. How difficult the migration is depends on how much of Jersey 1 API you use (depends a lot on your particular project).

Mira


On 6.5.2013 19:57, Hingarajiya,Ravi wrote:
Hi Mira, 

Thanks for the prompt response. 

I am using Jersey 1.8.1 library. It is difficult to move from 1.8.1 to 2.0. 
Is there any option in Jersey 1.8.1 ? 

Thanks,
Ravi



On Mon, May 6, 2013 at 4:43 AM, miroslav fuksa <[hidden email]> wrote:
Hi,

If you speak about Jersey2/JAX-RS 2.0, you can use "javax.ws.rs.core.Form" and define it as an entity.

For example:
        @POST
        public String post(Form form) {
            ...
        }

Form is an entity parameter. You can then call "form.asMap()" to get map or form params.

Mira





On 6.5.2013 4:34, Hingarajiya,Ravi wrote:
I am looking Is there any way to get all form parameters programmatic way instead of @FormParam annotation.
I may not know all Form Parameter key during developing JAXRS REST Service. We can't use @FormParam in this situation APIk.
I can retrieve all query parameters using @Context. I am looking similar way to get all form parameters.
  
    @POST
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    @Produces(MediaType.APPLICATION_JSON)
    public String post(@Context UriInfo uriinfo) {
        MultivaluedMap<String, String> params = uriinfo.getQueryParameters();
    
    }


Thanks,
Ravi Hingarajiya



Reply | Threaded
Open this post in threaded view
|

Re: get all form parameters programmatic

Hingarajiya,Ravi
Thanks Mira. 
It works for me. 

Thanks,
Ravi Hingarajiya 


On Tue, May 7, 2013 at 7:11 AM, Miroslav Fuksa <[hidden email]> wrote:
Hi Ravi,

in Jersey 1 you can use

com.sun.jersey.api.representation.Form

in the similar way.

Jersey 2 has not yet been finally released but you can use latest not final release to play with. How difficult the migration is depends on how much of Jersey 1 API you use (depends a lot on your particular project).

Mira



On 6.5.2013 19:57, Hingarajiya,Ravi wrote:
Hi Mira, 

Thanks for the prompt response. 

I am using Jersey 1.8.1 library. It is difficult to move from 1.8.1 to 2.0. 
Is there any option in Jersey 1.8.1 ? 

Thanks,
Ravi



On Mon, May 6, 2013 at 4:43 AM, miroslav fuksa <[hidden email]> wrote:
Hi,

If you speak about Jersey2/JAX-RS 2.0, you can use "javax.ws.rs.core.Form" and define it as an entity.

For example:
        @POST
        public String post(Form form) {
            ...
        }

Form is an entity parameter. You can then call "form.asMap()" to get map or form params.

Mira





On 6.5.2013 4:34, Hingarajiya,Ravi wrote:
I am looking Is there any way to get all form parameters programmatic way instead of @FormParam annotation.
I may not know all Form Parameter key during developing JAXRS REST Service. We can't use @FormParam in this situation APIk.
I can retrieve all query parameters using @Context. I am looking similar way to get all form parameters.
  
    @POST
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    @Produces(MediaType.APPLICATION_JSON)
    public String post(@Context UriInfo uriinfo) {
        MultivaluedMap<String, String> params = uriinfo.getQueryParameters();
    
    }


Thanks,
Ravi Hingarajiya




Reply | Threaded
Open this post in threaded view
|

Re: get all form parameters programmatic

Utkarsh Agarwal
In reply to this post by miroslav fuksa
Hi I tried the method suggested by you.
It works well if there is no '=' in the form params.
But in my case I am sending some data which contains '=' as a part of the String .For eg:
If the form param is :
name="he=llo"
It will give the value as 'he' only which is wrong.

Is there any way to handle such situation??