1 57 58 61 package org.apache.soap.transport; 62 63 import java.io.*; 64 import java.net.*; 65 import java.util.*; 66 import javax.xml.parsers.*; 67 import org.w3c.dom.*; 68 import org.xml.sax.*; 69 import org.apache.soap.util.net.*; 70 import org.apache.soap.util.xml.*; 71 import org.apache.soap.*; 72 import org.apache.soap.rpc.SOAPContext; 73 import org.apache.soap.encoding.*; 74 import org.apache.soap.transport.*; 75 76 82 public class FilterTransport implements SOAPTransport { 83 private EnvelopeEditor editor; 84 private SOAPTransport transport; 85 86 public FilterTransport(EnvelopeEditor editor, SOAPTransport transport) { 87 this.editor = editor; 88 this.transport = transport; 89 } 90 91 105 public void send(URL sendTo, 106 String action, 107 Hashtable headers, 108 Envelope env, 109 SOAPMappingRegistry 110 smr, 111 SOAPContext ctx) throws SOAPException 112 { 113 try { 114 StringWriter sout = new StringWriter(); 115 env.marshall (sout, smr, ctx); 116 117 StringReader sin = new StringReader(sout.getBuffer().toString()); 118 if (editor != null) { 119 sout = new StringWriter(); 120 editor.editOutgoing(sin, sout); 121 sout.flush(); 122 sin = new StringReader(sout.getBuffer().toString()); 123 } 124 125 DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder(); 126 Element docElem = xdb.parse(new InputSource(sin)).getDocumentElement(); 127 128 Envelope env2 = Envelope.unmarshall(docElem); 129 transport.send(sendTo, action, headers, env2, smr, ctx); 130 } catch (IllegalArgumentException e) { 131 throw new SOAPException (Constants.FAULT_CODE_CLIENT, 132 e.getMessage(), 133 e); 134 } catch (SAXException e) { 135 throw new SOAPException (Constants.FAULT_CODE_CLIENT, 136 e.getMessage(), 137 e); 138 } catch (IOException e) { 139 throw new SOAPException (Constants.FAULT_CODE_CLIENT, 140 e.getMessage(), 141 e); 142 } 143 } 144 145 152 public BufferedReader receive () { 153 try { 154 BufferedReader in = transport.receive(); 155 if (editor == null || in == null) 156 return in; 157 else { 158 StringWriter sout = new StringWriter(); 159 editor.editIncoming(in, sout); 160 sout.flush(); 161 StringReader sin = new StringReader(sout.getBuffer().toString()); 162 return new BufferedReader(sin); 163 } 164 } catch (SOAPException e) { 165 e.printStackTrace(); 166 return null; 168 } 169 } 170 171 176 public Hashtable getHeaders () { 177 return transport.getHeaders(); 178 } 179 180 185 public SOAPContext getResponseSOAPContext () { 186 return transport.getResponseSOAPContext(); 187 } 188 } 189 192 | Popular Tags |