1 package org.kuali.ole.web;
2
3 import org.kuali.ole.docstore.OleException;
4 import org.kuali.ole.docstore.model.xmlpojo.ingest.Response;
5 import org.kuali.ole.docstore.model.xstream.ingest.ResponseHandler;
6 import org.kuali.ole.service.MultiPartBagRequestClient;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9
10 import javax.servlet.ServletException;
11 import javax.servlet.http.HttpServlet;
12 import javax.servlet.http.HttpServletRequest;
13 import javax.servlet.http.HttpServletResponse;
14 import java.io.IOException;
15 import java.io.PrintWriter;
16 import java.util.List;
17
18
19
20
21
22
23
24 public class MultiPartBagRequestClientServlet extends HttpServlet {
25 private static final long serialVersionUID = 1L;
26 private Logger logger = LoggerFactory.getLogger(MultiPartBagRequestClientServlet.class);
27 private ResponseHandler rh = new ResponseHandler();
28
29 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
30 doPost(request, response);
31 }
32
33 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
34 String requestFolderPath = request.getParameter("requestFolderPath");
35 String restUrl = request.getParameter("restUrl");
36 PrintWriter out = response.getWriter();
37 logger.debug("restUrl-->" + restUrl);
38 logger.debug("requestFolderPath-->" + requestFolderPath);
39 out.println("<responses>");
40 try {
41 List<Response> responses = new MultiPartBagRequestClient().runMultiPartRequestsAtLocation(requestFolderPath, restUrl);
42 response.setContentType("text/xml");
43 for (Response resp : responses)
44 out.println(rh.toXML(resp));
45 out.println("</responses>");
46 } catch (OleException e) {
47 out.print(e.getMessage());
48 logger.error(e.getMessage());
49 } catch (Exception e) {
50 out.print(e.getMessage());
51 logger.error(e.getMessage(), e);
52 }
53 }
54
55 }