1 /* $Id: SOAPServlet.java,v 1.5 2004/09/07 18:48:03 pelle Exp $
2 * $Log: SOAPServlet.java,v $
3 * Revision 1.5 2004/09/07 18:48:03 pelle
4 * Added support for dom4j 1.5 and added a new XPP3Reader
5 *
6 * Revision 1.4 2003/12/08 22:05:01 pelle
7 * Some further documentation. Added the start of a busy developers guide form neuclear-id
8 *
9 * Revision 1.3 2003/11/24 23:33:15 pelle
10 * More Cactus unit testing going on.
11 *
12 * Revision 1.2 2003/11/21 04:44:30 pelle
13 * EncryptedFileStore now works. It uses the PBECipher with DES3 afair.
14 * Otherwise You will Finaliate.
15 * 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.
16 * This should hopefully make everything more stable (and secure).
17 *
18 * Revision 1.1.1.1 2003/11/11 16:33:22 pelle
19 * Moved over from neudist.org
20 * Moved remaining common utilities into commons
21 *
22 * Revision 1.3 2003/11/09 03:27:09 pelle
23 * More house keeping and shuffling about mainly pay
24 *
25 * Revision 1.2 2003/09/26 23:52:47 pelle
26 * Changes mainly in receiver and related fun.
27 * First real neuclear stuff in the payment package. Added TransferContract and AssetControllerReceiver.
28 *
29 * Revision 1.1 2003/01/18 18:12:31 pelle
30 * First Independent commit of the Independent XML-Signature API for NeuDist.
31 *
32 * Revision 1.8 2002/12/17 21:41:02 pelle
33 * First part of refactoring of SignedNamedObject and SignedObject Interface/Class parings.
34 *
35 * Revision 1.7 2002/12/17 20:34:44 pelle
36 * Lots of changes to core functionality.
37 * First of all I've refactored most of the Resolving and verification code. I have a few more things to do
38 * on it before I'm happy.
39 * There is now a NSResolver class, which handles all the namespace resolution. I took most of the functionality
40 * for this out of SignedNamedObject.
41 * Then there is the veriifer, which verifies a given SignedNamedObject using the NSResolver.
42 * This has simplified the SignedNamedObject classes drastically, leaving them as mainly data objects, which is what they
43 * should be.
44 * I have also gone around and tightened up security on many different classes, making clases and/or methods final where appropriate.
45 * NSCache now operates using http://www.waterken.com's fantastic ADT collections library.
46 * Something important has been added, which is a SignRequest named object. This signed object, embeds an unsigned
47 * named object for signing by an end users' signing service.
48 * Now were almost ready to start seriously implementing AssetIssuers and Transfers, which will be the most important
49 * part of the framework.
50 *
51 * Revision 1.6 2002/10/03 01:51:58 pelle
52 * Bunch of smaller fixes for bugs found during deployment.
53 * Also a bit more documentation.
54 * I'm happy with this being called rev. 0.4
55 *
56 * Revision 1.5 2002/10/02 21:03:45 pelle
57 * Major Commit
58 * I completely redid the namespace resolving code.
59 * It now works correctly with the new store attribute of the namespace
60 * And can correctly work out the location of a namespace file
61 * by hierarchically signing it.
62 * I have also included several top level namespaces and finalised
63 * the root namespace.
64 * In short all of the above means that we can theoretically call
65 * Neubia live now. (Well on my first deployment anyway).
66 * There is a new CommandLineSigner utility class which creates and signs
67 * namespaces using standard java keystores.
68 * I'm now working on updating the documentation, so other people
69 * than me might have a chance at using it.
70 *
71 * Revision 1.4 2002/09/21 23:11:16 pelle
72 * A bunch of clean ups. Got rid of as many hard coded URL's as I could.
73 *
74 */
75 package org.neuclear.xml.soap;
76
77 /***
78 * @author pelleb
79 * @version $Revision: 1.5 $
80 */
81
82 import org.dom4j.Document;
83 import org.dom4j.DocumentException;
84 import org.dom4j.DocumentHelper;
85 import org.dom4j.Element;
86 import org.dom4j.io.OutputFormat;
87 import org.dom4j.io.XMLWriter;
88 import org.dom4j.io.XPP3Reader;
89 import org.xmlpull.v1.XmlPullParserException;
90
91 import javax.servlet.http.HttpServletRequest;
92 import javax.servlet.http.HttpServletResponse;
93 import java.io.IOException;
94 import java.io.InputStream;
95 import java.io.OutputStream;
96
97 public abstract class SOAPServlet extends XMLInputStreamServlet {
98
99
100 protected abstract Element handleSOAPRequest(Element request, String soapAction) throws SOAPException;
101
102 protected final void handleInputStream(final InputStream is, final HttpServletRequest request, final HttpServletResponse response) throws IOException {
103 try {
104 final XPP3Reader xpp = new XPP3Reader();
105 final Document doc = xpp.read(is);
106
107 final Element bodyElement = doc.getRootElement().element(SOAPTools.createEnvelopeQName());
108 //TODO: Check for null
109 final Element requestElement = (Element) bodyElement.elements().get(0);
110 if (requestElement == null) {
111 response.sendError(500, "NEUDIST: SOAP Request was invalid");
112 }
113 Element respElement = null;
114 try {
115 respElement = handleSOAPRequest(requestElement, request.getHeader("SOAPAction"));
116 } catch (SOAPException e) {
117 respElement = DocumentHelper.createElement("Exception");
118 respElement.addElement("Message").addText(e.getMessage());
119 }
120 if (respElement == null)
121 respElement = DocumentHelper.createElement("Response").addText("OK");
122 if (respElement.getDocument() == null)
123 DocumentHelper.createDocument(respElement);
124 response.setContentType("text/xml");
125 final OutputStream out = response.getOutputStream();
126
127
128 final XMLWriter writer = new XMLWriter(out, OutputFormat.createCompactFormat());
129 writer.write(respElement);
130 out.close();
131 } catch (XmlPullParserException e) {
132 e.printStackTrace(System.out);
133 response.sendError(500, e.getMessage());
134 } catch (DocumentException e) {
135 e.printStackTrace(System.out);
136 response.sendError(500, e.getMessage());
137 }
138 }
139 }
This page was automatically generated by Maven