1 22 package org.jboss.test.webservice.jbws84; 23 24 import com.ibm.wsdl.util.xml.DOM2Writer; 25 import org.jboss.logging.Logger; 26 import org.w3c.dom.Document ; 27 28 import javax.xml.parsers.DocumentBuilder ; 29 import javax.xml.parsers.DocumentBuilderFactory ; 30 import javax.xml.parsers.ParserConfigurationException ; 31 import javax.xml.soap.MessageFactory ; 32 import javax.xml.soap.Name ; 33 import javax.xml.soap.SOAPBody ; 34 import javax.xml.soap.SOAPElement ; 35 import javax.xml.soap.SOAPFactory ; 36 import javax.xml.soap.SOAPMessage ; 37 import java.io.ByteArrayInputStream ; 38 import java.io.StringWriter ; 39 import java.rmi.RemoteException ; 40 41 45 public class MessageJavaBean implements Message 46 { 47 private final Logger log = Logger.getLogger(MessageJavaBean.class); 49 50 52 public SOAPElement processSOAPElement(SOAPElement reqElement) throws RemoteException 53 { 54 StringWriter swr = new StringWriter (); 55 DOM2Writer.serializeAsXML(reqElement, swr); 56 log.info("processSOAPElement: " + swr); 57 58 try 59 { 60 SOAPFactory soapFactory = SOAPFactory.newInstance(); 61 62 Name name = soapFactory.createName("Order", PREFIX, NAMESPACE_URI); 63 Name elementName = reqElement.getElementName(); 64 if (name.equals(elementName) == false) 65 throw new IllegalArgumentException ("Unexpected element: " + elementName); 66 67 name = soapFactory.createName("Customer"); 68 SOAPElement custElement = (SOAPElement )reqElement.getChildElements(name).next(); 69 String elementValue = custElement.getValue(); 70 if ("Customer".equals(custElement.getLocalName()) && "Kermit".equals(elementValue) == false) 71 throw new IllegalArgumentException ("Unexpected element value: " + elementValue); 72 73 name = soapFactory.createName("Item"); 74 SOAPElement itemElement = (SOAPElement )reqElement.getChildElements(name).next(); 75 elementValue = itemElement.getValue(); 76 if ("Item".equals(itemElement.getLocalName()) && "Ferrari".equals(elementValue) == false) 77 throw new IllegalArgumentException ("Unexpected element value: " + elementValue); 78 79 MessageFactory msgFactory = MessageFactory.newInstance(); 80 SOAPMessage resMessage = msgFactory.createMessage(); 81 SOAPBody soapBody = resMessage.getSOAPBody(); 82 83 DocumentBuilder builder = getDocumentBuilder(); 84 Document doc = builder.parse(new ByteArrayInputStream (Message.response.getBytes())); 85 soapBody.addDocument(doc); 86 87 SOAPElement resElement = (SOAPElement )soapBody.getChildElements().next(); 88 return resElement; 89 } 90 catch (RuntimeException e) 91 { 92 throw e; 93 } 94 catch (Exception e) 95 { 96 throw new RemoteException (e.toString(), e); 97 } 98 } 99 100 private DocumentBuilder getDocumentBuilder() throws ParserConfigurationException 101 { 102 DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); 104 docBuilderFactory.setNamespaceAware(true); 105 106 DocumentBuilder builder = docBuilderFactory.newDocumentBuilder(); 107 return builder; 108 } 109 } 110 | Popular Tags |