View Javadoc

1   /*
2    * SymmetricDS is an open source database synchronization solution.
3    *   
4    * Copyright (C) Chris Henson <chenson42@users.sourceforge.net>,
5    *               Eric Long <erilong@users.sourceforge.net>,
6    *               Keith Naas <knaas@users.sourceforge.net>
7    *               
8    *
9    * This library is free software; you can redistribute it and/or
10   * modify it under the terms of the GNU Lesser General Public
11   * License as published by the Free Software Foundation; either
12   * version 3 of the License, or (at your option) any later version.
13   *
14   * This library is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this library; if not, see
21   * <http://www.gnu.org/licenses/>.
22   */
23  
24  package org.jumpmind.symmetric.web;
25  
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.http.HttpServletResponse;
28  
29  import org.apache.commons.lang.StringUtils;
30  import org.apache.commons.logging.Log;
31  import org.apache.commons.logging.LogFactory;
32  import org.jumpmind.symmetric.transport.handler.BatchResourceHandler;
33  
34  /***
35   * Allows for the request of a batch by id.
36   */
37  public class BatchServlet extends AbstractTransportResourceServlet<BatchResourceHandler> {
38  
39      private static final Log logger = LogFactory.getLog(BatchServlet.class);
40  
41      private static final long serialVersionUID = 1L;
42  
43      @Override
44      public boolean isContainerCompatible() {
45          return true;
46      }
47  
48      @Override
49      public void handleGet(HttpServletRequest req, HttpServletResponse resp) throws Exception {
50          handlePost(req, resp);
51      }
52  
53      @Override
54      protected void handlePost(HttpServletRequest req, HttpServletResponse resp) throws Exception {
55          resp.setContentType("text/plain");
56          String path = req.getPathInfo();
57          if (!StringUtils.isBlank(path)) {
58              int batchIdStartIndex = path.lastIndexOf("/")+1;
59              String batchId = path.substring(batchIdStartIndex);
60              if (!getTransportResourceHandler().write(batchId, resp.getOutputStream())) {
61                  resp.sendError(HttpServletResponse.SC_NOT_FOUND);
62              }
63          } else {
64              resp.sendError(HttpServletResponse.SC_NOT_FOUND);
65          }
66      }
67  
68      @Override
69      protected Log getLogger() {
70          return logger;
71      }
72  
73  }