Get the project
The advanse-api code is available on GitLab. Feel free to fork, change and do pull requests to add new services.
Get the code
git clone https://gite.lirmm.fr/advanse/advanse-api.git
Build the war using Maven
mvn clean package
Upload the war to Tomcat7
Edit the API
You can add an example on how to use your service in the src/main/webapp/index.html file
You can add and configure servlet mappings in the src/main/webapp/WEB-INF/web.xml file
You can find example on how to upload files in the servet project: the simple html code and the java servlet code
Create a new servlet
To add a new servlet use the ApiResponseWrapper to define a new Response It allows to get the response with generic parameters already defined (character encoding on UTF-8, Access-Control-Allow-Origin header for javascript query). But the response parameters can still be changed (in the following example we are changing the response content type through the wrapper)
@WebServlet("/mynewservlet") public class MyNewServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ApiResponseWrapper wrapper = new ApiResponseWrapper(response); PrintWriter out = wrapper.getWriter(); // Changing the reponse content-type wrapper.setContentType("text/plain"); String text = request.getParameter("text"); out.print(Pretraitements.ReplaceArgots(text)); } }
Add your program to the API
Import your jar in the pom.xml of the advanse-api java API
Import the class you want to use in the servlet Class
import fr.lirmm.advanse.textpreprocessing.Preprocessing;
Example by lemmatizing words using the Preprocessing library
package fr.lirmm.advanse.advanse_api.Preprocessing; import fr.lirmm.advanse.advanse_api.ApiResponseWrapper; import fr.lirmm.advanse.textpreprocessing.Preprocessing; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.annotation.WebServlet; @WebServlet("/preprocessing/argot") protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ApiResponseWrapper wrapper = new ApiResponseWrapper(response); PrintWriter out = wrapper.getWriter(); String text = request.getParameter("text"); if (text != null) { // Path to TreeTagger on the server Lemmatizer lm = new Lemmatizer("/data/TreeTagger"); try { out.print(lm.lemmatize(text)); } catch (Exception ex) { out.print("BUUUUG"); } } else { out.print(wrapper.defaultResponse); } }