Hi,
I have a problem with deserialization.I created a sample service which takes a java bean and returns "OK".
It works fine with serializing and deserializing.
Now i placed a client side handler and server side handler to process the message.
Client Handler:encryt the envelope into encrypt.xml and set that as new envelope.
ServerHandler:decrypt the envelope in to decrypt.xml and set it as new envelope.
But when i use the handlers ,I get deserialzation error.
There seems to be a problem in the order iam ser and deser it.
why is the server not deserializing my bean which is set in deploy.wsdd?It works fine until end of server handler.
I posted in apache axis user forum already without much help.
I have tried a lot and posting this with a lot of hope for help.I am stuck with this from 15 days ,believe me
Iam sending client handler and server handler as attachments.
Please please please suggest me the fix.
thank you.
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now
import org.apache.axis.AxisFault; import org.apache.axis.Handler; import org.apache.axis.Message; import org.apache.axis.MessageContext; import org.apache.axis.handlers.BasicHandler; import org.apache.axis.message.SOAPEnvelope; import javax.xml.soap.SOAPHeader; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory;
import org.apache.axis.Constants; import org.apache.axis.client.AxisClient; import org.apache.axis.configuration.NullProvider; import org.apache.axis.encoding.DeserializationContext; import org.apache.axis.encoding.DeserializationContextImpl; import org.apache.axis.encoding.SerializationContext; import org.apache.axis.encoding.SerializationContextImpl; import org.apache.axis.message.SOAPHeaderElement; import org.apache.axis.utils.JavaUtils; import org.apache.axis.utils.Mapping; import org.apache.axis.utils.XMLUtils; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.InputSource; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import java.io.*; public class ClientRepHandler extends BasicHandler { static Log log = LogFactory.getLog(ClientRepHandler.class.getName()); private Document getSOAPEnvelopeAsDocument(SOAPEnvelope env, MessageContext msgContext) throws Exception { StringWriter writer = new StringWriter(); SerializationContext serializeContext = new SerializationContextImpl(writer, msgContext); env.output(serializeContext); writer.close(); Reader reader = new StringReader(writer.getBuffer().toString()); Document doc = XMLUtils.newDocument(new InputSource(reader)); if (doc == null) throw new Exception( //JavaUtils.getMessage("noDoc00", writer.getBuffer().toString()) ); return doc; } private void output(Document doc,String filename) { DOMSource source = new DOMSource(doc); File newXML = new File(filename); try { FileOutputStream os = new FileOutputStream(newXML); StreamResult result = new StreamResult(os); TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); transformer.transform(source, result); } catch(TransformerConfigurationException tcEx) { tcEx.printStackTrace(); } catch(TransformerException tEx) { tEx.printStackTrace(); }catch(Exception Ex) { Ex.printStackTrace(); } } public void invoke(MessageContext msgContext) throws AxisFault { try { Handler serviceHandler = msgContext.getService(); Message requestMessage = msgContext.getRequestMessage(); SOAPEnvelope PreEnvelope = requestMessage.getSOAPEnvelope(); System.out.println("This is printing in ClientRepHandler"); System.out.println(PreEnvelope); //serializing envelope in to document Document doc = getSOAPEnvelopeAsDocument(PreEnvelope,msgContext); output(doc,"tempXML.xml"); Test2Client tc = new Test2Client(); //encrypting:reading tempXML.xml and writng encrypted message in to encrypted.xml tc.rkmain("tempXML.xml","encrypted.xml"); SOAPEnvelope PostEnvelope = new SOAPEnvelope( new FileInputStream("encrypted.xml")); requestMessage = new Message(PostEnvelope); msgContext.setCurrentMessage(requestMessage); System.out.println(PostEnvelope); } catch (Exception e) { throw AxisFault.makeFault(e); } } public void undo(MessageContext msgContext) { try { // probably needs to fault. } catch (Exception e) { log.error(e); } } }
import org.apache.axis.AxisFault; import org.apache.axis.Handler; import org.apache.axis.Message; import org.apache.axis.MessageContext; import org.apache.axis.handlers.BasicHandler; import org.apache.axis.message.SOAPEnvelope; import javax.xml.soap.SOAPHeader; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.axis.Constants; import org.apache.axis.client.AxisClient; import org.apache.axis.configuration.NullProvider; import org.apache.axis.encoding.DeserializationContext; import org.apache.axis.encoding.DeserializationContextImpl; import org.apache.axis.encoding.SerializationContext; import org.apache.axis.encoding.SerializationContextImpl; import org.apache.axis.message.SOAPHeaderElement; import org.apache.axis.utils.JavaUtils; import org.apache.axis.utils.Mapping; import org.apache.axis.utils.XMLUtils; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.InputSource; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import java.io.*; public class ServerHandler extends BasicHandler { static Log log = LogFactory.getLog(ClientRepHandler.class.getName()); private Document getSOAPEnvelopeAsDocument(SOAPEnvelope env, MessageContext msgContext) throws Exception { StringWriter writer = new StringWriter(); SerializationContext serializeContext = new SerializationContextImpl(writer, msgContext); env.output(serializeContext); writer.close(); Reader reader = new StringReader(writer.getBuffer().toString()); Document doc = XMLUtils.newDocument(new InputSource(reader)); if (doc == null) throw new Exception( //JavaUtils.getMessage("noDoc00", writer.getBuffer().toString()) ); return doc; } private void output(Document doc,String filename) { DOMSource source = new DOMSource(doc); File newXML = new File(filename); try { FileOutputStream os = new FileOutputStream(newXML); StreamResult result = new StreamResult(os); TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); transformer.transform(source, result); } catch(TransformerConfigurationException tcEx) { tcEx.printStackTrace(); } catch(TransformerException tEx) { tEx.printStackTrace(); }catch(Exception Ex) { Ex.printStackTrace(); } } public void invoke(MessageContext msgContext) throws AxisFault { try { Handler serviceHandler = msgContext.getService(); Message requestMessage = msgContext.getRequestMessage(); SOAPEnvelope PreEnvelope = requestMessage.getSOAPEnvelope(); System.out.println("This is printing in ServerSwapHandler"); //serializaing envelope in to document Document doc = getSOAPEnvelopeAsDocument(PreEnvelope,msgContext); output(doc,"encrypted.xml"); Test2Server ts = new Test2Server(); ts.rkmain("encrypted.xml","decrypted.xml"); //deserializing xml into msgcontext Reader reader = new FileReader("decrypted.xml"); DeserializationContext dser = new DeserializationContextImpl( new InputSource(reader), msgContext, org.apache.axis.Message.REQUEST); dser.parse(); Message newMessage = msgContext.getRequestMessage(); SOAPEnvelope newEnvelope = newMessage.getSOAPEnvelope(); System.out.println(newEnvelope); System.out.println("end of handler"); } catch (Exception e) { throw AxisFault.makeFault(e); } } public void undo(MessageContext msgContext) { try { // probably needs to fault. } catch (Exception e) { log.error(e); } } }