1 package org.kuali.ole.web;
2
3 import com.google.common.io.CharStreams;
4 import org.kuali.ole.docstore.common.exception.DocstoreException;
5 import org.kuali.ole.docstore.common.exception.DocstoreExceptionProcessor;
6 import org.kuali.ole.docstore.common.search.SearchParams;
7 import org.kuali.ole.docstore.common.search.SearchResponse;
8 import org.kuali.ole.docstore.common.service.DocstoreService;
9 import org.kuali.ole.docstore.service.BeanLocator;
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
12 import javax.servlet.ServletException;
13 import javax.servlet.http.HttpServlet;
14 import javax.servlet.http.HttpServletRequest;
15 import javax.servlet.http.HttpServletResponse;
16 import java.io.IOException;
17 import java.io.PrintWriter;
18
19
20
21
22
23
24
25
26
27 public class SearchRestServlet extends HttpServlet {
28 private static final Logger LOG = LoggerFactory.getLogger(SearchRestServlet.class);
29
30
31 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
32 PrintWriter out = resp.getWriter();
33 String requestBody = CharStreams.toString(req.getReader());
34 DocstoreService ds = BeanLocator.getDocstoreService();
35 SearchParams searchParams = new SearchParams();
36 searchParams = (SearchParams) searchParams.deserialize(requestBody);
37 SearchResponse searchResponse = null;
38 try {
39 searchResponse = ds.search(searchParams);
40 } catch (DocstoreException e) {
41 LOG.error("Exception : ", e);
42 out.print(DocstoreExceptionProcessor.toXml(e));
43 }
44 out.print(searchResponse.serialize(searchResponse));
45
46 }
47 }