|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2011 the original author or authors. |
| 2 | + * Copyright 2002-2012 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
17 | 17 | package org.springframework.scheduling.quartz;
|
18 | 18 |
|
19 | 19 | import java.lang.reflect.InvocationTargetException;
|
| 20 | +import java.lang.reflect.Method; |
20 | 21 |
|
21 | 22 | import org.apache.commons.logging.Log;
|
22 | 23 | import org.apache.commons.logging.LogFactory;
|
|
40 | 41 | import org.springframework.util.Assert;
|
41 | 42 | import org.springframework.util.ClassUtils;
|
42 | 43 | import org.springframework.util.MethodInvoker;
|
| 44 | +import org.springframework.util.ReflectionUtils; |
43 | 45 |
|
44 | 46 | /**
|
45 | 47 | * {@link org.springframework.beans.factory.FactoryBean} that exposes a
|
@@ -80,13 +82,23 @@ public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethod
|
80 | 82 |
|
81 | 83 | private static Class<?> jobDetailImplClass;
|
82 | 84 |
|
| 85 | + private static Method setResultMethod; |
| 86 | + |
83 | 87 | static {
|
84 | 88 | try {
|
85 | 89 | jobDetailImplClass = Class.forName("org.quartz.impl.JobDetailImpl");
|
86 | 90 | }
|
87 | 91 | catch (ClassNotFoundException ex) {
|
88 | 92 | jobDetailImplClass = null;
|
89 | 93 | }
|
| 94 | + try { |
| 95 | + Class jobExecutionContextClass = |
| 96 | + QuartzJobBean.class.getClassLoader().loadClass("org.quartz.JobExecutionContext"); |
| 97 | + setResultMethod = jobExecutionContextClass.getMethod("setResult"); |
| 98 | + } |
| 99 | + catch (Exception ex) { |
| 100 | + throw new IllegalStateException("Incompatible Quartz API: " + ex); |
| 101 | + } |
90 | 102 | }
|
91 | 103 |
|
92 | 104 |
|
@@ -296,7 +308,7 @@ public void setMethodInvoker(MethodInvoker methodInvoker) {
|
296 | 308 | @Override
|
297 | 309 | protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
|
298 | 310 | try {
|
299 |
| - context.setResult(this.methodInvoker.invoke()); |
| 311 | + ReflectionUtils.invokeMethod(setResultMethod, context, this.methodInvoker.invoke()); |
300 | 312 | }
|
301 | 313 | catch (InvocationTargetException ex) {
|
302 | 314 | if (ex.getTargetException() instanceof JobExecutionException) {
|
|
0 commit comments