Hi
I am using the following:
Tomcat 7.0.52
Windows 7
IntelliJ 13 Ultimate
JUnit 4.11
Jersey 2.5.1
Maven
My REST Api makes minimal use of the web.xml file and instead I
extended the javax.ws.rs.core.Application class with my own class.
@ApplicationPath("/")
public class RestApiApplication extends Application {
/**
* Get a set of root resource, provider and {@link
javax.ws.rs.core.Feature feature} classes.
*
* @return a set of root resource and provider classes. Returning
{@code null}
* is equivalent to returning an empty set.
*/
@Override
public Set<Class<?>> getClasses() {
System.out.print("*********\n\n\n************\n\n\n**********\n\n\n*********");
final Set<Class<?>> resourceClasses = new HashSet<Class<?>>();
// api classes
resourceClasses.add(SendFileToUsers.class);
// required for jason
resourceClasses.add(JacksonJsonProvider.class);
// required for multipart form uploads
resourceClasses.add(MultiPartFeature.class);
return resourceClasses;
}
}
I am trying to do some integration testing using the embedded tomcat
7. Everything seems to be working except that I cannot figure out how
to tell tomcat to use my RestApiApplication class. When I deploy to an
instance of tomcat it automatically scans and finds this class and the
getClasses() method is called. I do not know how to do this from code.
So far I have this:
try {
String webappDirLocation = "rest_api/src/main/webapp/";
Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
tomcat.enableNaming();
Context ctx = tomcat.addWebapp("", new
File(webappDirLocation).getAbsolutePath());
tomcat.start();
tomcat.getServer().await();
} catch (Exception e) {
e.printStackTrace();
}
This starts up my tomcat fine. I just need some help on setting it up
to call the Application getClasses().
Please help.
Richard
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]