From 39417cbd5af4e72bdc6fafc12645a29e883ea8be Mon Sep 17 00:00:00 2001
From: sin <sin@localhost>
Date: Tue, 07 Oct 2008 16:05:15 +0000
Subject: [PATCH] Fix for Issue# 3514: DSMLServer.java is not MT-safe

---
 opends/src/dsml/org/opends/dsml/protocol/DSMLServlet.java |   27 ++++++++++++++++-----------
 1 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/opends/src/dsml/org/opends/dsml/protocol/DSMLServlet.java b/opends/src/dsml/org/opends/dsml/protocol/DSMLServlet.java
index 8483e11..3dd5b66 100644
--- a/opends/src/dsml/org/opends/dsml/protocol/DSMLServlet.java
+++ b/opends/src/dsml/org/opends/dsml/protocol/DSMLServlet.java
@@ -52,6 +52,7 @@
 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;
@@ -97,11 +98,11 @@
   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
@@ -126,17 +127,18 @@
 
       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 ) {
-        SchemaFactory sf = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
-        unmarshaller.setSchema(sf.newSchema(schema));
+      if(schema==null)
+      {
+        URL url = getClass().getResource("/resources/DSMLv2.xsd");
+        if ( url != null ) {
+          SchemaFactory sf = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
+          schema = sf.newSchema(url);
+        }
       }
 
-      marshaller = jaxbContext.createMarshaller();
-
       objFactory = new ObjectFactory();
       messageFactory = MessageFactory.newInstance();
       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
@@ -258,6 +260,8 @@
         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
@@ -317,6 +321,7 @@
       }
     }
     try {
+      Marshaller marshaller = jaxbContext.createMarshaller();
       marshaller.marshal(objFactory.createBatchResponse(batchResponse), doc);
       sendResponse(doc, res);
     } catch (Exception e) {
@@ -539,7 +544,7 @@
     return nextID;
   }
 
-  /**
+    /**
    * This class is used when a xml request is malformed to retrieve the
    * requestID value using an event xml parser.
    */

--
Gitblit v1.10.0