I have a Webservice using jersey. I want to access a hashmap which is created in a servlet from rest service. That hashmap in servlet sholud be created only once during application startup. this is web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>GrpService_Map</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.ericsson.mapService</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
Service class TestSErvice is within com.ericsson.mapService package .My question is where will I place the required servlet that creates the hashmap and how will I access that map from TestSErvice ? This is my service class TestService.java
@Path("/Service")
public class TestService {
@GET
@Consumes("application/xml")
@Produces(MediaType.TEXT_PLAIN)
@Path("/cacheserviceTestMap")
public String createGroupCache(@Context HttpServletRequest request)
throws IOException {
//here i want to access the IndexMap hashmap
return "Success";
}
}
This is my servlet class
public class TestSerlvet extends HttpServlet{
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
Map<String, Map<String,List<String>>> IndexMap = new HashMap<String, Map<String,List<String>>>();
Map<String,List<String>> signumMap = new HashMap<String,List<String>>();
List<String> grp = new ArrayList<String>();
grp.add("1");
grp.add("2");
signumMap.put("eab", grp);
signumMap.put("eabc",grp);
signumMap.put("exy",grp);
IndexMap.put("I", signumMap);
}
}
Thank you