Skip to content
Permalink
Browse files
BATCHEE-103 BATCHEE-102 BATCHEE-101 upgrade xbean + provide a jaxrs t…
…omeeplus webapp + use johnzon as default instead of jackson
  • Loading branch information
rmannibucau committed Aug 3, 2016
1 parent 7a74df4 commit 93adf7ce37efb3b3de4efb091a4731d7b8c67fe5
Showing 19 changed files with 163 additions and 32 deletions.
@@ -43,12 +43,8 @@
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
<version>0.9.2-incubating</version>
<version>${johnzon.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<properties>
<jackson.version>2.2.3</jackson.version>
</properties>
</project>
@@ -53,9 +53,12 @@
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<scope>compile</scope>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-json_1.0_spec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-jaxrs</artifactId>
</dependency>

<dependency>
@@ -138,7 +138,7 @@ protected Response doInvoke(final Method jaxrsMethod, final Method method, final
resolvedTarget = resolvedTarget.queryParam(qp.getKey(), qp.getValue());
}

final Invocation.Builder request = resolvedTarget.resolveTemplates(templates).request(MediaType.APPLICATION_JSON_TYPE);
final Invocation.Builder request = resolvedTarget.resolveTemplates(templates).request(findType(method.getReturnType()));
if (jaxrsMethod.getAnnotation(GET.class) != null) {
return request.get();
} else if (jaxrsMethod.getAnnotation(HEAD.class) != null) {
@@ -149,6 +149,10 @@ protected Response doInvoke(final Method jaxrsMethod, final Method method, final
throw new IllegalArgumentException("Unexpected http method");
}

private MediaType findType(final Class<?> returnType) {
return returnType.isPrimitive() ? MediaType.TEXT_PLAIN_TYPE : MediaType.APPLICATION_JSON_TYPE;
}

@Override
protected void close() {
// no-op
@@ -20,7 +20,7 @@

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 static final String JOHNZON_PROVIDER = "org.apache.batchee.jaxrs.common.johnzon.JohnzonBatcheeProvider";

private String baseUrl = null;
private String jsonProvider = null;
@@ -5,4 +5,4 @@
"value": "jbatch"
}
]
}}
}}
@@ -35,5 +35,12 @@
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jaxrs_1.1_spec</artifactId>
</dependency>

<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-jaxrs</artifactId>
<version>${johnzon.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
@@ -26,8 +26,8 @@
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("batchee")
public interface JBatchResource {
@GET
@@ -36,6 +36,7 @@ public interface JBatchResource {

@GET
@Path("job-instance/count/{name}")
@Produces(MediaType.TEXT_PLAIN)
int getJobInstanceCount(final @PathParam("name") String jobName);

@GET
@@ -68,10 +69,12 @@ public interface JBatchResource {

@POST
@Path("execution/start/{name}")
@Produces(MediaType.TEXT_PLAIN)
long start(final @PathParam("name") String jobXMLName, final RestProperties jobParameters);

@POST
@Path("execution/restart/{id}")
@Produces(MediaType.TEXT_PLAIN)
long restart(final @PathParam("id") long executionId, final RestProperties restartParameters);

@HEAD
@@ -41,6 +41,14 @@ public String getName() {
return name;
}

public void setName(final String name) {
this.name = name;
}

public void setId(final long id) {
this.id = id;
}

public static List<RestJobInstance> wrap(final List<JobInstance> jobInstances) {
final List<RestJobInstance> instances = new ArrayList<RestJobInstance>(jobInstances.size());
for (final JobInstance instance : jobInstances) {
@@ -24,6 +24,10 @@
public class RestProperties {
private List<RestEntry> entries = new LinkedList<RestEntry>();

public void setEntries(final List<RestEntry> entries) {
this.entries = entries;
}

public List<RestEntry> getEntries() {
return entries;
}
@@ -0,0 +1,51 @@
/*
* 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.common.johnzon;

import org.apache.johnzon.jaxrs.JohnzonProvider;
import org.apache.johnzon.mapper.MapperBuilder;
import org.apache.johnzon.mapper.converter.TimestampAdapter;

import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.ext.Provider;
import java.util.Comparator;

/**
* Johnzon integration provider to keep old date formatting.
*
* Note 1: that if your client and server use the same formatting/provider (jackson, default johnzon, other...)
* then this one is useless.
*
* Note 2: this provider also sort attribute in a deterministic order (String natural order).
*/
@Provider
@Produces("application/json")
@Consumes("application/json")
public class JohnzonBatcheeProvider<T> extends JohnzonProvider<T> {
public JohnzonBatcheeProvider() {
super(new MapperBuilder()
.addAdapter(new TimestampAdapter()) // backward compatibility
.setAttributeOrder(new Comparator<String>() { // deterministic order (useful when used with scripts)
@Override
public int compare(final String o1, final String o2) {
return o1.compareTo(o2);
}
})
.build(), null);
}
}
@@ -57,9 +57,12 @@
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<scope>compile</scope>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-json_1.0_spec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
@@ -58,6 +58,7 @@ public String[] getJobNames() {

@GET
@Path("job-instance/count/{name}")
@Produces(MediaType.TEXT_PLAIN)
public int getJobInstanceCount(final @PathParam("name") String jobName) {
return operator.getJobInstanceCount(jobName);
}
@@ -110,12 +111,14 @@ public RestStepExecution[] getStepExecutions(final @PathParam("id") long jobExec

@POST
@Path("execution/start/{name}")
@Produces(MediaType.TEXT_PLAIN)
public long start(final @PathParam("name") String jobXMLName, final RestProperties jobParameters) {
return operator.start(jobXMLName, RestProperties.unwrap(jobParameters));
}

@POST
@Path("execution/restart/{id}")
@Produces(MediaType.TEXT_PLAIN)
public long restart(final @PathParam("id") long executionId, final RestProperties restartParameters) {
return operator.restart(executionId, RestProperties.unwrap(restartParameters));
}
@@ -16,13 +16,13 @@
*/
package org.apache.batchee.jaxrs.server;

import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
import org.apache.batchee.jaxrs.common.JBatchResource;
import org.apache.batchee.jaxrs.common.RestEntry;
import org.apache.batchee.jaxrs.common.RestJobExecution;
import org.apache.batchee.jaxrs.common.RestJobInstance;
import org.apache.batchee.jaxrs.common.RestProperties;
import org.apache.batchee.jaxrs.common.RestStepExecution;
import org.apache.batchee.jaxrs.common.johnzon.JohnzonBatcheeProvider;
import org.apache.batchee.jaxrs.server.util.CreateSomeJobs;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxrs.client.WebClient;
@@ -43,8 +43,8 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.net.URL;
import java.util.Arrays;

import static java.util.Collections.singletonList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

@@ -63,7 +63,7 @@ public void getJobNames() {

@Test
public void getJobInstanceCount() {
final int count = newClient().path("job-instance/count/{id}", "init").get(Integer.class);
final int count = newClient().path("job-instance/count/{id}", "init").accept(MediaType.TEXT_PLAIN_TYPE).get(Integer.class);
assertEquals(1, count);
}

@@ -152,7 +152,7 @@ public static Archive<?> war() {
.up()
.createInitParam()
.paramName("jaxrs.providers")
.paramValue("com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider," + JBatchExceptionMapper.class.getName())
.paramValue(JohnzonBatcheeProvider.class.getName() + "," + JBatchExceptionMapper.class.getName())
.up()
.createInitParam()
.paramName("jaxrs.outInterceptors")
@@ -171,6 +171,6 @@ public static Archive<?> war() {
}

private WebClient newClient() {
return WebClient.create(base.toExternalForm() + "api/batchee", Arrays.asList(new JacksonJsonProvider())).accept(MediaType.APPLICATION_JSON_TYPE);
return WebClient.create(base.toExternalForm() + "api/batchee", singletonList(new JohnzonBatcheeProvider())).accept(MediaType.APPLICATION_JSON_TYPE);
}
}
@@ -41,6 +41,38 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-war</id>
<goals>
<goal>war</goal>
</goals>
<configuration>
<packagingExcludes>
WEB-INF/classes/META-INF/LICENSE,
WEB-INF/classes/META-INF/NOTICE,
WEB-INF/classes/META-INF/DEPENDENCIES
</packagingExcludes>
</configuration>
</execution>
<execution> <!-- tomee already provides johnzon, xbean and jbatch module, no need to add them -->
<id>war-tomee</id>
<goals>
<goal>war</goal>
</goals>
<configuration>
<classifier>tomeeplus</classifier>
<packagingExcludes>
WEB-INF/lib/batchee-jbatch*jar,
WEB-INF/lib/xbean-reflect*jar,
WEB-INF/lib/johnzon-*jar,
WEB-INF/classes/META-INF/LICENSE,
WEB-INF/classes/META-INF/NOTICE,
WEB-INF/classes/META-INF/DEPENDENCIES
</packagingExcludes>
</configuration>
</execution>
</executions>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<webResources>
@@ -55,11 +87,6 @@
<filtering>false</filtering>
</resource>
</webResources>
<packagingExcludes>
WEB-INF/classes/META-INF/LICENSE,
WEB-INF/classes/META-INF/NOTICE,
WEB-INF/classes/META-INF/DEPENDENCIES
</packagingExcludes>
</configuration>
</plugin>
<plugin>
@@ -183,9 +183,14 @@
<version>${batch-api.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>${jackson.version}</version>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-json_1.0_spec</artifactId>
<version>1.0-alpha-1</version>
</dependency>
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-jaxrs</artifactId>
<version>${johnzon.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
@@ -72,7 +72,7 @@
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-reflect</artifactId>
<version>3.16</version>
<version>4.5</version>
</dependency>

<dependency>
13 pom.xml
@@ -43,6 +43,7 @@
<batch-api.version>1.0</batch-api.version>
<jackson.version>2.2.2</jackson.version>
<jodatime.version>2.9.1</jodatime.version>
<johnzon.version>0.9.5-SNAPSHOT</johnzon.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<batchee.scmPubUrl>https://svn.apache.org/repos/asf/incubator/batchee/site</batchee.scmPubUrl>
<batchee.scmPubCheckoutDirectory>${basedir}/.site-content</batchee.scmPubCheckoutDirectory>
@@ -166,6 +167,18 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-json_1.0_spec</artifactId>
<version>1.0-alpha-1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-jaxrs</artifactId>
<version>${johnzon.version}</version>
</dependency>

<dependency>
<!-- We have optional support for joda time IF it is available on the classpath -->
<groupId>joda-time</groupId>

0 comments on commit 93adf7c

Please sign in to comment.