X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frest%2Fimpl%2FRestconfDocumentedExceptionMapper.java;h=0854ca71673465e76e7659bfa9479afc3fb1962f;hb=0e7b83c0739ac579ca6dbf6a3f7992f70eb3000f;hp=456354bbf0eac9c9eab31c0d72800f5f3a6462e6;hpb=26da3c2a206a753356b507b018052cbb9cccca7d;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/RestconfDocumentedExceptionMapper.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/RestconfDocumentedExceptionMapper.java index 456354bbf0..0854ca7167 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/RestconfDocumentedExceptionMapper.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/RestconfDocumentedExceptionMapper.java @@ -8,6 +8,20 @@ package org.opendaylight.controller.sal.rest.impl; +import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ERRORS_CONTAINER_QNAME; +import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ERROR_APP_TAG_QNAME; +import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ERROR_INFO_QNAME; +import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ERROR_LIST_QNAME; +import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ERROR_MESSAGE_QNAME; +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.gson.stream.JsonWriter; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; @@ -21,7 +35,6 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.ext.Provider; import javax.xml.parsers.DocumentBuilderFactory; @@ -34,8 +47,6 @@ import javax.xml.transform.TransformerFactoryConfigurationError; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; -import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.*; - import org.opendaylight.controller.sal.restconf.impl.ControllerContext; import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException; import org.opendaylight.controller.sal.restconf.impl.RestconfError; @@ -51,10 +62,6 @@ import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.xml.sax.InputSource; -import com.google.common.base.Strings; -import com.google.common.collect.ImmutableList; -import com.google.gson.stream.JsonWriter; - /** * This class defines an ExceptionMapper that handles RestconfDocumentedExceptions thrown by * resource implementations and translates appropriately to restconf error response as defined in @@ -71,7 +78,7 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper> errorNodes = ImmutableList.> builder(); @@ -117,7 +124,7 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper toDomNode( RestconfError error ) { + private Node toDomNode( final RestconfError error ) { CompositeNodeBuilder builder = ImmutableCompositeNode.builder(); builder.setQName( ERROR_LIST_QNAME ); @@ -210,7 +216,7 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper parseErrorInfo( String errorInfo ) { + private Node parseErrorInfo( final String errorInfo ) { if( Strings.isNullOrEmpty( errorInfo ) ) { return null; } @@ -227,19 +233,17 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper" ) - .append( errorInfo ).append( "" ).toString(); + .append( errorInfo ).append( "" ).toString(); Document doc = null; try { doc = factory.newDocumentBuilder().parse( - new InputSource( new StringReader( errorInfoWithRoot ) ) ); - } - catch( Exception e ) { + new InputSource( new StringReader( errorInfoWithRoot ) ) ); + } catch( Exception e ) { // TODO: what if the content is text that happens to contain invalid markup? Could // wrap in CDATA and try again. - LOG.warn( "Error parsing restconf error-info, \"" + errorInfo + "\", as XML: " + - e.toString() ); + LOG.warn( "Error parsing restconf error-info, \"{}\", as XML", errorInfo, e); return null; } @@ -264,8 +268,8 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper builder, QName qname, - String value ) { + private void addLeaf( final CompositeNodeBuilder builder, final QName qname, + final String value ) { if( !Strings.isNullOrEmpty( value ) ) { builder.addLeaf( qname, value ); }