Add ACLs to java SimpleClientService so example runs when SECURED=1
authorGeorge Nash <george.nash@intel.com>
Fri, 13 Jan 2017 22:53:22 +0000 (14:53 -0800)
committerRick Bell <richard.s.bell@intel.com>
Mon, 30 Jan 2017 19:24:50 +0000 (19:24 +0000)
The ioc_svr_db_server ACL file is a copy of the ACL file from
resource/examples. This currently installs the .dat file from
the simpleserver sample.

Build:
scons BUILD_JAVA=1

Run example:
export LD_LIBRARY_PATH=<iotivity>/out/linux/x86_64/release/

java -cp java/examples-java/simpleclientserver/build/libs/simpleclientserver.jar:\
java/iotivity-linux/build/libs/iotivity-linux.jar \
org.iotivity.base.examples.SimpleClientServer

Change-Id: I02617ad852231a730cdf75f8a0b01c01ee0daeb2
Signed-off-by: George Nash <george.nash@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16399
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Rick Bell <richard.s.bell@intel.com>
java/SConscript
java/examples-java/simpleclientserver/src/main/java/org/iotivity/base/examples/SimpleClientServer.java

index 45d9e5c..5d4427c 100644 (file)
@@ -102,6 +102,7 @@ jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' b
 cmdBuildExamples=jdk_env.Gradle(target="examples-%s/simpleclient/jar" % (examples_target, ), source="examples-%s/simpleclient/src/main/java/org/iotivity/base/examples/SimpleClient.java" % (examples_target, ))
 
 exampleAclFiles = jdk_env.Install('#java/examples-java/simpleserver/build/libs/', 'examples-java/simpleserver/src/main/assets/oic_svr_db_server.dat')
+exampleAclFiles += jdk_env.Install('#java/examples-java/simpleclientserver/build/libs/', 'examples-java/simpleserver/src/main/assets/oic_svr_db_server.dat')
 
 Depends(cmdBuildExamples, exampleAclFiles)
 Depends(cmdBuildExamples, cmdBuildApi)
index e6152dd..8d9a402 100644 (file)
@@ -29,6 +29,7 @@ import org.iotivity.base.PlatformConfig;
 import org.iotivity.base.QualityOfService;
 import org.iotivity.base.ServiceType;
 
+import java.net.URISyntaxException;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -43,9 +44,18 @@ public class SimpleClientServer {
     private static final String TAG = SimpleClientServer.class.getSimpleName();
 
     public static void main(String[] args) {
+        String path = "";
+        // This assumes the oic_svr_db_server.dat file is in the same location as the SimpleServer.jar file
+        try {
+            path = SimpleServer.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
+            path = path.substring(0, path.lastIndexOf('/'));
+        } catch (URISyntaxException e) {
+            msg(TAG, e.getMessage() + " unable to find local file path.");
+        }
 
         PlatformConfig platformConfig = new PlatformConfig(ServiceType.IN_PROC, ModeType.CLIENT_SERVER, "0.0.0.0", 0,
-                QualityOfService.LOW);
+                QualityOfService.LOW,
+                path + "/oic_svr_db_server.dat");
         msg(TAG, "Configuring platform.");
         OcPlatform.Configure(platformConfig);