}
} else if (childType.isJsonPrimitive()) {
JsonPrimitive childPrimitive = childType.getAsJsonPrimitive();
- String value = childPrimitive.getAsString();
+ String value = childPrimitive.getAsString().trim();
parent.addValue(new SimpleNodeWrapper(getNamespaceFor(childName), getLocalNameFor(childName),
resolveValueOfElement(value)));
}
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;
.entity( " " ).build();
}
- Status status = errors.iterator().next().getErrorTag().getStatusCode();
+ int status = errors.iterator().next().getErrorTag().getStatusCode();
ControllerContext context = ControllerContext.getInstance();
DataNodeContainer errorsSchemaNode = (DataNodeContainer)context.getRestconfModuleErrorsSchemaNode();
}
}
}
- return data;
+ return data == null ? null : data.trim();
}
private String getAdditionalData(XMLEvent event) throws XMLStreamException {
import java.io.PrintWriter;
import java.io.StringWriter;
-import javax.ws.rs.core.Response.Status;
-
import org.opendaylight.yangtools.yang.common.RpcError;
import com.google.common.base.Preconditions;
}
public static enum ErrorTag {
- IN_USE( "in-use", Status.fromStatusCode(409)),
- INVALID_VALUE( "invalid-value", Status.fromStatusCode(400)),
- TOO_BIG( "too-big", Status.fromStatusCode(413)),
- MISSING_ATTRIBUTE( "missing-attribute", Status.fromStatusCode(400)),
- BAD_ATTRIBUTE( "bad-attribute", Status.fromStatusCode(400)),
- UNKNOWN_ATTRIBUTE( "unknown-attribute", Status.fromStatusCode(400)),
- BAD_ELEMENT( "bad-element", Status.fromStatusCode(400)),
- UNKNOWN_ELEMENT( "unknown-element", Status.fromStatusCode(400)),
- UNKNOWN_NAMESPACE( "unknown-namespace", Status.fromStatusCode(400)),
- ACCESS_DENIED( "access-denied", Status.fromStatusCode(403)),
- LOCK_DENIED( "lock-denied", Status.fromStatusCode(409)),
- RESOURCE_DENIED( "resource-denied", Status.fromStatusCode(409)),
- ROLLBACK_FAILED( "rollback-failed", Status.fromStatusCode(500)),
- DATA_EXISTS( "data-exists", Status.fromStatusCode(409)),
- DATA_MISSING( "data-missing", Status.fromStatusCode(409)),
- OPERATION_NOT_SUPPORTED( "operation-not-supported", Status.fromStatusCode(501)),
- OPERATION_FAILED( "operation-failed", Status.fromStatusCode(500)),
- PARTIAL_OPERATION( "partial-operation", Status.fromStatusCode(500)),
- MALFORMED_MESSAGE( "malformed-message", Status.fromStatusCode(400));
+ IN_USE( "in-use", 409 /*Conflict*/ ),
+ INVALID_VALUE( "invalid-value", 400 /*Bad Request*/ ),
+ TOO_BIG( "too-big", 413 /*Request Entity Too Large*/ ),
+ MISSING_ATTRIBUTE( "missing-attribute", 400 /*Bad Request*/ ),
+ BAD_ATTRIBUTE( "bad-attribute", 400 /*Bad Request*/ ),
+ UNKNOWN_ATTRIBUTE( "unknown-attribute", 400 /*Bad Request*/ ),
+ BAD_ELEMENT( "bad-element", 400 /*Bad Request*/ ),
+ UNKNOWN_ELEMENT( "unknown-element", 400 /*Bad Request*/ ),
+ UNKNOWN_NAMESPACE( "unknown-namespace", 400 /*Bad Request*/ ),
+ ACCESS_DENIED( "access-denied", 403 /*Forbidden*/ ),
+ LOCK_DENIED( "lock-denied", 409 /*Conflict*/ ),
+ RESOURCE_DENIED( "resource-denied", 409 /*Conflict*/ ),
+ ROLLBACK_FAILED( "rollback-failed", 500 /*INTERNAL_SERVER_ERROR*/ ),
+ DATA_EXISTS( "data-exists", 409 /*Conflict*/ ),
+ DATA_MISSING( "data-missing", 409 /*Conflict*/ ),
+ OPERATION_NOT_SUPPORTED( "operation-not-supported", 501 /*Not Implemented*/ ),
+ OPERATION_FAILED( "operation-failed", 500 /*INTERNAL_SERVER_ERROR*/ ),
+ PARTIAL_OPERATION( "partial-operation", 500 /*INTERNAL_SERVER_ERROR*/ ),
+ MALFORMED_MESSAGE( "malformed-message", 400 /*Bad Request*/ );
private final String tagValue;
- private final Status statusCode;
+ private final int statusCode;
- ErrorTag(final String tagValue, final Status statusCode) {
+ ErrorTag(final String tagValue, final int statusCode) {
this.tagValue = tagValue;
this.statusCode = statusCode;
}
}
}
- public Status getStatusCode() {
+ public int getStatusCode() {
return statusCode;
}
}
return rpcDef;
}
+ @Override
+ public RpcResult<CompositeNode> invokeRpc( CompositeNode rpcRequest )
+ throws RestconfDocumentedException {
+ try {
+ return getRpcResult( invokeRpcUnchecked( rpcRequest ) );
+ }
+ catch( IllegalArgumentException e ) {
+ throw new RestconfDocumentedException(
+ e.getMessage(), ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE );
+ }
+ catch( UnsupportedOperationException e ) {
+ throw new RestconfDocumentedException(
+ e.getMessage(), ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED );
+ }
+ catch( Exception e ) {
+ throw new RestconfDocumentedException(
+ "The operation encountered an unexpected error while executing.", e );
+ }
+ }
+
+ protected abstract Future<RpcResult<CompositeNode>> invokeRpcUnchecked( CompositeNode rpcRequest );
+
protected RpcResult<CompositeNode> getRpcResult(
Future<RpcResult<CompositeNode>> fromFuture ) {
try {
*/
package org.opendaylight.controller.sal.restconf.rpc.impl;
+import java.util.concurrent.Future;
+
import org.opendaylight.controller.sal.restconf.impl.BrokerFacade;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
}
@Override
- public RpcResult<CompositeNode> invokeRpc(CompositeNode rpcRequest) {
- return getRpcResult( broker.invokeRpc( getRpcDefinition().getQName(), rpcRequest ) );
+ protected Future<RpcResult<CompositeNode>> invokeRpcUnchecked( CompositeNode rpcRequest ) {
+ return broker.invokeRpc( getRpcDefinition().getQName(), rpcRequest );
}
}
\ No newline at end of file
*/
package org.opendaylight.controller.sal.restconf.rpc.impl;
+import java.util.concurrent.Future;
+
import org.opendaylight.controller.sal.core.api.mount.MountInstance;
-import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
}
@Override
- public RpcResult<CompositeNode> invokeRpc( CompositeNode rpcRequest )
- throws RestconfDocumentedException {
- return getRpcResult( mountPoint.rpc( getRpcDefinition().getQName(), rpcRequest ) );
+ protected Future<RpcResult<CompositeNode>> invokeRpcUnchecked( CompositeNode rpcRequest ) {
+ return mountPoint.rpc( getRpcDefinition().getQName(), rpcRequest );
}
}
\ No newline at end of file
import java.util.HashMap;
import java.util.Map;
-import javax.ws.rs.core.Response.Status;
-
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
@Test
public void testErrorTagStatusCodes()
{
- Map<String,Status> lookUpMap = new HashMap<String,Status>();
-
- lookUpMap.put( "in-use", Status.fromStatusCode(409));
- lookUpMap.put( "invalid-value", Status.fromStatusCode(400));
- lookUpMap.put( "too-big", Status.fromStatusCode(413));
- lookUpMap.put( "missing-attribute", Status.fromStatusCode(400));
- lookUpMap.put( "bad-attribute", Status.fromStatusCode(400));
- lookUpMap.put( "unknown-attribute", Status.fromStatusCode(400));
- lookUpMap.put( "bad-element", Status.fromStatusCode(400));
- lookUpMap.put( "unknown-element", Status.fromStatusCode(400));
- lookUpMap.put( "unknown-namespace", Status.fromStatusCode(400));
- lookUpMap.put( "access-denied", Status.fromStatusCode(403));
- lookUpMap.put( "lock-denied", Status.fromStatusCode(409));
- lookUpMap.put( "resource-denied", Status.fromStatusCode(409));
- lookUpMap.put( "rollback-failed", Status.fromStatusCode(500));
- lookUpMap.put( "data-exists", Status.fromStatusCode(409));
- lookUpMap.put( "data-missing", Status.fromStatusCode(409));
- lookUpMap.put( "operation-not-supported", Status.fromStatusCode(501));
- lookUpMap.put( "operation-failed", Status.fromStatusCode(500));
- lookUpMap.put( "partial-operation", Status.fromStatusCode(500));
- lookUpMap.put( "malformed-message", Status.fromStatusCode(400));
+ Map<String,Integer> lookUpMap = new HashMap<String,Integer>();
+
+ lookUpMap.put( "in-use", 409);
+ lookUpMap.put( "invalid-value", 400);
+ lookUpMap.put( "too-big", 413);
+ lookUpMap.put( "missing-attribute", 400);
+ lookUpMap.put( "bad-attribute", 400);
+ lookUpMap.put( "unknown-attribute", 400);
+ lookUpMap.put( "bad-element", 400);
+ lookUpMap.put( "unknown-element", 400);
+ lookUpMap.put( "unknown-namespace", 400);
+ lookUpMap.put( "access-denied", 403);
+ lookUpMap.put( "lock-denied", 409);
+ lookUpMap.put( "resource-denied", 409);
+ lookUpMap.put( "rollback-failed", 500);
+ lookUpMap.put( "data-exists", 409);
+ lookUpMap.put( "data-missing", 409);
+ lookUpMap.put( "operation-not-supported", 501);
+ lookUpMap.put( "operation-failed", 500);
+ lookUpMap.put( "partial-operation", 500);
+ lookUpMap.put( "malformed-message", 400);
for( ErrorTag tag : ErrorTag.values() )
{
- Status expectedStatusCode = lookUpMap.get( tag.getTagValue() );
+ Integer expectedStatusCode = lookUpMap.get( tag.getTagValue() );
assertNotNull( "Failed to find " + tag.getTagValue(), expectedStatusCode );
- assertEquals( "Status Code does not match", expectedStatusCode, tag.getStatusCode() );
+ assertEquals( "Status Code does not match", expectedStatusCode,
+ Integer.valueOf( tag.getStatusCode() ) );
}
}