You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@batchee.apache.org by rm...@apache.org on 2015/03/22 15:51:38 UTC
incubator-batchee git commit: BATCHEE-59 patch from Kohei Nozaki
(thanks a lot) fixing properties parameter for start method in jaxrs-client +
starting to test it (still need an assert on server side but waiting featured
mock upgrade)
Repository: incubator-batchee
Updated Branches:
refs/heads/master a0ac7912d -> 9868a839d
BATCHEE-59 patch from Kohei Nozaki (thanks a lot) fixing properties parameter for start method in jaxrs-client + starting to test it (still need an assert on server side but waiting featured mock upgrade)
Project: http://git-wip-us.apache.org/repos/asf/incubator-batchee/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-batchee/commit/9868a839
Tree: http://git-wip-us.apache.org/repos/asf/incubator-batchee/tree/9868a839
Diff: http://git-wip-us.apache.org/repos/asf/incubator-batchee/diff/9868a839
Branch: refs/heads/master
Commit: 9868a839d21fb9966905ca00b576cdb7227ba68b
Parents: a0ac791
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Sun Mar 22 15:51:22 2015 +0100
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Sun Mar 22 15:51:22 2015 +0100
----------------------------------------------------------------------
gui/jaxrs/jaxrs-client/pom.xml | 2 +-
.../jaxrs/client/BatchEEJAXRS1CxfClient.java | 28 +++++++++++++--
.../jaxrs/client/BatchEEJAXRS2Client.java | 2 +-
.../jaxrs/client/ClientConfiguration.java | 15 +++++++-
.../jaxrs/client/CxfClientConfiguration.java | 31 +++++++++++++++++
.../batchee/jaxrs/client/ClientTestBase.java | 22 ++++++------
.../batchee/jaxrs/client/SimpleBatchlet.java | 36 ++++++++++++++++++++
.../batchee/execution/start/simple.json | 1 +
8 files changed, 121 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/9868a839/gui/jaxrs/jaxrs-client/pom.xml
----------------------------------------------------------------------
diff --git a/gui/jaxrs/jaxrs-client/pom.xml b/gui/jaxrs/jaxrs-client/pom.xml
index 8f14fd8..72ce2f8 100644
--- a/gui/jaxrs/jaxrs-client/pom.xml
+++ b/gui/jaxrs/jaxrs-client/pom.xml
@@ -42,7 +42,7 @@
<!-- cxf for "jaxrs 1" servers like TomEE only -->
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
- <version>2.6.9</version>
+ <version>2.6.16</version>
<scope>provided</scope>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/9868a839/gui/jaxrs/jaxrs-client/src/main/java/org/apache/batchee/jaxrs/client/BatchEEJAXRS1CxfClient.java
----------------------------------------------------------------------
diff --git a/gui/jaxrs/jaxrs-client/src/main/java/org/apache/batchee/jaxrs/client/BatchEEJAXRS1CxfClient.java b/gui/jaxrs/jaxrs-client/src/main/java/org/apache/batchee/jaxrs/client/BatchEEJAXRS1CxfClient.java
index bf5966b..c94b350 100644
--- a/gui/jaxrs/jaxrs-client/src/main/java/org/apache/batchee/jaxrs/client/BatchEEJAXRS1CxfClient.java
+++ b/gui/jaxrs/jaxrs-client/src/main/java/org/apache/batchee/jaxrs/client/BatchEEJAXRS1CxfClient.java
@@ -18,20 +18,24 @@ package org.apache.batchee.jaxrs.client;
import org.apache.batchee.jaxrs.client.http.Base64s;
import org.apache.batchee.jaxrs.common.JBatchResource;
+import org.apache.batchee.jaxrs.common.RestProperties;
import org.apache.cxf.configuration.jsse.TLSClientParameters;
import org.apache.cxf.configuration.security.AuthorizationPolicy;
import org.apache.cxf.jaxrs.client.Client;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.transport.http.HTTPConduit;
+import org.apache.cxf.transports.http.configuration.ConnectionType;
+import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
-import javax.batch.runtime.JobInstance;
-import javax.net.ssl.KeyManagerFactory;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.LinkedList;
import java.util.List;
+import java.util.Properties;
+import javax.batch.runtime.JobInstance;
+import javax.net.ssl.KeyManagerFactory;
class BatchEEJAXRS1CxfClient extends BatchEEJAXRSClientBase<Object> implements Base64s {
private final JBatchResource client;
@@ -45,6 +49,14 @@ class BatchEEJAXRS1CxfClient extends BatchEEJAXRSClientBase<Object> implements B
client = JAXRSClientFactory.create(configuration.getBaseUrl(), JBatchResource.class, providers);
final HTTPConduit conduit = WebClient.getConfig(client).getHttpConduit();
+ if (CxfClientConfiguration.class.isInstance(conduit)) {
+ final HTTPClientPolicy policy = CxfClientConfiguration.class.cast(configuration).getPolicy();
+ if (policy != null) {
+ conduit.setClient(policy);
+ }
+ } else {
+ conduit.setClient(defaultClientPolicy());
+ }
final ClientSslConfiguration ssl = configuration.getSsl();
if (ssl != null) {
@@ -86,6 +98,15 @@ class BatchEEJAXRS1CxfClient extends BatchEEJAXRSClientBase<Object> implements B
}
}
+ private static HTTPClientPolicy defaultClientPolicy() {
+ final HTTPClientPolicy client = new HTTPClientPolicy();
+ client.setConnection(ConnectionType.CLOSE);
+ client.setAllowChunking(false);
+ client.setConnectionTimeout(0);
+ client.setReceiveTimeout(0);
+ return client;
+ }
+
@Override
protected Object extractEntity(final Object o, final Type genericReturnType) {
return o;
@@ -104,6 +125,9 @@ class BatchEEJAXRS1CxfClient extends BatchEEJAXRSClientBase<Object> implements B
usedArgs = new Object[] { ji.getInstanceId(), ji.getJobName() };
}
}
+ if (args != null && args.length == 2 && Properties.class.isInstance(args[1])) {
+ usedArgs[1] = RestProperties.wrap(Properties.class.cast(args[1]));
+ }
try {
return jaxrsMethod.invoke(client, usedArgs);
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/9868a839/gui/jaxrs/jaxrs-client/src/main/java/org/apache/batchee/jaxrs/client/BatchEEJAXRS2Client.java
----------------------------------------------------------------------
diff --git a/gui/jaxrs/jaxrs-client/src/main/java/org/apache/batchee/jaxrs/client/BatchEEJAXRS2Client.java b/gui/jaxrs/jaxrs-client/src/main/java/org/apache/batchee/jaxrs/client/BatchEEJAXRS2Client.java
index 83f3c0b..9c0556b 100644
--- a/gui/jaxrs/jaxrs-client/src/main/java/org/apache/batchee/jaxrs/client/BatchEEJAXRS2Client.java
+++ b/gui/jaxrs/jaxrs-client/src/main/java/org/apache/batchee/jaxrs/client/BatchEEJAXRS2Client.java
@@ -127,7 +127,7 @@ class BatchEEJAXRS2Client extends BatchEEJAXRSClientBase<Response> {
}
if (!found) {
- body = convertParam(body, type);
+ body = convertParam(args[i], type);
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/9868a839/gui/jaxrs/jaxrs-client/src/main/java/org/apache/batchee/jaxrs/client/ClientConfiguration.java
----------------------------------------------------------------------
diff --git a/gui/jaxrs/jaxrs-client/src/main/java/org/apache/batchee/jaxrs/client/ClientConfiguration.java b/gui/jaxrs/jaxrs-client/src/main/java/org/apache/batchee/jaxrs/client/ClientConfiguration.java
index 360d60c..304e028 100644
--- a/gui/jaxrs/jaxrs-client/src/main/java/org/apache/batchee/jaxrs/client/ClientConfiguration.java
+++ b/gui/jaxrs/jaxrs-client/src/main/java/org/apache/batchee/jaxrs/client/ClientConfiguration.java
@@ -16,8 +16,11 @@
*/
package org.apache.batchee.jaxrs.client;
+import static java.util.Arrays.asList;
+
public class ClientConfiguration {
private static final String JACKSON_PROVIDER = "com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider";
+ private static final String JOHNZON_PROVIDER = "org.apache.johnzon.jaxrs.JohnzonProvider";
private String baseUrl = null;
private String jsonProvider = null;
@@ -34,7 +37,17 @@ public class ClientConfiguration {
public Class<?> getJsonProvider() {
if (jsonProvider == null) { // try to force jackson
- setJsonProvider(JACKSON_PROVIDER);
+ for (final String p : asList(JOHNZON_PROVIDER, JACKSON_PROVIDER)) {
+ try {
+ Thread.currentThread().getContextClassLoader().loadClass(p);
+ setJsonProvider(p);
+ } catch (final ClassNotFoundException cnfe) {
+ // no-op
+ }
+ }
+ if (jsonProvider == null) {
+ throw new IllegalStateException("No JSon provider found, please set it on the client configuration");
+ }
}
try {
return Class.class.cast(Thread.currentThread().getContextClassLoader().loadClass(jsonProvider));
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/9868a839/gui/jaxrs/jaxrs-client/src/main/java/org/apache/batchee/jaxrs/client/CxfClientConfiguration.java
----------------------------------------------------------------------
diff --git a/gui/jaxrs/jaxrs-client/src/main/java/org/apache/batchee/jaxrs/client/CxfClientConfiguration.java b/gui/jaxrs/jaxrs-client/src/main/java/org/apache/batchee/jaxrs/client/CxfClientConfiguration.java
new file mode 100644
index 0000000..45cdf29
--- /dev/null
+++ b/gui/jaxrs/jaxrs-client/src/main/java/org/apache/batchee/jaxrs/client/CxfClientConfiguration.java
@@ -0,0 +1,31 @@
+/*
+ * 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.
+ */
+package org.apache.batchee.jaxrs.client;
+
+import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
+
+public class CxfClientConfiguration extends ClientConfiguration {
+ private HTTPClientPolicy policy;
+
+ public HTTPClientPolicy getPolicy() {
+ return policy;
+ }
+
+ public void setPolicy(final HTTPClientPolicy policy) {
+ this.policy = policy;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/9868a839/gui/jaxrs/jaxrs-client/src/test/java/org/apache/batchee/jaxrs/client/ClientTestBase.java
----------------------------------------------------------------------
diff --git a/gui/jaxrs/jaxrs-client/src/test/java/org/apache/batchee/jaxrs/client/ClientTestBase.java b/gui/jaxrs/jaxrs-client/src/test/java/org/apache/batchee/jaxrs/client/ClientTestBase.java
index b024add..d7c0cec 100644
--- a/gui/jaxrs/jaxrs-client/src/test/java/org/apache/batchee/jaxrs/client/ClientTestBase.java
+++ b/gui/jaxrs/jaxrs-client/src/test/java/org/apache/batchee/jaxrs/client/ClientTestBase.java
@@ -24,16 +24,15 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
import javax.batch.operations.JobOperator;
import javax.batch.runtime.JobExecution;
import javax.batch.runtime.JobInstance;
import javax.batch.runtime.StepExecution;
import javax.ws.rs.ext.RuntimeDelegate;
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.util.List;
-import java.util.Properties;
-import java.util.Set;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
@@ -46,12 +45,8 @@ public abstract class ClientTestBase {
@BeforeClass
public static void startServer() throws IOException {
- final ServerSocket server = new ServerSocket(0);
- port = server.getLocalPort();
- server.close();
-
- mockServer = new FeaturedHttpServerBuilder().port(port).build().start();
-
+ mockServer = new FeaturedHttpServerBuilder().port(-1).build().start();
+ port = mockServer.getPort();
RuntimeDelegate.setInstance(null); // reset
}
@@ -68,6 +63,11 @@ public abstract class ClientTestBase {
}
@Test
+ public void start() {
+ assertEquals(1L, client.start("simple", new Properties()));
+ }
+
+ @Test
public void jobNames() {
final Set<String> names = client.getJobNames();
assertNotNull(names);
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/9868a839/gui/jaxrs/jaxrs-client/src/test/java/org/apache/batchee/jaxrs/client/SimpleBatchlet.java
----------------------------------------------------------------------
diff --git a/gui/jaxrs/jaxrs-client/src/test/java/org/apache/batchee/jaxrs/client/SimpleBatchlet.java b/gui/jaxrs/jaxrs-client/src/test/java/org/apache/batchee/jaxrs/client/SimpleBatchlet.java
new file mode 100644
index 0000000..0f30fc1
--- /dev/null
+++ b/gui/jaxrs/jaxrs-client/src/test/java/org/apache/batchee/jaxrs/client/SimpleBatchlet.java
@@ -0,0 +1,36 @@
+/*
+ * 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.
+ */
+package org.apache.batchee.jaxrs.client;
+
+import java.util.Properties;
+import javax.batch.api.AbstractBatchlet;
+import javax.batch.runtime.BatchRuntime;
+import javax.batch.runtime.context.JobContext;
+import javax.inject.Inject;
+
+public class SimpleBatchlet extends AbstractBatchlet {
+ public static Properties jobParameters;
+
+ @Inject
+ private JobContext jobContext;
+
+ @Override
+ public String process() throws Exception {
+ jobParameters = BatchRuntime.getJobOperator().getJobExecution(jobContext.getExecutionId()).getJobParameters();
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/9868a839/gui/jaxrs/jaxrs-client/src/test/resources/batchee/execution/start/simple.json
----------------------------------------------------------------------
diff --git a/gui/jaxrs/jaxrs-client/src/test/resources/batchee/execution/start/simple.json b/gui/jaxrs/jaxrs-client/src/test/resources/batchee/execution/start/simple.json
new file mode 100644
index 0000000..56a6051
--- /dev/null
+++ b/gui/jaxrs/jaxrs-client/src/test/resources/batchee/execution/start/simple.json
@@ -0,0 +1 @@
+1
\ No newline at end of file