{"_id":"588f722cbcace50f0052ba19","version":{"_id":"588f722bbcace50f0052b9e1","project":"565f5fa26bafd40d0030a064","__v":1,"createdAt":"2017-01-30T17:04:43.410Z","releaseDate":"2017-01-30T17:04:43.410Z","categories":["588f722bbcace50f0052b9e2","588f722bbcace50f0052b9e3","588f722bbcace50f0052b9e4","588f722bbcace50f0052b9e5","588f722bbcace50f0052b9e6","588f722bbcace50f0052b9e7"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"5.3.0","version":"5.3.0"},"__v":0,"category":{"_id":"588f722bbcace50f0052b9e5","version":"588f722bbcace50f0052b9e1","__v":0,"project":"565f5fa26bafd40d0030a064","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-18T20:31:28.395Z","from_sync":false,"order":3,"slug":"sdks","title":"Client SDKs"},"user":"565f5f29de5dc50d00acfe9f","parentDoc":null,"project":"565f5fa26bafd40d0030a064","updates":["57e54ae203746919001f0d43","57ea8c327728c8220022bffa"],"next":{"pages":[],"description":""},"createdAt":"2016-02-19T16:11:10.720Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"The nanoscale.io Java SDK is a lightweight SDK written in Java. It can be used to connect things like mobile devices and server side applications to a nanoscale.io gateway. You can view the source <a href=\"https://github.com/nanoscaleio/justapis-java-sdk\" target=\"_blank\">here on GitHub</a>.\n\n## Dependencies\n\nThese dependencies are needed:\n\n### Gradle\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"compile 'com.google.code.gson:gson:2.5'\\ncompile 'org.apache.commons:commons-lang3:3.4'\\ncompile 'com.google.guava:guava:18.0'\",\n      \"language\": \"java\",\n      \"name\": \"Gradle\"\n    }\n  ]\n}\n[/block]\n### Maven\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<dependency>\\n    <groupId>com.google.code.gson</groupId>\\n    <artifactId>gson</artifactId>\\n    <version>2.5</version>\\n</dependency>\\n\\n<dependency>\\n    <groupId>org.apache.commons</groupId>\\n    <artifactId>commons-lang3</artifactId>\\n    <version>3.4</version>\\n</dependency>\\n\\n<dependency>\\n    <groupId>com.google.guava</groupId>\\n    <artifactId>guava</artifactId>\\n    <version>18.0</version>\\n</dependency>\",\n      \"language\": \"xml\",\n      \"name\": \"Maven\"\n    }\n  ]\n}\n[/block]\n## Setup\n\nThere are a few ways to add these dependencies. Below is for Eclipse:\n\n0. Add APGW-[version]-SNAPSHOT.jar into the libs folder for your java project.\n\n1. You also need to also make sure the library is listed as a dependency in File->Properties->Java Build Path->Jars.\n\n2. If not using maven or gradle, you may need to download the jars for the above dependencies.\n\nIf using maven or gradle build system, you need to add the above dependencies into proper build scripts.\n\n## Quick Examples\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"APGateway.Builder builder = new APGateway.Builder();\\nbuilder.url(\\\"http://foo.lvh.me:3000/api/v1/foo\\\");\\n\\nAPGateway gw = builder.build();\\nMap<String,String> param = new HashMap<String,String>();\\nparam.put(\\\"foo\\\", \\\"bar\\\");\\ngw.setPostParam(param);\\n\\ngw.post(\\\"/bar\\\");\\n\\nResponseFromRequest response = gw.readResponse();\\n\\nSystem.out.println(\\\"response: \\\" + response.data);\\n\",\n      \"language\": \"java\",\n      \"name\": \"Send a POST request synchronously\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \" APGateway.Builder builder = new APGateway.Builder();\\nbuilder.url(\\\"http://localhost:3000\\\");\\n\\nAPGateway gw = builder.build();\\n\\ngw.get(\\\"/api/v1/foo\\\", new APStringCallback() {\\n    :::at:::Override\\n    public void finished(String object, Throwable ex) {\\n        if (ex == null) {\\n            System.out.println(\\\"success\\\");\\n        } else {                    \\n            System.out.println(\\\"failure\\\");\\n            ex.printStackTrace();\\n        }\\n    }\\n});\",\n      \"language\": \"java\",\n      \"name\": \"Send a GET request asynchronously\"\n    }\n  ]\n}\n[/block]\n### Certificate pinning\n\nCertificate pinning allows you to tie certificates against specified domains. It defends against attacks on certificate authorities. It has it's limitations as well.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"APGateway.getCertPinningManager().setupCa(\\\"myalias\\\", certificateInBytes);\\n        \\nAPGateway.Builder builder = new APGateway.Builder();\\nbuilder.url(\\\"https://localhost:3000\\\");\\nbuilder.useCertPinning(true);\\n\\nAPGateway gw = builder.build();\\ngw.post(\\\"/bar\\\");\",\n      \"language\": \"java\",\n      \"name\": \"Certificate pinning\"\n    }\n  ]\n}\n[/block]\n### Caching\n\nThe default cache store is an in-memory cache.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"APGateway.Builder builder = new APGateway.Builder();\\nbuilder.url(\\\"http://localhost:1080/api/v1/foo\\\");\\n\\nAPGateway gw = builder.build();\\ngw.useCaching(true).get();\\n\\nResponseFromRequest response = gw.readResponse();       \\nSystem.out.println(\\\"response: \\\" + response.data);\",\n      \"language\": \"java\",\n      \"name\": \"Caching\"\n    }\n  ]\n}\n[/block]\nYou can set your own cache store by subclassing java.net.ResponseCache and calling:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Config.setCacheManager(new MyMemoryCache());\",\n      \"language\": \"java\",\n      \"name\": \"Custom cache store\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"java","type":"basic","title":"Java"}
The nanoscale.io Java SDK is a lightweight SDK written in Java. It can be used to connect things like mobile devices and server side applications to a nanoscale.io gateway. You can view the source <a href="https://github.com/nanoscaleio/justapis-java-sdk" target="_blank">here on GitHub</a>. ## Dependencies These dependencies are needed: ### Gradle [block:code] { "codes": [ { "code": "compile 'com.google.code.gson:gson:2.5'\ncompile 'org.apache.commons:commons-lang3:3.4'\ncompile 'com.google.guava:guava:18.0'", "language": "java", "name": "Gradle" } ] } [/block] ### Maven [block:code] { "codes": [ { "code": "<dependency>\n <groupId>com.google.code.gson</groupId>\n <artifactId>gson</artifactId>\n <version>2.5</version>\n</dependency>\n\n<dependency>\n <groupId>org.apache.commons</groupId>\n <artifactId>commons-lang3</artifactId>\n <version>3.4</version>\n</dependency>\n\n<dependency>\n <groupId>com.google.guava</groupId>\n <artifactId>guava</artifactId>\n <version>18.0</version>\n</dependency>", "language": "xml", "name": "Maven" } ] } [/block] ## Setup There are a few ways to add these dependencies. Below is for Eclipse: 0. Add APGW-[version]-SNAPSHOT.jar into the libs folder for your java project. 1. You also need to also make sure the library is listed as a dependency in File->Properties->Java Build Path->Jars. 2. If not using maven or gradle, you may need to download the jars for the above dependencies. If using maven or gradle build system, you need to add the above dependencies into proper build scripts. ## Quick Examples [block:code] { "codes": [ { "code": "APGateway.Builder builder = new APGateway.Builder();\nbuilder.url(\"http://foo.lvh.me:3000/api/v1/foo\");\n\nAPGateway gw = builder.build();\nMap<String,String> param = new HashMap<String,String>();\nparam.put(\"foo\", \"bar\");\ngw.setPostParam(param);\n\ngw.post(\"/bar\");\n\nResponseFromRequest response = gw.readResponse();\n\nSystem.out.println(\"response: \" + response.data);\n", "language": "java", "name": "Send a POST request synchronously" } ] } [/block] [block:code] { "codes": [ { "code": " APGateway.Builder builder = new APGateway.Builder();\nbuilder.url(\"http://localhost:3000\");\n\nAPGateway gw = builder.build();\n\ngw.get(\"/api/v1/foo\", new APStringCallback() {\n @Override\n public void finished(String object, Throwable ex) {\n if (ex == null) {\n System.out.println(\"success\");\n } else { \n System.out.println(\"failure\");\n ex.printStackTrace();\n }\n }\n});", "language": "java", "name": "Send a GET request asynchronously" } ] } [/block] ### Certificate pinning Certificate pinning allows you to tie certificates against specified domains. It defends against attacks on certificate authorities. It has it's limitations as well. [block:code] { "codes": [ { "code": "APGateway.getCertPinningManager().setupCa(\"myalias\", certificateInBytes);\n \nAPGateway.Builder builder = new APGateway.Builder();\nbuilder.url(\"https://localhost:3000\");\nbuilder.useCertPinning(true);\n\nAPGateway gw = builder.build();\ngw.post(\"/bar\");", "language": "java", "name": "Certificate pinning" } ] } [/block] ### Caching The default cache store is an in-memory cache. [block:code] { "codes": [ { "code": "APGateway.Builder builder = new APGateway.Builder();\nbuilder.url(\"http://localhost:1080/api/v1/foo\");\n\nAPGateway gw = builder.build();\ngw.useCaching(true).get();\n\nResponseFromRequest response = gw.readResponse(); \nSystem.out.println(\"response: \" + response.data);", "language": "java", "name": "Caching" } ] } [/block] You can set your own cache store by subclassing java.net.ResponseCache and calling: [block:code] { "codes": [ { "code": "Config.setCacheManager(new MyMemoryCache());", "language": "java", "name": "Custom cache store" } ] } [/block]