1 4 5 package com.sun.j2ee.blueprints.docoriented.client.stringposervice; 6 7 import java.rmi.*; 8 import java.io.*; 9 10 import javax.xml.parsers.*; 11 12 import org.w3c.dom.*; 13 import org.xml.sax.*; 14 15 import com.sun.j2ee.blueprints.docoriented.client.*; 16 17 21 22 public class StringPOServiceBD { 23 24 private ServiceLocator serviceLocator; 25 26 public StringPOServiceBD(){ 27 serviceLocator = new ServiceLocator(); 28 } 29 30 public String submitPO(PurchaseOrder po) throws RequestHandlerException { 31 String ret = null; 32 try { 33 StringPurchaseOrderServiceSEI port = (StringPurchaseOrderServiceSEI) 34 serviceLocator.getServicePort(JNDINames.STRING_SERVICE_REF, StringPurchaseOrderServiceSEI.class); 35 String xmlDoc = po.toXMLString(); 36 if(!(validate(xmlDoc))){ 37 throw new RequestHandlerException("Request Handler Exception: Error parsing the purchase order XML document"); 38 } 39 ret = port.submitPO(xmlDoc); 40 return ret; 41 } catch(InvalidPOException ipoe){ 42 ipoe.printStackTrace(System.err); 43 throw new RequestHandlerException("Request Handler Exception: Service Endpoint Application-Defined Exception "+ipoe.getMessage(), ipoe); 44 } catch(RemoteException re){ 45 re.printStackTrace(System.err); 46 throw new RuntimeException ("The web service you are trying to access is not available. A possible reason could be that the service has not been deployed yet. "+ re.getMessage(), re); 47 } 48 } 49 50 55 private boolean validate(String xmlDoc) { 56 Document doc = null; 57 try { 58 DocumentBuilderFactory dbf = null; 59 DocumentBuilder db = null; 60 try { 61 dbf = DocumentBuilderFactory.newInstance(); 62 dbf.setValidating(true); 63 dbf.setNamespaceAware(true); 64 dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", 65 "http://www.w3.org/2001/XMLSchema"); 66 if (dbf != null){ 67 db = dbf.newDocumentBuilder(); 68 } 69 db.setEntityResolver(new POEntityResolver()); 70 db.setErrorHandler(new POXMLErrorHandler()); 71 } catch (ParserConfigurationException pce) { 72 pce.printStackTrace(System.err); 73 throw new RuntimeException (pce.getMessage(), pce); 74 } 75 InputSource is = new InputSource(new StringReader(xmlDoc)); 76 doc = db.parse(is); 77 return true; 78 } catch (Exception e) { 79 System.err.println("XML Validation Error " + e); 80 } 81 return false; 82 } 83 } | Popular Tags |