...
In the dependencies section insert the appropriate bitrepository dependencies and the following required for jersey:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-server</artifactId> <version>1.8</version> </dependency> <dependency> <groupId>javax.ws.rs</groupId> <artifactId>jsr311-api</artifactId> <version>1.1</version> </dependency> |
...
To enable an applicationserver (say Tomcat), to expose the REST methods, a web.xml file needs to be setup. The file should be placed in src/main/webapp/WEB-INF/web.xml. web.xml file from the bitrepository-webclient can serve as an example:
Code Block | lang | xml|||
---|---|---|---|---|
| ||||
<?xml version="1.0" encoding="UTF-8"?> <web-app> <display-name>Bitrepository webservice</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index-v1.html</welcome-file> </welcome-file-list> <servlet> <servlet-name>Bitrepository-webclient</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>org.bitrepository.webservice</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>Bitrepository-webclient</servlet-name> <url-pattern>/repo/*</url-pattern> </servlet-mapping> <listener> <listener-class>org.bitrepository.webservice.ShutdownListener</listener-class> </listener> </web-app> |
...
By running its constructor with the path and filename to a logback configuration file (i.e. logback.xml), logback can be configured. This should be done from the 'ShutdownListener' referred to in the web.xml file above.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
public class LogbackConfigLoader { private Logger log = LoggerFactory.getLogger(LogbackConfigLoader.class); public LogbackConfigLoader(String configFileLocation) throws IOException, JoranException{ LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); File configFile = new File(configFileLocation); if(!configFile.exists()){ throw new IOException("Logback External Config File Parameter does not reference a file that exists"); } if(!configFile.isFile()){ throw new IOException("Logback External Config File Parameter exists, but does not reference a file"); } if(!configFile.canRead()){ throw new IOException("Logback External Config File exists and is a file, but cannot be read."); } JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(loggerContext); loggerContext.reset(); configurator.doConfigure(configFileLocation); log.info("Configured Logback with config file from: " + configFileLocation); } } |