Bug 5528 - Impl Post data
[netconf.git] / restconf / sal-rest-connector / src / main / java / org / opendaylight / restconf / restful / utils / ResponseFactory.java
index a8545568f0983175c290c866773eea685ab56d51..d3f9a68453df4d522b1765b87b7e51a9a53684fb 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.restconf.restful.utils;
 
+import java.net.URI;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
 import javax.ws.rs.core.Response.Status;
 import org.apache.commons.lang3.builder.Builder;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -15,14 +17,25 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 final class ResponseFactory extends FutureDataFactory<Void> implements Builder<Response> {
 
     private final NormalizedNode<?, ?> readData;
+    private final URI location;
 
     ResponseFactory(final NormalizedNode<?, ?> readData) {
         this.readData = readData;
+        this.location = null;
+    }
+
+    ResponseFactory(final NormalizedNode<?, ?> readData, final URI location) {
+        this.readData = readData;
+        this.location = location;
     }
 
     @Override
     public Response build() {
         final Status status = this.readData != null ? Status.OK : Status.CREATED;
-        return Response.status(status).build();
+        final ResponseBuilder responseBuilder = Response.status(status);
+        if (this.location != null) {
+            responseBuilder.location(this.location);
+        }
+        return responseBuilder.build();
     }
 }