1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.ksb.messaging.exceptionhandling; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.apache.log4j.Logger; |
20 | |
import org.kuali.rice.ksb.messaging.AsynchronousCall; |
21 | |
import org.kuali.rice.ksb.messaging.PersistedMessage; |
22 | |
import org.kuali.rice.ksb.messaging.RemoteResourceServiceLocator; |
23 | |
import org.kuali.rice.ksb.messaging.quartz.MessageServiceExecutorJob; |
24 | |
import org.kuali.rice.ksb.messaging.quartz.MessageServiceExecutorJobListener; |
25 | |
import org.kuali.rice.ksb.messaging.resourceloader.KSBResourceLoaderFactory; |
26 | |
import org.kuali.rice.ksb.service.KSBServiceLocator; |
27 | |
import org.quartz.JobDataMap; |
28 | |
import org.quartz.JobDetail; |
29 | |
import org.quartz.Scheduler; |
30 | |
import org.quartz.SimpleTrigger; |
31 | |
import org.quartz.Trigger; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 0 | public class DefaultExceptionServiceImpl implements ExceptionRoutingService { |
43 | |
|
44 | 0 | private static final Logger LOG = Logger.getLogger(DefaultExceptionServiceImpl.class); |
45 | |
|
46 | |
public void placeInExceptionRouting(Throwable throwable, PersistedMessage message, Object service) throws Exception { |
47 | 0 | LOG.error("Exception caught processing message " + message.getRouteQueueId() + " " + message.getServiceName() + ": " + throwable); |
48 | |
|
49 | 0 | RemoteResourceServiceLocator remoteResourceServiceLocator = KSBResourceLoaderFactory.getRemoteResourceLocator(); |
50 | 0 | AsynchronousCall methodCall = null; |
51 | 0 | if (message.getMethodCall() != null) { |
52 | 0 | methodCall = message.getMethodCall(); |
53 | |
} else { |
54 | 0 | methodCall = message.getPayload().getMethodCall(); |
55 | |
} |
56 | 0 | message.setMethodCall(methodCall); |
57 | 0 | MessageExceptionHandler exceptionHandler = remoteResourceServiceLocator.getMessageExceptionHandler(methodCall.getServiceInfo().getQname()); |
58 | 0 | exceptionHandler.handleException(throwable, message, service); |
59 | 0 | } |
60 | |
|
61 | |
public void placeInExceptionRoutingLastDitchEffort(Throwable throwable, PersistedMessage message, Object service) throws Exception { |
62 | 0 | LOG.error("Exception caught processing message " + message.getRouteQueueId() + " " + message.getServiceName() + ": " + throwable); |
63 | |
|
64 | 0 | RemoteResourceServiceLocator remoteResourceServiceLocator = KSBResourceLoaderFactory.getRemoteResourceLocator(); |
65 | 0 | AsynchronousCall methodCall = null; |
66 | 0 | if (message.getMethodCall() != null) { |
67 | 0 | methodCall = message.getMethodCall(); |
68 | |
} else { |
69 | 0 | methodCall = message.getPayload().getMethodCall(); |
70 | |
} |
71 | 0 | message.setMethodCall(methodCall); |
72 | 0 | MessageExceptionHandler exceptionHandler = remoteResourceServiceLocator.getMessageExceptionHandler(methodCall.getServiceInfo().getQname()); |
73 | 0 | exceptionHandler.handleExceptionLastDitchEffort(throwable, message, service); |
74 | 0 | } |
75 | |
|
76 | |
|
77 | |
|
78 | |
public void scheduleExecution(Throwable throwable, PersistedMessage message, String description) throws Exception { |
79 | 0 | KSBServiceLocator.getRouteQueueService().delete(message); |
80 | 0 | Scheduler scheduler = KSBServiceLocator.getScheduler(); |
81 | 0 | JobDataMap jobData = new JobDataMap(); |
82 | 0 | jobData.put(MessageServiceExecutorJob.MESSAGE_KEY, message); |
83 | 0 | JobDetail jobDetail = new JobDetail("Exception_Message_Job " + Math.random(), "Exception Messaging", |
84 | |
MessageServiceExecutorJob.class); |
85 | 0 | jobDetail.setJobDataMap(jobData); |
86 | 0 | if (!StringUtils.isBlank(description)) { |
87 | 0 | jobDetail.setDescription(description); |
88 | |
} |
89 | 0 | jobDetail.addJobListener(MessageServiceExecutorJobListener.NAME); |
90 | 0 | Trigger trigger = new SimpleTrigger("Exception_Message_Trigger " + Math.random(), "Exception Messaging", message |
91 | |
.getQueueDate()); |
92 | 0 | trigger.setJobDataMap(jobData); |
93 | 0 | scheduler.scheduleJob(jobDetail, trigger); |
94 | 0 | } |
95 | |
|
96 | |
} |