Skip to content

ClientInterceptor#afterCompletion can be called twice [SWS-983] #1054

Closed
@gregturn

Description

@gregturn

Sergey Trofimov opened SWS-983 and commented

Relevant code section in WebServiceTemplate.java

	protected Object handleError(WebServiceConnection connection, WebServiceMessage request) throws IOException {
		if (logger.isDebugEnabled()) {
			logger.debug("Received error for request [" + request + "]");
		}
		throw new WebServiceTransportException(connection.getErrorMessage());
	}

	protected <T> T doSendAndReceive(/* ... */) throws IOException {
		try {
      // ...

			if (!messageContext.hasResponse() && !intercepted) {
				sendRequest(connection, messageContext.getRequest());
				if (hasError(connection, messageContext.getRequest())) {
					triggerAfterCompletion(interceptorIndex, messageContext, null);
					return (T) handleError(connection, messageContext.getRequest());
				}
				WebServiceMessage response = connection.receive(getMessageFactory());
				messageContext.setResponse(response);
			}

      // ...
		}
		catch (TransformerException ex) {
			triggerAfterCompletion(interceptorIndex, messageContext, ex);
			throw new WebServiceTransformerException("Transformation error: " + ex.getMessage(), ex);
		}
		catch (RuntimeException ex) {
			// Trigger after-completion for thrown exception.
			triggerAfterCompletion(interceptorIndex, messageContext, ex);
			throw ex;
		}
		catch (IOException ex) {
			// Trigger after-completion for thrown exception.
			triggerAfterCompletion(interceptorIndex, messageContext, ex);
			throw ex;
		}
	}

If after sendRequest(), hasError returns true then triggerAfterCompletion is fired and then handleError() is called which throws WebServiceTransportException.
Latter exception is catched by catch (RuntimeException ex) block and then triggerAfterCompletion is called second time.

I got into this situation when target WebService was returning 404 error.

I have looked into the latest source code and seems that the bug remains.


Affects: 2.3.1

4 votes, 6 watchers

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions