users@jersey.java.net

[Jersey] Re: Re:Implementation of POST

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Mon, 10 Oct 2011 17:12:32 +0200

On 10/10/11 1:12 PM, bharat maharajan wrote:
>
> Hi Pavel,
>
> In our application we are implementing a GET method as follows,
> @Path("{serviceCommand}")
> public class OutboundServices {
> private static LoginServiceBO loginServiceBO;
> private static Logger logger = Logger.getLogger(OutboundServices.class);
> @GET
> @Consumes("text/plain")
> @Produces("text/plain;charset=utf-8")
> public String callService(
> @PathParam("serviceCommand") String servicecommand,
> @Context UriInfo info,
> @QueryParam(OutboundConstants.SECURITYTOKEN) String securityToken,
> @QueryParam(OutboundConstants.START_ARTICLE_NUM) String startNumber,
> @QueryParam(OutboundConstants.END_ARTICLE_NUM) String resultNo,
> @DefaultValue(OutboundConstants.DESC)
> @QueryParam(OutboundConstants.POSTORDER) String postorder,
> @QueryParam("username") String userName,
> @QueryParam("password") String hashword,
> @QueryParam("passwordtype") String passwordType)
> {
> if(logger.isInfoEnabled()){
> logger.info <http://logger.info>("serviceCommand in callService =" +
> servicecommand);
> }
>
> servicecommand = servicecommand.toLowerCase();
> String response = null;
> String
> format=info.getQueryParameters().getFirst(OutboundConstants.FORMAT);
> if (servicecommand.equals(OutboundConstants.MESSAGES)) {
> response = getMessages(info, startNumber, resultNo, postorder,
> securityToken, servicecommand);
> }
> else if (servicecommand.equals(OutboundConstants.LOGIN)) {
> response = login(userName, hashword, passwordType);
> }
> return getResponseInFormat(format, response,servicecommand);
> }
> }
> How can the POST method be implemented for the same ? Can you explain
> the concept for the implementation?

just replace @GET with @POST, as I wrote earlier:

@Path("{serviceCommand}")
public class OutboundServices {
  private static LoginServiceBO loginServiceBO;
  private static Logger logger = Logger.getLogger(OutboundServices.class);

  @POST
  @Consumes("text/plain")
  @Produces("text/plain;charset=utf-8")
  public String callService(
    @PathParam("serviceCommand") String servicecommand,
    @Context UriInfo info,
    @QueryParam(OutboundConstants.SECURITYTOKEN) String securityToken,
    @QueryParam(OutboundConstants.START_ARTICLE_NUM) String startNumber,
    @QueryParam(OutboundConstants.END_ARTICLE_NUM) String resultNo,
    @DefaultValue(OutboundConstants.DESC)
@QueryParam(OutboundConstants.POSTORDER) String postorder,
    @QueryParam("username") String userName,
    @QueryParam("password") String hashword,
    @QueryParam("passwordtype") String passwordType)
  {
   if(logger.isInfoEnabled()){
logger.info <http://logger.info>("serviceCommand in callService =" +
servicecommand);
   }

   servicecommand = servicecommand.toLowerCase();
   String response = null;
   String
format=info.getQueryParameters().getFirst(OutboundConstants.FORMAT);
   if (servicecommand.equals(OutboundConstants.MESSAGES)) {
    response = getMessages(info, startNumber, resultNo, postorder,
      securityToken, servicecommand);
   }
   else if (servicecommand.equals(OutboundConstants.LOGIN)) {
    response = login(userName, hashword, passwordType);
   }
   return getResponseInFormat(format, response,servicecommand);
  }
}

I'm not sure what do you mean by "concept of the implementation" in
current context; please ask more specific question if you can..

Pavel

> Thanks for your help in advance.
>
>
> ---------- Forwarded message ----------
> From: *Pavel Bucek* <pavel.bucek_at_oracle.com
> <mailto:pavel.bucek_at_oracle.com>>
> Date: Thu, Oct 6, 2011 at 12:35 AM
> Subject: [Jersey] Re:
> To: users_at_jersey.java.net <mailto:users_at_jersey.java.net>
>
>
> Hello Bharat,
>
> answers inline.
>
>
> On 10/5/11 7:10 AM, bharat.m69_at_gmail.com
> <mailto:bharat.m69_at_gmail.com> wrote:
>
> Hi,
>
> Currently we have implemented the GET method in our application.
>
> Can anyone tell me how the POST method could be implemented with
> minimum changes?
>
> replace @GET with @POST.
>
> you might want to study our user guide:
> http://jersey.java.net/nonav/documentation/latest/jax-rs.html#d4e137
>
>
> What is the maximum character limit for GET method and POST
> method?
>
> in what context? Entity can be theoretically indefinite (it can be
> stream); url length is something different - it may be
> theoretically indefinite as well, but browsers usually limit its
> size to ~2000 characters.
>
>
> Can you explain the implementation of POST method.
>
> see http protocol rfc:
> http://www.w3.org/Protocols/rfc2616/rfc2616.html
>
>
> Regards,
> Pavel
>
>
>
> Thanks,
> Bharat
>
>
>
>
>