Cache TransformerFactory 62/13562/2
authorRobert Varga <rovarga@cisco.com>
Thu, 11 Dec 2014 10:11:59 +0000 (11:11 +0100)
committerRobert Varga <nite@hq.sk>
Fri, 12 Dec 2014 12:40:33 +0000 (12:40 +0000)
Instantiating a transformerfactory is costly, so cache and reuse it.

Change-Id: I43561ef36cdd10ef077b77c71673840d4dc83fbd
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/RestconfDocumentedExceptionMapper.java

index 10201ab6f5148c78480b9cceea34b77766f0027e..d564d4cbd40d92ff18bc19fdb6c6c04698a12bcf 100644 (file)
@@ -16,7 +16,6 @@ import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ER
 import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ERROR_TAG_QNAME;
 import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ERROR_TYPE_QNAME;
 import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.NAMESPACE;
-
 import com.google.common.base.Charsets;
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
@@ -69,6 +68,7 @@ import org.xml.sax.InputSource;
 public class RestconfDocumentedExceptionMapper implements ExceptionMapper<RestconfDocumentedException> {
 
     private final static Logger LOG = LoggerFactory.getLogger(RestconfDocumentedExceptionMapper.class);
+    private static final TransformerFactory TRANSFORMER_FACTORY = TransformerFactory.newInstance();
 
     @Context
     private HttpHeaders headers;
@@ -178,8 +178,7 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
 
     private Transformer createTransformer() throws TransformerFactoryConfigurationError,
             TransformerConfigurationException {
-        TransformerFactory tf = TransformerFactory.newInstance();
-        Transformer transformer = tf.newTransformer();
+        Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
         transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
         transformer.setOutputProperty(OutputKeys.METHOD, "xml");
         transformer.setOutputProperty(OutputKeys.INDENT, "yes");