You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Jayakumar Mounagurusamy <ja...@hotmail.com> on 2014/04/20 22:50:50 UTC

Jeresy MVC jsp question -



I am following the  “bookstore-webapp”
jersey example project , in my index.jsp 
I am not getting the values build in “getData()” method in the index.jsp when the
resource is invoked, I suspect even the method is getting executed. In the below example for the variable "userAgentString" i getting the initialized value not the derived one make me think the “getData()” is not being invoked

 

Basically this is what I am trying to accomplish, provide a REST
API, send to a JSP page with client OS, browser information extracted from the
httpserveletRequest. Can you please point out what I am doing wrong here? 

 

The below Install.java is the resource class 

 

package me.install.resource;

 

import java.util.Map;

import java.util.TreeMap;

 

import
javax.inject.Singleton;

import
javax.servlet.http.HttpServletRequest;

import javax.ws.rs.GET;

import javax.ws.rs.POST;

import javax.ws.rs.Path;

import
javax.ws.rs.Produces;

import
javax.ws.rs.core.Context;

import
javax.ws.rs.core.MediaType;

import
javax.xml.bind.annotation.XmlAccessType;

import
javax.xml.bind.annotation.XmlAccessorType;

import
javax.xml.bind.annotation.XmlRootElement;

 

import
org.glassfish.jersey.server.mvc.Template;

 

import
eu.bitwalker.useragentutils.*;

 

@Path("/")

@Singleton

@Template

@Produces("text/html;qs=5")

@XmlRootElement

@XmlAccessorType(XmlAccessType.FIELD)

public class Install {

 

       private final Map<String,
String> opMap = new TreeMap<String, String>();

 

       //Browser br;

       int id;

       //Version brVersion;

       

       String userAgentString = "Did not get
info from Header";

 

       public Install() {

 

       }

 

       public Map<String, String> getOpMap()
{

              return opMap;

       }

 

       public int getId() {

              return id;

       }

 

       @GET 

       @Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML,

                     MediaType.APPLICATION_JSON })

       public Install getData(@Context HttpServletRequest
request) {

              

              System.out.println("In Get
Method");

 

              extractData(request);

              System.out.println("Done - In Get
Method");

 

              return this;

       }

       

       @POST

       @Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML,

                     MediaType.APPLICATION_JSON })

       public Install getDataPost(@Context HttpServletRequest
request) {

              

              System.out.println("In Post
Method");

 

              extractData(request);

              System.out.println("Done - In
Post Method");

 

              return this;

       }

       

       private void
extractData(HttpServletRequest request)

       {

              userAgentString = request.getHeader("user-agent");

              System.out.println("userAgentString
= "
+ userAgentString);

              UserAgent userAgent = new UserAgent(userAgentString);

              // Unique id of the client type

              id = userAgent.getId();

              // information on Operating system.

              buildOperatingSystem(userAgent.getOperatingSystem());

 

              //br =
userAgent.getBrowser();

              //brVersion =
userAgent.getBrowserVersion();

              

       }

 

       public String getUserAgentString() {

              return userAgentString;

       }

 

       private void
buildOperatingSystem(OperatingSystem op) {

              opMap.put("OS Name", op.getName());

              opMap.put("OS Normalized Name", op.name());

 

       }

}



 		 	   		  

Re: Jeresy MVC jsp question -

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

Did you debug your code? Then this is not a jersey mvc code afaik but just
a standard rest service.
Le 20 avr. 2014 21:51, "Jayakumar Mounagurusamy" <ja...@hotmail.com> a
écrit :

>
>
>
> I am following the  “bookstore-webapp”
> jersey example project , in my index.jsp
> I am not getting the values build in “getData()” method in the index.jsp
> when the
> resource is invoked, I suspect even the method is getting executed. In the
> below example for the variable "userAgentString" i getting the initialized
> value not the derived one make me think the “getData()” is not being invoked
>
>
>
> Basically this is what I am trying to accomplish, provide a REST
> API, send to a JSP page with client OS, browser information extracted from
> the
> httpserveletRequest. Can you please point out what I am doing wrong here?
>
>
>
> The below Install.java is the resource class
>
>
>
> package me.install.resource;
>
>
>
> import java.util.Map;
>
> import java.util.TreeMap;
>
>
>
> import
> javax.inject.Singleton;
>
> import
> javax.servlet.http.HttpServletRequest;
>
> import javax.ws.rs.GET;
>
> import javax.ws.rs.POST;
>
> import javax.ws.rs.Path;
>
> import
> javax.ws.rs.Produces;
>
> import
> javax.ws.rs.core.Context;
>
> import
> javax.ws.rs.core.MediaType;
>
> import
> javax.xml.bind.annotation.XmlAccessType;
>
> import
> javax.xml.bind.annotation.XmlAccessorType;
>
> import
> javax.xml.bind.annotation.XmlRootElement;
>
>
>
> import
> org.glassfish.jersey.server.mvc.Template;
>
>
>
> import
> eu.bitwalker.useragentutils.*;
>
>
>
> @Path("/")
>
> @Singleton
>
> @Template
>
> @Produces("text/html;qs=5")
>
> @XmlRootElement
>
> @XmlAccessorType(XmlAccessType.FIELD)
>
> public class Install {
>
>
>
>        private final Map<String,
> String> opMap = new TreeMap<String, String>();
>
>
>
>        //Browser br;
>
>        int id;
>
>        //Version brVersion;
>
>
>
>        String userAgentString = "Did not get
> info from Header";
>
>
>
>        public Install() {
>
>
>
>        }
>
>
>
>        public Map<String, String> getOpMap()
> {
>
>               return opMap;
>
>        }
>
>
>
>        public int getId() {
>
>               return id;
>
>        }
>
>
>
>        @GET
>
>        @Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML,
>
>                      MediaType.APPLICATION_JSON })
>
>        public Install getData(@Context HttpServletRequest
> request) {
>
>
>
>               System.out.println("In Get
> Method");
>
>
>
>               extractData(request);
>
>               System.out.println("Done - In Get
> Method");
>
>
>
>               return this;
>
>        }
>
>
>
>        @POST
>
>        @Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML,
>
>                      MediaType.APPLICATION_JSON })
>
>        public Install getDataPost(@Context HttpServletRequest
> request) {
>
>
>
>               System.out.println("In Post
> Method");
>
>
>
>               extractData(request);
>
>               System.out.println("Done - In
> Post Method");
>
>
>
>               return this;
>
>        }
>
>
>
>        private void
> extractData(HttpServletRequest request)
>
>        {
>
>               userAgentString = request.getHeader("user-agent");
>
>               System.out.println("userAgentString
> = "
> + userAgentString);
>
>               UserAgent userAgent = new UserAgent(userAgentString);
>
>               // Unique id of the client type
>
>               id = userAgent.getId();
>
>               // information on Operating system.
>
>               buildOperatingSystem(userAgent.getOperatingSystem());
>
>
>
>               //br =
> userAgent.getBrowser();
>
>               //brVersion =
> userAgent.getBrowserVersion();
>
>
>
>        }
>
>
>
>        public String getUserAgentString() {
>
>               return userAgentString;
>
>        }
>
>
>
>        private void
> buildOperatingSystem(OperatingSystem op) {
>
>               opMap.put("OS Name", op.getName());
>
>               opMap.put("OS Normalized Name", op.name());
>
>
>
>        }
>
> }
>
>
>
>