1 package org.neuclear.xml.soap;
2
3 import org.neuclear.commons.NeuClearException;
4 import org.neuclear.commons.Utility;
5 import org.neuclear.commons.crypto.Base64;
6 import org.neuclear.xml.XMLException;
7
8 import javax.servlet.ServletConfig;
9 import javax.servlet.ServletContext;
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.ByteArrayInputStream;
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.io.PrintWriter;
18
19 /*
20 NeuClear Distributed Transaction Clearing Platform
21 (C) 2003 Pelle Braendgaard
22
23 This library is free software; you can redistribute it and/or
24 modify it under the terms of the GNU Lesser General Public
25 License as published by the Free Software Foundation; either
26 version 2.1 of the License, or (at your option) any later version.
27
28 This library is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31 Lesser General Public License for more details.
32
33 You should have received a copy of the GNU Lesser General Public
34 License along with this library; if not, write to the Free Software
35 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36
37 $Id: XMLInputStreamServlet.java,v 1.7 2004/05/25 17:21:47 pelle Exp $
38 $Log: XMLInputStreamServlet.java,v $
39 Revision 1.7 2004/05/25 17:21:47 pelle
40 Put KeyStorePanel into a JScrollPane
41 Fixed some things in the ReceiverServlet
42
43 Revision 1.6 2004/04/21 23:26:42 pelle
44 Integrated Browser with the asset controller
45 Updated look and feel
46 Added ServletLedgerFactory
47 Added ServletAssetControllerFactory
48 Created issue.jsp file
49 Fixed many smaller issues
50
51 Revision 1.5 2003/12/12 15:12:40 pelle
52 The ReceiverServletTest now passes.
53 Add first stab at a SigningServletTest which currently doesnt pass.
54
55 Revision 1.4 2003/11/28 00:12:36 pelle
56 Getting the NeuClear web transactions working.
57
58 Revision 1.3 2003/11/22 00:23:18 pelle
59 All unit tests in commons, id and xmlsec now work.
60 AssetController now successfully processes payments in the unit test.
61 Payment Web App has working form that creates a TransferRequest presents it to the signer
62 and forwards it to AssetControlServlet. (Which throws an XML Parser Exception) I think the XMLReaderServlet is bust.
63
64 Revision 1.2 2003/11/21 04:44:30 pelle
65 EncryptedFileStore now works. It uses the PBECipher with DES3 afair.
66 Otherwise You will Finaliate.
67 Anything that can be final has been made final throughout everyting. We've used IDEA's Inspector tool to find all instance of variables that could be final.
68 This should hopefully make everything more stable (and secure).
69
70 Revision 1.1.1.1 2003/11/11 16:33:23 pelle
71 Moved over from neudist.org
72 Moved remaining common utilities into commons
73
74 Revision 1.2 2003/11/09 03:27:09 pelle
75 More house keeping and shuffling about mainly pay
76
77 Revision 1.1 2003/09/26 23:52:47 pelle
78 Changes mainly in receiver and related fun.
79 First real neuclear stuff in the payment package. Added TransferContract and AssetControllerReceiver.
80
81 */
82
83 /***
84 * User: pelleb
85 * Date: Sep 25, 2003
86 * Time: 1:07:57 PM
87 */
88 public abstract class XMLInputStreamServlet extends HttpServlet {
89 public void init(ServletConfig servletConfig) throws ServletException {
90 ctx = servletConfig.getServletContext();
91 }
92
93 protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
94 response.setContentType("text/html");
95 final PrintWriter out = response.getWriter();
96 out.println("<html><head><title>SOAP Servlet</title></head><body>");
97 out.println("<h3>");
98 out.println(getClass().getName());
99 out.println(" doesnt support GET</h3>");
100 out.println("</body></html>");
101 out.flush();
102 out.close();
103
104
105 }
106
107 protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
108 try {
109 InputStream is = null;
110
111 if (request.getContentType().equals("text/xml")) {
112 ctx.log("XMLSIG: Got xml encoded neuclear-request");
113 is = request.getInputStream();
114 }
115 if (!Utility.isEmpty(request.getParameter("neuclear-request"))) {
116 ctx.log("XMLSIG: Got form encoded neuclear-request");
117 is = new ByteArrayInputStream(Base64.decode(request.getParameter("neuclear-request")));
118 }
119 if (is != null)
120 handleInputStream(is, request, response);
121 else {
122 PrintWriter writer = response.getWriter();
123 final boolean isXML = request.getContentType().equals("text/xml");
124 if (isXML) {
125 response.setContentType("text/xml");
126 } else {
127 response.setContentType("text/html");
128 writer.print("<html><head><title>XMLInputStreamServlet Error</title></head><body>");
129 }
130 writer.println("<h1>Error: Empty Request</h1><h3>");
131 writer.println("</h3><pre>");
132
133
134 }
135 } catch (Exception e) {
136 PrintWriter writer = response.getWriter();
137 final boolean isXML = request.getContentType().equals("text/xml");
138 if (isXML) {
139 response.setContentType("text/xml");
140 outputXMLError(writer, e);
141 } else {
142 response.setContentType("text/html");
143 }
144 outputHTMLError(writer, e);
145 log("ERROR", e);
146 }
147
148 }
149
150 protected void outputHTMLError(PrintWriter writer, Exception e) {
151 writer.print("<html><head><title>XMLInputStreamServlet Error</title></head><body>");
152 writer.println("<h1>Error</h1><h3>");
153 writer.println(e.getLocalizedMessage());
154 writer.println("</h3><pre style=\"display:none\">");
155 e.printStackTrace(writer);
156 writer.println("</pre>");
157 writer.println("</body></html>");
158
159 }
160
161 protected void outputXMLError(PrintWriter writer, Throwable e) {
162 writer.println("<exception><name>");
163 writer.println(e.getClass().getName());
164 writer.println("</name><description>");
165 writer.println(e.getLocalizedMessage());
166 writer.println("</description>");
167 if (e.getCause() != null)
168 outputXMLError(writer, e.getCause());
169 writer.println("</exception>");
170 }
171
172 protected abstract void handleInputStream(InputStream is, HttpServletRequest request, HttpServletResponse response) throws IOException, NeuClearException, XMLException;
173
174 protected ServletContext ctx;
175
176 }
This page was automatically generated by Maven