Instantiating a transformerfactory is costly, so cache and reuse it.
Change-Id: I43561ef36cdd10ef077b77c71673840d4dc83fbd
Signed-off-by: Robert Varga <rovarga@cisco.com>
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 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;
import com.google.common.base.Charsets;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
public class RestconfDocumentedExceptionMapper implements ExceptionMapper<RestconfDocumentedException> {
private final static Logger LOG = LoggerFactory.getLogger(RestconfDocumentedExceptionMapper.class);
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;
@Context
private HttpHeaders headers;
private Transformer createTransformer() throws TransformerFactoryConfigurationError,
TransformerConfigurationException {
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");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");