View Javadoc

1   /*$Id: BackdoorServlet.java,v 1.5 2005/03/13 07:13:39 clq2 Exp $
2    * Created on 21-Apr-2004
3    *
4    * Copyright (C) AstroGrid. All rights reserved.
5    *
6    * This software is published under the terms of the AstroGrid 
7    * Software License version 1.2, a copy of which has been included 
8    * with this distribution in the LICENSE.txt file.  
9    *
10  **/
11  package org.astrogrid.jes.servlet;
12  
13  import org.astrogrid.jes.JesException;
14  import org.astrogrid.jes.component.JesComponentManager;
15  import org.astrogrid.jes.component.JesComponentManagerFactory;
16  import org.astrogrid.jes.jobscheduler.Locator;
17  import org.astrogrid.workflow.beans.v1.Tool;
18  
19  import java.io.IOException;
20  import java.io.PrintWriter;
21  
22  import javax.servlet.ServletException;
23  import javax.servlet.http.HttpServlet;
24  import javax.servlet.http.HttpServletRequest;
25  import javax.servlet.http.HttpServletResponse;
26  
27  /*** Backdoor into some of the jes componets, for easy server-side testing.
28   * @author Noel Winstanley nw@jb.man.ac.uk 21-Apr-2004
29   *
30   */
31  public class BackdoorServlet extends HttpServlet {
32      /*** Construct a new BackdoorServlet
33       * 
34       */
35      public BackdoorServlet() {
36          super();
37      }
38      /***
39       * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
40       */
41      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
42          String action = request.getParameter("action");
43          if (action.equalsIgnoreCase("locate")) {
44              String toolName = request.getParameter("name");
45              JesComponentManager manager = JesComponentManagerFactory.getInstance();
46              Locator locator = (Locator)manager.getContainer().getComponentInstance(Locator.class);
47              if (locator == null) {
48                  throw new ServletException("locator object was null");
49              }
50              Tool tool = new Tool();
51              tool.setName(toolName);
52              try {
53                  String url = locator.locateTool(tool)[0];
54                  PrintWriter writer = response.getWriter();
55                  writer.println(url);
56              } catch (JesException e) {
57                  throw new ServletException("Jes Barfed with exception",e);
58              }
59          } 
60      }
61  
62  }
63  
64  
65  /* 
66  $Log: BackdoorServlet.java,v $
67  Revision 1.5  2005/03/13 07:13:39  clq2
68  merging jes-nww-686 common-nww-686 workflow-nww-996 scripting-nww-995 cea-nww-994
69  
70  Revision 1.4.92.1  2005/03/11 15:21:35  nw
71  adjusted locator so that it returns a list of endpoints to connect to.
72  we can get round-robin by shuffling the list.
73  dispatcher tries each endpoint in the list until can connect to one wihout throwing an exception.
74  
75  Revision 1.4  2004/08/13 09:07:26  nw
76  tidied imports
77  
78  Revision 1.3  2004/08/03 16:31:25  nw
79  simplified interface to dispatcher and locator components.
80  removed redundant implementations.
81  
82  Revision 1.2  2004/07/09 09:30:28  nw
83  merged in scripting workflow interpreter from branch
84  nww-x-workflow-extensions
85  
86  Revision 1.1  2004/04/21 10:06:21  nw
87  added backdoor servlet
88   
89  */