I am attempting to access a Wink Resource that should be deployed in tomcat. The Resource code is
@Path("/lookup")
public class LookupResource {
private static final Logger logger = LoggerFactory.getLogger(LookupResource.class);
private MetaService metaService;
/**
*
*/
public LookupResource() {
logger.debug("CTOR +-");
}
/**
* @return the metaService
*/
public MetaService getMetaService() {
return metaService;
}
/**
* @param metaService the metaService to set
*/
public void setMetaService(MetaService metaService) {
logger.debug(String.format("Setting Meta Svc: %s ", metaService));
this.metaService = metaService;
}
@GET
@Path("/states")
@Produces("application/json")
public JSONObject getStates() {
final String METHOD = "getMessage";
JSONObject answer = new JSONObject();
try {
logger.debug(String.format("%s +", METHOD));
List<Lookup> states = getMetaService().findStates();
for (Lookup state : states) {
answer.put("Lookup", state);
}
} catch (JSONException e) {
logger.debug("Problem", e);
} finally {
logger.debug(String.format("%s -", METHOD));
}
return answer;
}
}
I added Spring to the web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:META-INF/server/wink-core-context.xml
classpath:my-server.xml
classpath:my-webapp.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
And in my-webapp.xml spring configuration I registered the Resource
<bean id="lookupResource" class="com.codeheadllc.webapp.LookupResource" >
<property name="metaService" ref="metaService" />
</bean>
<bean class="org.apache.wink.spring.Registrar">
<property name = "instances">
<set>
<ref bean="lookupResource"/>
</set>
</property>
</bean>
When I deploy and start tomcat I see in the logger that my LookupResource bean is loaded and it gets a reference to the metaService. However, when I hit http:///my-webapp/lookup/states, instead of accessing LookupResouce, I get a 404 message. I am sure it is a bonehead oversight, but I do not understand what I am doing wrong. If I add a servlet to the web.xml for RestServlet and add a mapping, say rest/*, then the RestServlet will create a new instance of LookupResource (without spring IOC) and attempt to execute the method.
Any help will be appreciated