View Javadoc

1   /*
2      Licensed under the Apache License, Version 2.0 (the "License");
3      you may not use this file except in compliance with the License.
4      You may obtain a copy of the License at
5   
6        http://www.apache.org/licenses/LICENSE-2.0
7   
8      Unless required by applicable law or agreed to in writing, software
9      distributed under the License is distributed on an "AS IS" BASIS,
10     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11     See the License for the specific language governing permissions and
12     limitations under the License.
13  */
14  package uk.nhs.interoperability.client.samples.cda;
15  
16  import java.io.IOException;
17  
18  import javax.servlet.ServletException;
19  import javax.servlet.http.HttpServlet;
20  import javax.servlet.http.HttpServletRequest;
21  import javax.servlet.http.HttpServletResponse;
22  import javax.servlet.http.HttpSession;
23  
24  import uk.nhs.interoperability.transform.TransformManager;
25  import uk.nhs.interoperability.util.Logger;
26  
27  /**
28   * The Class CDAView.
29   *
30   * @author Michael Odling-Smee
31   * @author Nicholas Jones
32   * @since 0.1
33   */
34  public class CDAView extends HttpServlet {
35  	
36  	/** The Constant serialVersionUID. */
37  	private static final long serialVersionUID = 1L;
38         
39      /**
40       * Instantiates a new cDA view.
41       *
42       * @see HttpServlet#HttpServlet()
43       */
44      public CDAView() {
45          super();
46          // TODO Auto-generated constructor stub
47      }
48  
49  	/**
50  	 * Do get.
51  	 *
52  	 * @param request the request
53  	 * @param response the response
54  	 * @throws ServletException the servlet exception
55  	 * @throws IOException Signals that an I/O exception has occurred.
56  	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
57  	 */
58  	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
59  
60  		String docId    = request.getParameter("docid");
61  		Logger.trace("Document ID:"+docId);
62  		HttpSession session = request.getSession(true);
63          session.removeAttribute("errorMessage");
64          session.removeAttribute("outcomeMessage");
65          session.removeAttribute("responseMessage");
66  
67  		String document = DocStore.getDocument(docId);
68  
69  		if (null!=document){
70  			String htmlResponse = "";
71  			try {
72  				htmlResponse = TransformManager.doTransform("CDA_NPfIT_Document_Renderer.xsl", document);
73  				session.setAttribute("outcomeMessage", "CDA Message Sent.");
74  				session.setAttribute("responseMessage", htmlResponse);
75  			} catch (Exception e) {
76  				Logger.error("Document Transform failed:",e);
77  				session.setAttribute("errorMessage", "Document Transform Failed.");
78  			}
79  			Logger.trace(htmlResponse);
80  		} else {
81  			Logger.trace("Document not found");
82  			session.setAttribute("errorMessage", "Document Not Found.");
83  		}
84  		response.sendRedirect("./CDAView.jsp");
85  	}
86  
87  	/**
88  	 * Do post.
89  	 *
90  	 * @param request the request
91  	 * @param response the response
92  	 * @throws ServletException the servlet exception
93  	 * @throws IOException Signals that an I/O exception has occurred.
94  	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
95  	 */
96  	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
97  		// TODO Auto-generated method stub
98  		System.out.println("this is doPost");
99  		String docId= request.getParameter("docid");
100 		response.getWriter().write("DO POST. DOCID:"+docId);
101 	}
102 
103 }