You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/11/15 13:31:33 UTC
[camel] 05/05: CAMEL-12810 - Fixed CS
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 8e96df649421455c745988630e5256572b5dd2e8
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Nov 15 14:28:11 2018 +0100
CAMEL-12810 - Fixed CS
---
.../apache/camel/component/ipfs/IPFSComponent.java | 22 ++++---
.../apache/camel/component/ipfs/IPFSEndpoint.java | 13 ++--
.../apache/camel/component/ipfs/IPFSProducer.java | 39 ++++++-----
.../camel/component/ipfs/SimpleIPFSTest.java | 76 ++++++++++------------
4 files changed, 78 insertions(+), 72 deletions(-)
diff --git a/components/camel-ipfs/src/main/java/org/apache/camel/component/ipfs/IPFSComponent.java b/components/camel-ipfs/src/main/java/org/apache/camel/component/ipfs/IPFSComponent.java
index 9d5b228..f6cb6f8 100644
--- a/components/camel-ipfs/src/main/java/org/apache/camel/component/ipfs/IPFSComponent.java
+++ b/components/camel-ipfs/src/main/java/org/apache/camel/component/ipfs/IPFSComponent.java
@@ -19,16 +19,16 @@ package org.apache.camel.component.ipfs;
import java.net.URI;
import java.util.Map;
-import org.apache.camel.Endpoint;
-import org.apache.camel.impl.DefaultComponent;
-
import io.nessus.ipfs.IPFSClient;
import io.nessus.ipfs.impl.DefaultIPFSClient;
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+
public class IPFSComponent extends DefaultComponent {
private IPFSClient client;
-
+
@Override
protected Endpoint createEndpoint(String urispec, String remaining, Map<String, Object> params) throws Exception {
@@ -42,15 +42,19 @@ public class IPFSComponent extends DefaultComponent {
int port = uri.getPort();
String cmd = remaining;
if (!cmd.equals(host)) {
- if (host != null) config.setIpfsHost(host);
- if (port > 0) config.setIpfsPort(port);
+ if (host != null) {
+ config.setIpfsHost(host);
+ }
+ if (port > 0) {
+ config.setIpfsPort(port);
+ }
int idx = cmd.indexOf('/');
cmd = cmd.substring(idx + 1);
}
config.setIpfsCmd(cmd);
-
+
client = createClient(config);
-
+
return new IPFSEndpoint(urispec, this, config);
}
@@ -61,4 +65,4 @@ public class IPFSComponent extends DefaultComponent {
private synchronized IPFSClient createClient(IPFSConfiguration config) {
return new DefaultIPFSClient(config.getIpfsHost(), config.getIpfsPort());
}
-}
\ No newline at end of file
+}
diff --git a/components/camel-ipfs/src/main/java/org/apache/camel/component/ipfs/IPFSEndpoint.java b/components/camel-ipfs/src/main/java/org/apache/camel/component/ipfs/IPFSEndpoint.java
index 6709332..0494151 100644
--- a/components/camel-ipfs/src/main/java/org/apache/camel/component/ipfs/IPFSEndpoint.java
+++ b/components/camel-ipfs/src/main/java/org/apache/camel/component/ipfs/IPFSEndpoint.java
@@ -23,6 +23,8 @@ import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
+import io.nessus.ipfs.IPFSClient;
+
import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
@@ -31,17 +33,16 @@ import org.apache.camel.impl.DefaultEndpoint;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
-import io.nessus.ipfs.IPFSClient;
-
/**
- * The camel-ipfs component provides access to the Interplanetary File System (IPFS).
+ * The camel-ipfs component provides access to the Interplanetary File System
+ * (IPFS).
*/
@UriEndpoint(firstVersion = "2.23.0", scheme = "ipfs", title = "IPFS", syntax = "ipfs:host:port/cmd", producerOnly = true, label = "file,ipfs")
public class IPFSEndpoint extends DefaultEndpoint {
@UriParam
private final IPFSConfiguration configuration;
-
+
public IPFSEndpoint(String uri, IPFSComponent component, IPFSConfiguration configuration) {
super(uri, component);
this.configuration = configuration;
@@ -49,7 +50,7 @@ public class IPFSEndpoint extends DefaultEndpoint {
@Override
public IPFSComponent getComponent() {
- return (IPFSComponent) super.getComponent();
+ return (IPFSComponent)super.getComponent();
}
@Override
@@ -79,7 +80,7 @@ public class IPFSEndpoint extends DefaultEndpoint {
throw new IllegalArgumentException("Unsupported command: " + cmd);
}
}
-
+
String ipfsVersion() throws IOException {
return ipfs().version();
}
diff --git a/components/camel-ipfs/src/main/java/org/apache/camel/component/ipfs/IPFSProducer.java b/components/camel-ipfs/src/main/java/org/apache/camel/component/ipfs/IPFSProducer.java
index 0f6e533..1554927 100644
--- a/components/camel-ipfs/src/main/java/org/apache/camel/component/ipfs/IPFSProducer.java
+++ b/components/camel-ipfs/src/main/java/org/apache/camel/component/ipfs/IPFSProducer.java
@@ -23,19 +23,18 @@ import java.nio.file.Paths;
import java.util.List;
import org.apache.camel.Exchange;
-import org.apache.camel.impl.DefaultProducer;
-
import org.apache.camel.component.ipfs.IPFSConfiguration.IPFSCommand;
+import org.apache.camel.impl.DefaultProducer;
public class IPFSProducer extends DefaultProducer {
-
+
public IPFSProducer(IPFSEndpoint endpoint) {
super(endpoint);
}
@Override
public IPFSEndpoint getEndpoint() {
- return (IPFSEndpoint) super.getEndpoint();
+ return (IPFSEndpoint)super.getEndpoint();
}
@Override
@@ -43,14 +42,14 @@ public class IPFSProducer extends DefaultProducer {
IPFSEndpoint endpoint = getEndpoint();
IPFSCommand cmd = endpoint.getCommand();
-
+
if (IPFSCommand.version == cmd) {
-
+
String resp = endpoint.ipfsVersion();
exchange.getMessage().setBody(resp);
-
- } else if (IPFSCommand.add == cmd) {
-
+
+ } else if (IPFSCommand.add == cmd) {
+
Path path = pathFromBody(exchange);
List<String> cids = endpoint.ipfsAdd(path);
Object resp = cids;
@@ -58,20 +57,20 @@ public class IPFSProducer extends DefaultProducer {
resp = cids.size() > 0 ? cids.get(0) : null;
}
exchange.getMessage().setBody(resp);
-
- } else if (IPFSCommand.cat == cmd) {
+
+ } else if (IPFSCommand.cat == cmd) {
String cid = exchange.getMessage().getBody(String.class);
InputStream resp = endpoint.ipfsCat(cid);
exchange.getMessage().setBody(resp);
-
- } else if (IPFSCommand.get == cmd) {
+
+ } else if (IPFSCommand.get == cmd) {
Path outdir = endpoint.getConfiguration().getOutdir();
String cid = exchange.getMessage().getBody(String.class);
Path resp = endpoint.ipfsGet(cid, outdir);
exchange.getMessage().setBody(resp);
-
+
} else {
throw new UnsupportedOperationException(cmd.toString());
}
@@ -79,9 +78,15 @@ public class IPFSProducer extends DefaultProducer {
private Path pathFromBody(Exchange exchange) {
Object body = exchange.getMessage().getBody();
- if (body instanceof Path) return (Path) body;
- if (body instanceof String) return Paths.get((String) body);
- if (body instanceof File) return ((File) body).toPath();
+ if (body instanceof Path) {
+ return (Path)body;
+ }
+ if (body instanceof String) {
+ return Paths.get((String)body);
+ }
+ if (body instanceof File) {
+ return ((File)body).toPath();
+ }
throw new IllegalArgumentException("Invalid path: " + body);
}
}
diff --git a/components/camel-ipfs/src/test/java/org/apache/camel/component/ipfs/SimpleIPFSTest.java b/components/camel-ipfs/src/test/java/org/apache/camel/component/ipfs/SimpleIPFSTest.java
index 589b919..07aec74 100644
--- a/components/camel-ipfs/src/test/java/org/apache/camel/component/ipfs/SimpleIPFSTest.java
+++ b/components/camel-ipfs/src/test/java/org/apache/camel/component/ipfs/SimpleIPFSTest.java
@@ -1,12 +1,10 @@
-/*
- * #%L
- * Wildfly Camel :: Testsuite
- * %%
- * Copyright (C) 2013 - 2014 RedHat
- * %%
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@@ -15,9 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * #L%
*/
-
package org.apache.camel.component.ipfs;
import java.io.ByteArrayOutputStream;
@@ -29,6 +25,8 @@ import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
+import io.nessus.utils.StreamUtils;
+
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
@@ -37,8 +35,6 @@ import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;
-import io.nessus.utils.StreamUtils;
-
public class SimpleIPFSTest {
@Test
@@ -56,7 +52,7 @@ public class SimpleIPFSTest {
camelctx.start();
assumeIPFS(camelctx);
-
+
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
String resA = producer.requestBody("direct:startA", null, String.class);
@@ -73,8 +69,8 @@ public class SimpleIPFSTest {
@Test
public void ipfsAddSingle() throws Exception {
- String HASH = "QmYgjSRbXFPdPYKqQSnUjmXLYLudVahEJQotMaAJKt6Lbd";
-
+ String hash = "QmYgjSRbXFPdPYKqQSnUjmXLYLudVahEJQotMaAJKt6Lbd";
+
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
@@ -84,14 +80,14 @@ public class SimpleIPFSTest {
});
Path path = Paths.get("src/test/resources/html/index.html");
-
+
camelctx.start();
assumeIPFS(camelctx);
-
+
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
String res = producer.requestBody("direct:start", path, String.class);
- Assert.assertEquals(HASH, res);
+ Assert.assertEquals(hash, res);
} finally {
camelctx.stop();
}
@@ -101,8 +97,8 @@ public class SimpleIPFSTest {
@SuppressWarnings("unchecked")
public void ipfsAddRecursive() throws Exception {
- String HASH = "Qme6hd6tYXTFb7bb7L3JZ5U6ygktpAHKxbaeffYyQN85mW";
-
+ String hash = "Qme6hd6tYXTFb7bb7L3JZ5U6ygktpAHKxbaeffYyQN85mW";
+
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
@@ -112,15 +108,15 @@ public class SimpleIPFSTest {
});
Path path = Paths.get("src/test/resources/html");
-
+
camelctx.start();
assumeIPFS(camelctx);
-
+
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
List<String> res = producer.requestBody("direct:start", path, List.class);
Assert.assertEquals(10, res.size());
- Assert.assertEquals(HASH, res.get(9));
+ Assert.assertEquals(hash, res.get(9));
} finally {
camelctx.stop();
}
@@ -129,8 +125,8 @@ public class SimpleIPFSTest {
@Test
public void ipfsCat() throws Exception {
- String HASH = "QmUD7uG5prAMHbcCfp4x1G1mMSpywcSMHTGpq62sbpDAg6";
-
+ String hash = "QmUD7uG5prAMHbcCfp4x1G1mMSpywcSMHTGpq62sbpDAg6";
+
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
@@ -141,10 +137,10 @@ public class SimpleIPFSTest {
camelctx.start();
assumeIPFS(camelctx);
-
+
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
- InputStream res = producer.requestBody("direct:start", HASH, InputStream.class);
+ InputStream res = producer.requestBody("direct:start", hash, InputStream.class);
verifyFileContent(res);
} finally {
camelctx.stop();
@@ -154,8 +150,8 @@ public class SimpleIPFSTest {
@Test
public void ipfsGetSingle() throws Exception {
- String HASH = "QmUD7uG5prAMHbcCfp4x1G1mMSpywcSMHTGpq62sbpDAg6";
-
+ String hash = "QmUD7uG5prAMHbcCfp4x1G1mMSpywcSMHTGpq62sbpDAg6";
+
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
@@ -166,11 +162,11 @@ public class SimpleIPFSTest {
camelctx.start();
assumeIPFS(camelctx);
-
+
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
- Path res = producer.requestBody("direct:start", HASH, Path.class);
- Assert.assertEquals(Paths.get("target", HASH), res);
+ Path res = producer.requestBody("direct:start", hash, Path.class);
+ Assert.assertEquals(Paths.get("target", hash), res);
verifyFileContent(new FileInputStream(res.toFile()));
} finally {
camelctx.stop();
@@ -180,8 +176,8 @@ public class SimpleIPFSTest {
@Test
public void ipfsGetRecursive() throws Exception {
- String HASH = "Qme6hd6tYXTFb7bb7L3JZ5U6ygktpAHKxbaeffYyQN85mW";
-
+ String hash = "Qme6hd6tYXTFb7bb7L3JZ5U6ygktpAHKxbaeffYyQN85mW";
+
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
@@ -192,11 +188,11 @@ public class SimpleIPFSTest {
camelctx.start();
assumeIPFS(camelctx);
-
+
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
- Path res = producer.requestBody("direct:start", HASH, Path.class);
- Assert.assertEquals(Paths.get("target", HASH), res);
+ Path res = producer.requestBody("direct:start", hash, Path.class);
+ Assert.assertEquals(Paths.get("target", hash), res);
Assert.assertTrue(res.toFile().isDirectory());
Assert.assertTrue(res.resolve("index.html").toFile().exists());
} finally {
@@ -207,11 +203,11 @@ public class SimpleIPFSTest {
private void verifyFileContent(InputStream ins) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
StreamUtils.copyStream(ins, baos);
- Assert.assertEquals("The quick brown fox jumps over the lazy dog.", new String (baos.toByteArray()));
+ Assert.assertEquals("The quick brown fox jumps over the lazy dog.", new String(baos.toByteArray()));
}
private void assumeIPFS(CamelContext camelctx) {
IPFSComponent comp = camelctx.getComponent("ipfs", IPFSComponent.class);
Assume.assumeTrue(comp.getIPFSClient().hasConnection());
}
-}
\ No newline at end of file
+}