View Javadoc
1 /* $Id: SOAPTools.java,v 1.9 2004/04/30 15:13:23 pelle Exp $ 2 * $Log: SOAPTools.java,v $ 3 * Revision 1.9 2004/04/30 15:13:23 pelle 4 * Added RESTTools for creating normal POST requests as handled by XMLInputStreamServlet 5 * Fixed bug in SignatureRequestServlet with regards to autosubmition to Mozilla based browsers such as FireFox. 6 * 7 * Revision 1.8 2004/02/19 19:37:33 pelle 8 * At times IntelliJ IDEA can cause some real hassle. On my last checkin it optimized away all of the dom4j and command line imports. 9 * We'll now, Ive added them all back. 10 * 11 * Revision 1.7 2004/02/19 15:30:08 pelle 12 * Various cleanups and corrections 13 * 14 * Revision 1.6 2003/12/12 12:32:49 pelle 15 * Working on getting the SOAPServletTest working under cactus 16 * 17 * Revision 1.5 2003/12/10 23:57:05 pelle 18 * Did some cleaning up in the builders 19 * Fixed some stuff in IdentityCreator 20 * New maven goal to create executable jarapp 21 * We are close to 0.8 final of ID, 0.11 final of XMLSIG and 0.5 of commons. 22 * Will release shortly. 23 * 24 * Revision 1.4 2003/11/24 23:33:15 pelle 25 * More Cactus unit testing going on. 26 * 27 * Revision 1.3 2003/11/21 04:44:30 pelle 28 * EncryptedFileStore now works. It uses the PBECipher with DES3 afair. 29 * Otherwise You will Finaliate. 30 * 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. 31 * This should hopefully make everything more stable (and secure). 32 * 33 * Revision 1.2 2003/11/19 23:33:16 pelle 34 * Signers now can generatekeys via the generateKey() method. 35 * Refactored the relationship between SignedNamedObject and NamedObjectBuilder a bit. 36 * SignedNamedObject now contains the full xml which is returned with getEncoded() 37 * This means that it is now possible to further receive on or process a SignedNamedObject, leaving 38 * NamedObjectBuilder for its original purposes of purely generating new Contracts. 39 * NamedObjectBuilder.sign() now returns a SignedNamedObject which is the prefered way of processing it. 40 * Updated all major interfaces that used the old model to use the new model. 41 * 42 * Revision 1.1.1.1 2003/11/11 16:33:23 pelle 43 * Moved over from neudist.org 44 * Moved remaining common utilities into commons 45 * 46 * Revision 1.9 2003/11/10 17:42:18 pelle 47 * The AssetController interface has been more or less finalized. 48 * CurrencyController fully implemented 49 * AssetControlClient implementes a remote client for communicating with AssetControllers 50 * 51 * Revision 1.8 2003/11/09 03:27:09 pelle 52 * More house keeping and shuffling about mainly pay 53 * 54 * Revision 1.7 2003/11/08 22:21:08 pelle 55 * Fixed a few things with regards to the SOAPTools class. 56 * 57 * Revision 1.6 2003/11/08 01:40:20 pelle 58 * WARNING this rev is majorly unstable and will almost certainly not compile. 59 * More major refactoring in neuclear-pay. 60 * Got rid of neuclear-ledger like features of pay such as Account and Issuer. 61 * Accounts have been replaced by Identity from neuclear-id 62 * Issuer is now Asset which is a subclass of Identity 63 * AssetController supports more than one Asset. Which is important for most non ecurrency implementations. 64 * TransferRequest/Receipt and its Held companions are now SignedNamedObjects. Thus to create them you must use 65 * their matching TransferRequest/ReceiptBuilder classes. 66 * PaymentProcessor has been renamed CurrencyController. I will extract a superclass later to be named AbstractLedgerController 67 * which will handle all neuclear-ledger based AssetControllers. 68 * 69 * Revision 1.5 2003/11/06 23:48:27 pelle 70 * Major Refactoring of CurrencyController. 71 * Factored out AssetController to be new abstract parent class together with most of its support classes. 72 * Created (Half way) AssetControlClient, which can perform transactions on external AssetControllers via NeuClear. 73 * Created the first attempt at the ExchangeAgent. This will need use of the AssetControlClient. 74 * SOAPTools was changed to return a stream. This is required by the VerifyingReader in NeuClear. 75 * 76 * Revision 1.4 2003/10/21 22:30:33 pelle 77 * Renamed NeudistException to NeuClearException and moved it to org.neuclear.commons where it makes more sense. 78 * Unhooked the XMLException in the xmlsig library from NeuClearException to make all of its exceptions an independent hierarchy. 79 * Obviously had to perform many changes throughout the code to support these changes. 80 * 81 * Revision 1.3 2003/09/26 23:52:47 pelle 82 * Changes mainly in receiver and related fun. 83 * First real neuclear stuff in the payment package. Added TransferContract and AssetControllerReceiver. 84 * 85 * Revision 1.2 2003/02/11 14:47:04 pelle 86 * Added benchmarking code. 87 * DigestValue is now a required part. 88 * If you pass a keypair when you sign, you get the PublicKey included as a KeyInfo block within the signature. 89 * 90 * Revision 1.1 2003/01/18 18:12:31 pelle 91 * First Independent commit of the Independent XML-Signature API for NeuDist. 92 * 93 * Revision 1.6 2003/01/16 19:16:08 pelle 94 * Major Structural Changes. 95 * We've split the test classes out of the normal source tree, to enable Maven's test support to work. 96 * WARNING 97 * for Development purposes the code does not as of this commit until otherwise notified actually verifysigs. 98 * We are reworking the XMLSig library and need to continue work elsewhere for the time being. 99 * DO NOT USE THIS FOR REAL APPS 100 * 101 * Revision 1.5 2002/12/17 21:41:03 pelle 102 * First part of refactoring of SignedNamedObject and SignedObject Interface/Class parings. 103 * 104 * Revision 1.4 2002/12/17 20:34:44 pelle 105 * Lots of changes to core functionality. 106 * First of all I've refactored most of the Resolving and verification code. I have a few more things to do 107 * on it before I'm happy. 108 * There is now a NSResolver class, which handles all the namespace resolution. I took most of the functionality 109 * for this out of SignedNamedObject. 110 * Then there is the veriifer, which verifies a given SignedNamedObject using the NSResolver. 111 * This has simplified the SignedNamedObject classes drastically, leaving them as mainly data objects, which is what they 112 * should be. 113 * I have also gone around and tightened up security on many different classes, making clases and/or methods final where appropriate. 114 * NSCache now operates using http://www.waterken.com's fantastic ADT collections library. 115 * Something important has been added, which is a SignRequest named object. This signed object, embeds an unsigned 116 * named object for signing by an end users' signing service. 117 * Now were almost ready to start seriously implementing AssetIssuers and Transfers, which will be the most important 118 * part of the framework. 119 * 120 * Revision 1.3 2002/09/21 23:11:16 pelle 121 * A bunch of clean ups. Got rid of as many hard coded URL's as I could. 122 * 123 */ 124 package org.neuclear.xml.soap; 125 126 /*** 127 * @author pelleb 128 * @version $Revision: 1.9 $ 129 */ 130 131 import org.dom4j.*; 132 import org.dom4j.io.SAXReader; 133 import org.neuclear.commons.NeuClearException; 134 135 import java.io.*; 136 import java.net.HttpURLConnection; 137 import java.net.MalformedURLException; 138 import java.net.URL; 139 import java.net.URLConnection; 140 141 public final class SOAPTools { 142 private SOAPTools() { 143 } 144 145 146 public static Element soapRequestElement(final String endpoint, final Element request, final String soapAction) throws NeuClearException { 147 try { 148 return soapRequestElement(new URL(endpoint), request, soapAction); 149 } catch (MalformedURLException e) { 150 throw new NeuClearException(e); 151 } 152 } 153 154 public static InputStream soapRequest(final String endpoint, final String request, final String soapAction) throws NeuClearException { 155 try { 156 return soapRequest(new URL(endpoint), request, soapAction); 157 } catch (MalformedURLException e) { 158 throw new NeuClearException(e); 159 } 160 } 161 162 public static Element soapRequestElement(final URL endpoint, final Element request, final String soapAction) throws NeuClearException { 163 try { 164 return soapRequestElement(endpoint.openConnection(), request, soapAction); 165 } catch (IOException e) { 166 throw new NeuClearException(e); 167 } 168 169 } 170 171 public static InputStream soapRequest(final URL endpoint, final String request, final String soapAction) throws NeuClearException { 172 try { 173 return soapRequest(endpoint.openConnection(), request, soapAction); 174 } catch (IOException e) { 175 throw new NeuClearException(e); 176 } 177 } 178 179 public static InputStream soapRequest(final URLConnection conn, final Element request, final String soapAction) throws NeuClearException { 180 return soapRequest(conn, request.asXML(), soapAction); 181 } 182 183 public static InputStream soapRequest(final URLConnection conn, final String request, final String soapAction) throws NeuClearException { 184 try { 185 //Set Headers 186 conn.setDoOutput(true); 187 conn.setDoInput(true); 188 if (conn instanceof HttpURLConnection) { 189 ((HttpURLConnection) conn).setRequestMethod("POST"); 190 ((HttpURLConnection) conn).setRequestProperty("Content-type", "text/xml"); 191 ((HttpURLConnection) conn).setRequestProperty("SOAPAction", soapAction); 192 } 193 final OutputStream out = conn.getOutputStream(); 194 createSoapRequestString(out, request); 195 out.close(); 196 197 return conn.getInputStream(); 198 } catch (IOException e) { 199 throw new NeuClearException(e); 200 } 201 } 202 203 public static void createSoapRequestString(final OutputStream out, final String request) throws IOException { 204 out.write(SOAP_START); 205 out.write(request.getBytes()); 206 out.write(SOAP_END); 207 } 208 209 public static Element soapRequestElement(final URLConnection conn, final Element request, final String soapAction) throws NeuClearException, IOException { 210 try { 211 final BufferedReader in = new BufferedReader(new InputStreamReader(soapRequest(conn, request, soapAction))); 212 final SAXReader reader = new SAXReader(); 213 final Document document = reader.read(in); 214 in.close(); 215 final Element envelope = document.getRootElement(); 216 if (envelope.getName().equals("Envelope")) { 217 final Element body = (Element) envelope.elements().get(0); 218 if (body != null) { 219 return (Element) body.elements().get(0); 220 } 221 222 } 223 return null; 224 } catch (DocumentException e) { 225 throw new NeuClearException(e); 226 } 227 } 228 229 static QName createEnvelopeQName() { 230 return DocumentHelper.createQName("Body", DocumentHelper.createNamespace("SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/")); 231 } 232 233 static final byte SOAP_START[] = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body>\n".getBytes(); 234 static final byte SOAP_END[] = "</SOAP-ENV:Body></SOAP-ENV:Envelope>".getBytes(); 235 }

This page was automatically generated by Maven