| | |
| | | import javax.xml.parsers.DocumentBuilder; |
| | | import javax.xml.parsers.DocumentBuilderFactory; |
| | | import javax.xml.soap.*; |
| | | import javax.xml.validation.Schema; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.net.URL; |
| | |
| | | private static final String ON_ERROR_RESUME = "resume"; |
| | | private static final String ON_ERROR_EXIT = "exit"; |
| | | |
| | | private Unmarshaller unmarshaller; |
| | | private Marshaller marshaller; |
| | | private static JAXBContext jaxbContext; |
| | | private ObjectFactory objFactory; |
| | | private MessageFactory messageFactory; |
| | | private DocumentBuilder db; |
| | | private static Schema schema; |
| | | |
| | | // this extends the default handler of SAX parser. It helps to retrieve the |
| | | // requestID value when the xml request is malformed and thus unparsable |
| | |
| | | |
| | | port = new Integer(config.getServletContext().getInitParameter(PORT)); |
| | | |
| | | JAXBContext jaxbContext = JAXBContext.newInstance(PKG_NAME); |
| | | unmarshaller = jaxbContext.createUnmarshaller(); |
| | | if(jaxbContext==null) |
| | | jaxbContext = JAXBContext.newInstance(PKG_NAME); |
| | | // assign the DSMLv2 schema for validation |
| | | URL schema = getClass().getResource("/resources/DSMLv2.xsd"); |
| | | if ( schema != null ) { |
| | | if(schema==null) |
| | | { |
| | | URL url = getClass().getResource("/resources/DSMLv2.xsd"); |
| | | if ( url != null ) { |
| | | SchemaFactory sf = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI); |
| | | unmarshaller.setSchema(sf.newSchema(schema)); |
| | | schema = sf.newSchema(url); |
| | | } |
| | | |
| | | marshaller = jaxbContext.createMarshaller(); |
| | | } |
| | | |
| | | objFactory = new ObjectFactory(); |
| | | messageFactory = MessageFactory.newInstance(); |
| | |
| | | SOAPElement se = (SOAPElement) obj; |
| | | JAXBElement<BatchRequest> batchRequestElement = null; |
| | | try { |
| | | Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); |
| | | unmarshaller.setSchema(schema); |
| | | batchRequestElement = unmarshaller.unmarshal(se, BatchRequest.class); |
| | | } catch (JAXBException e) { |
| | | // schema validation failed |
| | |
| | | } |
| | | } |
| | | try { |
| | | Marshaller marshaller = jaxbContext.createMarshaller(); |
| | | marshaller.marshal(objFactory.createBatchResponse(batchResponse), doc); |
| | | sendResponse(doc, res); |
| | | } catch (Exception e) { |