mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

sin
07.05.2008 39417cbd5af4e72bdc6fafc12645a29e883ea8be
Fix for Issue# 3514: DSMLServer.java is not MT-safe
1 files modified
23 ■■■■■ changed files
opends/src/dsml/org/opends/dsml/protocol/DSMLServlet.java 23 ●●●●● patch | view | raw | blame | history
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,16 +127,17 @@
      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();
@@ -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) {