nacx requested changes on this pull request.
Done reviewing. Thanks @alibazlamit!
> @@ -62,9 +65,10 @@
@Named("vpn:configurations:get")
@GET
@Path("/{vpnId}/configuration_file")
- @SelectJson("config_zip_file")
+ @ResponseParser(VPNConfigParser.class)
Is this parser class needed? You could leave the `@SelectJson` annotation and
just create the transformation function as a top level class.
> +import com.google.inject.TypeLiteral;
+import java.io.ByteArrayInputStream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.zip.ZipInputStream;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import org.apache.jclouds.oneandone.rest.domain.VPNConfig;
+import org.jclouds.http.functions.ParseJson;
+import org.jclouds.json.Json;
+
+@Singleton
+public class VPNConfigParser extends ParseJson<VPNConfig> {
+
+ @Inject
+ public VPNConfigParser(Json json) {
Remove the `public`modifier if this parser class remains.
> +import org.jclouds.json.Json;
+
+@Singleton
+public class VPNConfigParser extends ParseJson<VPNConfig> {
+
+ @Inject
+ public VPNConfigParser(Json json) {
+ super(json, TypeLiteral.get(VPNConfig.class));
+ }
+
+ public static class ToZipStream implements Function<VPNConfig,
ZipInputStream> {
+
+ @Inject
+ public ToZipStream() {
+ super();
+ }
Remove this constructor?
> +
+ public static class ToZipStream implements Function<VPNConfig,
ZipInputStream> {
+
+ @Inject
+ public ToZipStream() {
+ super();
+ }
+
+ @Override
+ public ZipInputStream apply(VPNConfig input) {
+ try {
+ byte[] decoded = base64().decode(input.content());
+ ZipInputStream zipStream = new ZipInputStream(new
ByteArrayInputStream(decoded));
+ return zipStream;
+ } catch (Exception ex) {
+
Logger.getLogger(VPNConfigParser.class.getName()).log(Level.SEVERE, null, ex);
Don't use java logging. jclouds provides a logging abstraction that allows
users to configure their preferred logging framework. In order to get the right
log, just declare the following class variable of type
`org.jclouds.logging.Logger`:
```java
@Resource
protected Logger logger = Logger.NULL;
```
This will configure a null logger by default, but use the one configured by
users providing a logging module when creating the jclouds context.
> + public static class ToZipStream implements Function<VPNConfig,
> ZipInputStream> {
+
+ @Inject
+ public ToZipStream() {
+ super();
+ }
+
+ @Override
+ public ZipInputStream apply(VPNConfig input) {
+ try {
+ byte[] decoded = base64().decode(input.content());
+ ZipInputStream zipStream = new ZipInputStream(new
ByteArrayInputStream(decoded));
+ return zipStream;
+ } catch (Exception ex) {
+
Logger.getLogger(VPNConfigParser.class.getName()).log(Level.SEVERE, null, ex);
+ return null;
Instead of returning `null` on *any* failure, are there situations where it
makes sense returning null? Can we return null just in those cases, and
propagate the exception otherwise?
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs/pull/319#pullrequestreview-1608407