|
1 | 1 | /* |
2 | | - * Copyright 2005-2011 the original author or authors. |
| 2 | + * Copyright 2005-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. |
|
29 | 29 | import org.springframework.context.ApplicationContext; |
30 | 30 | import org.springframework.context.ApplicationContextAware; |
31 | 31 | import org.springframework.core.OrderComparator; |
| 32 | +import org.springframework.util.CollectionUtils; |
32 | 33 | import org.springframework.util.ObjectUtils; |
33 | 34 | import org.springframework.web.servlet.DispatcherServlet; |
34 | 35 | import org.springframework.ws.FaultAwareWebServiceMessage; |
@@ -206,46 +207,54 @@ protected final void dispatch(MessageContext messageContext) throws Exception { |
206 | 207 | EndpointInvocationChain mappedEndpoint = null; |
207 | 208 | int interceptorIndex = -1; |
208 | 209 | try { |
209 | | - // Determine endpoint for the current context |
210 | | - mappedEndpoint = getEndpoint(messageContext); |
211 | | - if (mappedEndpoint == null || mappedEndpoint.getEndpoint() == null) { |
212 | | - throw new NoEndpointFoundException(messageContext.getRequest()); |
213 | | - } |
214 | | - if (!handleRequest(mappedEndpoint, messageContext)) { |
215 | | - return; |
216 | | - } |
217 | | - // Apply handleRequest of registered interceptors |
218 | | - if (mappedEndpoint.getInterceptors() != null) { |
219 | | - for (int i = 0; i < mappedEndpoint.getInterceptors().length; i++) { |
220 | | - EndpointInterceptor interceptor = mappedEndpoint.getInterceptors()[i]; |
221 | | - interceptorIndex = i; |
222 | | - if (!interceptor.handleRequest(messageContext, mappedEndpoint.getEndpoint())) { |
223 | | - triggerHandleResponse(mappedEndpoint, interceptorIndex, messageContext); |
224 | | - triggerAfterCompletion(mappedEndpoint, interceptorIndex, messageContext, null); |
225 | | - return; |
| 210 | + try { |
| 211 | + // Determine endpoint for the current context |
| 212 | + mappedEndpoint = getEndpoint(messageContext); |
| 213 | + if (mappedEndpoint == null || mappedEndpoint.getEndpoint() == null) { |
| 214 | + throw new NoEndpointFoundException(messageContext.getRequest()); |
| 215 | + } |
| 216 | + if (!handleRequest(mappedEndpoint, messageContext)) { |
| 217 | + return; |
| 218 | + } |
| 219 | + // Apply handleRequest of registered interceptors |
| 220 | + if (mappedEndpoint.getInterceptors() != null) { |
| 221 | + for (int i = 0; i < mappedEndpoint.getInterceptors().length; i++) { |
| 222 | + EndpointInterceptor interceptor = mappedEndpoint.getInterceptors()[i]; |
| 223 | + interceptorIndex = i; |
| 224 | + if (!interceptor.handleRequest(messageContext, mappedEndpoint.getEndpoint())) { |
| 225 | + triggerHandleResponse(mappedEndpoint, interceptorIndex, messageContext); |
| 226 | + triggerAfterCompletion(mappedEndpoint, interceptorIndex, messageContext, null); |
| 227 | + return; |
| 228 | + } |
226 | 229 | } |
227 | 230 | } |
228 | | - } |
229 | | - // Actually invoke the endpoint |
230 | | - EndpointAdapter endpointAdapter = getEndpointAdapter(mappedEndpoint.getEndpoint()); |
231 | | - endpointAdapter.invoke(messageContext, mappedEndpoint.getEndpoint()); |
| 231 | + // Actually invoke the endpoint |
| 232 | + EndpointAdapter endpointAdapter = getEndpointAdapter(mappedEndpoint.getEndpoint()); |
| 233 | + endpointAdapter.invoke(messageContext, mappedEndpoint.getEndpoint()); |
232 | 234 |
|
| 235 | + } |
| 236 | + catch (NoEndpointFoundException ex) { |
| 237 | + // No triggering of interceptors if no endpoint is found |
| 238 | + if (endpointNotFoundLogger.isWarnEnabled()) { |
| 239 | + endpointNotFoundLogger.warn("No endpoint mapping found for [" + messageContext.getRequest() + "]"); |
| 240 | + } |
| 241 | + throw ex; |
| 242 | + } |
| 243 | + catch (Exception ex) { |
| 244 | + Object endpoint = mappedEndpoint != null ? mappedEndpoint.getEndpoint() : null; |
| 245 | + processEndpointException(messageContext, endpoint, ex); |
| 246 | + } |
233 | 247 | // Apply handleResponse methods of registered interceptors |
234 | 248 | triggerHandleResponse(mappedEndpoint, interceptorIndex, messageContext); |
235 | 249 | triggerAfterCompletion(mappedEndpoint, interceptorIndex, messageContext, null); |
236 | 250 | } |
237 | 251 | catch (NoEndpointFoundException ex) { |
238 | | - // No triggering of interceptors if no endpoint is found |
239 | | - if (endpointNotFoundLogger.isWarnEnabled()) { |
240 | | - endpointNotFoundLogger.warn("No endpoint mapping found for [" + messageContext.getRequest() + "]"); |
241 | | - } |
242 | 252 | throw ex; |
243 | 253 | } |
244 | 254 | catch (Exception ex) { |
245 | | - Object endpoint = mappedEndpoint != null ? mappedEndpoint.getEndpoint() : null; |
246 | | - processEndpointException(messageContext, endpoint, ex); |
247 | | - triggerHandleResponse(mappedEndpoint, interceptorIndex, messageContext); |
| 255 | + // Trigger after-completion for thrown exception. |
248 | 256 | triggerAfterCompletion(mappedEndpoint, interceptorIndex, messageContext, ex); |
| 257 | + throw ex; |
249 | 258 | } |
250 | 259 | } |
251 | 260 |
|
@@ -316,12 +325,14 @@ protected boolean handleRequest(EndpointInvocationChain mappedEndpoint, MessageC |
316 | 325 | */ |
317 | 326 | protected void processEndpointException(MessageContext messageContext, Object endpoint, Exception ex) |
318 | 327 | throws Exception { |
319 | | - for (EndpointExceptionResolver resolver : getEndpointExceptionResolvers()) { |
320 | | - if (resolver.resolveException(messageContext, endpoint, ex)) { |
321 | | - if (logger.isDebugEnabled()) { |
322 | | - logger.debug("Endpoint invocation resulted in exception - responding with Fault", ex); |
| 328 | + if (!CollectionUtils.isEmpty(getEndpointExceptionResolvers())) { |
| 329 | + for (EndpointExceptionResolver resolver : getEndpointExceptionResolvers()) { |
| 330 | + if (resolver.resolveException(messageContext, endpoint, ex)) { |
| 331 | + if (logger.isDebugEnabled()) { |
| 332 | + logger.debug("Endpoint invocation resulted in exception - responding with Fault", ex); |
| 333 | + } |
| 334 | + return; |
323 | 335 | } |
324 | | - return; |
325 | 336 | } |
326 | 337 | } |
327 | 338 | // exception not resolved |
|
0 commit comments