Skip to content
Permalink
Browse files
BATCHEE616 removing OpenEJBJobOperatorClassLoaderFinder
  • Loading branch information
rmannibucau committed Mar 30, 2014
1 parent 6f9c3c3 commit 2523e389aceabf3beb8678333c7ec04af11e8c6e
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 162 deletions.
@@ -47,13 +47,6 @@
<artifactId>geronimo-atinject_1.0_spec</artifactId>
</dependency>

<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>openejb-core</artifactId>
<version>4.6.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
@@ -16,8 +16,6 @@
*/
package org.apache.batchee.servlet;

import org.apache.batchee.servlet.spi.JobOperatorClassLoaderFinder;

import javax.batch.operations.BatchRuntimeException;
import javax.batch.operations.JobExecutionNotRunningException;
import javax.batch.operations.JobOperator;
@@ -35,9 +33,6 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collections;
@@ -60,15 +55,12 @@ public class JBatchController extends HttpServlet {
private static final String START_MAPPING = "/start/";
private static final String DO_START_MAPPING = "/doStart/";
private static final String VIEW_MAPPING = "/view/";
public static final String BATCHEE_CLASSLOADER_FINDER_KEY = "batchee.classloader-finder";

private JobOperator operator;

private String context;
private String mapping = DEFAULT_MAPPING_SERVLET25;
private int executionByPage = DEFAULT_PAGE_SIZE;
private ClassLoader controllerLoader;
private JobOperatorClassLoaderFinder classLoaderFinder;

public JBatchController mapping(final String rawMapping) {
this.mapping = rawMapping.substring(0, rawMapping.length() - 2); // mapping pattern is /xxx/*
@@ -82,29 +74,7 @@ public JBatchController executionByPage(final int byPage) {

@Override
public void init(final ServletConfig config) throws ServletException {
controllerLoader = Thread.currentThread().getContextClassLoader();

final JobOperator delegate = BatchRuntime.getJobOperator();
classLoaderFinder = newClassLoaderFinder(
System.getProperty(BATCHEE_CLASSLOADER_FINDER_KEY, config.getInitParameter(BATCHEE_CLASSLOADER_FINDER_KEY)),
controllerLoader);

this.operator = JobOperator.class.cast(Proxy.newProxyInstance(
controllerLoader,
new Class<?>[] { JobOperator.class },
new InvocationHandler() {
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
final Thread thread = Thread.currentThread();
final ClassLoader original = thread.getContextClassLoader();
thread.setContextClassLoader(findLoaderToUse(original, method.getName(), args));
try {
return method.invoke(delegate, args);
} finally {
thread.setContextClassLoader(original);
}
}
}));
this.operator = BatchRuntime.getJobOperator();

this.context = config.getServletContext().getContextPath();
if ("/".equals(context)) {
@@ -114,29 +84,6 @@ public Object invoke(final Object proxy, final Method method, final Object[] arg
mapping = context + mapping;
}

private JobOperatorClassLoaderFinder newClassLoaderFinder(final String initParameter, final ClassLoader webappLoader) {
if (initParameter == null) {
return null;
}
try {
return JobOperatorClassLoaderFinder.class.cast(
controllerLoader.loadClass(initParameter.trim()).getConstructor(ClassLoader.class)
.newInstance(webappLoader));
} catch (final Exception e) {
throw new BatchRuntimeException(e.getMessage(), e);
}
}

protected ClassLoader findLoaderToUse(final ClassLoader original, String name, Object[] args) {
if (classLoaderFinder != null) {
final ClassLoader found = classLoaderFinder.find(name, args);
if (found != null) {
return found;
}
}
return original;
}

@Override
protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/html");

This file was deleted.

This file was deleted.

0 comments on commit 2523e38

Please sign in to comment.