1 37 38 package com.sun.j2ee.blueprints.opc.webservicebroker.provider; 39 40 import java.rmi.*; 41 42 import javax.ejb.*; 43 44 import com.sun.j2ee.blueprints.servicelocator.*; 45 import com.sun.j2ee.blueprints.servicelocator.ejb.*; 46 import com.sun.j2ee.blueprints.opc.JNDINames; 47 import com.sun.j2ee.blueprints.opc.utils.*; 48 import com.sun.j2ee.blueprints.opc.serviceexceptions.*; 49 50 import java.io.*; 51 import org.w3c.dom.*; 52 import org.xml.sax.*; 53 import javax.xml.parsers.*; 54 import javax.xml.transform.*; 55 import javax.xml.transform.dom.*; 56 57 public class BrokerServiceBean implements SessionBean { 58 59 private SessionContext sc; 60 private BrokerTransformer bt = null; 61 62 public BrokerServiceBean(){} 63 64 public void ejbCreate() throws CreateException { 65 bt = new BrokerTransformer(); 66 } 67 68 public String submitDocument(String doc) throws InvalidDocumentException, 69 ProcessingException { 70 72 boolean valid = validate(doc); 73 74 if (!valid) { 75 throw new ProcessingException("BrokerServiceBean: document does not match schema" + doc); 76 } 77 String tDoc = bt.transform(new InputSource(new StringReader(doc))); 79 if (tDoc != null) { 80 doc = tDoc; 81 } 82 86 90 if(delegateToProcessingLayer(JNDINames.WORKFLOW_MGR_MDB_QUEUE, doc) 93 == false) 94 throw new ProcessingException("Irrecoverable error while submitting requestfor processing"); 95 96 return("INV1234"); 98 } 99 100 private boolean delegateToProcessingLayer(String destQueue, String xmlDoc) 101 throws ProcessingException { 102 return(JMSUtils.sendMessage(destQueue, JNDINames.DOC_TYPE, 103 JNDINames.INVOICE_DOCUMENT, xmlDoc)); 104 } 105 106 public void setSessionContext(SessionContext sc) { 107 this.sc = sc; 108 } 109 110 public void ejbRemove() throws RemoteException { 111 bt = null; 112 } 113 114 public void ejbActivate() {} 116 117 public void ejbPassivate() {} 119 120 public boolean validate(String xmlText) { 121 Document doc = null; 122 try { 123 DocumentBuilderFactory dbf = null; 124 DocumentBuilder db = null; 125 try { 126 dbf = DocumentBuilderFactory.newInstance(); 127 dbf.setValidating(true); 128 dbf.setNamespaceAware(true); 129 dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", 130 "http://www.w3.org/2001/XMLSchema"); 131 if (dbf != null){ 132 db = dbf.newDocumentBuilder(); 133 } 134 db.setEntityResolver(new BrokerEntityResolver()); 135 db.setErrorHandler(new BrokerXMLMessageErrorHandler()); 136 } catch ( javax.xml.parsers.ParserConfigurationException pce) { 137 System.err.println(pce); 138 } 139 InputSource is = new InputSource(new StringReader(xmlText)); 140 doc = db.parse(is); 141 return true; 142 } catch (Exception e) { 143 System.err.println("BrokerServiceBean::getDocument error loading XML Document " + e); 144 } 145 return false; 146 } 147 } 148 | Popular Tags |