INT-3933: HTTP & WS Inbound Lifecycle Handling

JIRA: https://jira.spring.io/browse/INT-3933

Previously the HTTP and WS Inbound Endpoint haven't handled the `stopped` state properly.

* Add `lifecycle` parsing to the `HttpInboundEndpointParser`
* Handle `!isRunning()` state and throw an appropriate `503 Service Unavailable` HTTP response
* Expose `lifecycle` options for the `<int-ws:inbound-gateway>`
* Introduce `ServiceUnavailableException` `WebServiceException` to indicate `stopped` state for the WS Inbound Endpoint
* Fix tests for the new logic

INT-3933: PR comments: `OrderlyShutdownCapable` for `AbstractWebServiceInboundGateway`
This commit is contained in:
Artem Bilan
2016-01-18 16:09:11 -05:00
committed by Gary Russell
parent c97afe92fe
commit c0784bf6ef
18 changed files with 216 additions and 72 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -202,6 +202,9 @@ public class HttpInboundEndpointParser extends AbstractSingleBeanDefinitionParse
if (statusCodeExpressionDef != null) {
builder.addPropertyValue("statusCodeExpression", statusCodeExpressionDef);
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.AUTO_STARTUP);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.PHASE);
}
private String getInputChannelAttributeName() {

View File

@@ -148,8 +148,6 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
private volatile Map<String, Expression> headerExpressions;
private volatile boolean shuttingDown;
private volatile Expression statusCodeExpression;
private volatile EvaluationContext evaluationContext;
@@ -397,11 +395,11 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
*/
protected final Message<?> doHandleRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
throws IOException {
if (this.isShuttingDown()) {
return createServiceUnavailableResponse();
if (isRunning()) {
return actualDoHandleRequest(servletRequest, servletResponse);
}
else {
return actualDoHandleRequest(servletRequest, servletResponse);
return createServiceUnavailableResponse();
}
}
@@ -536,9 +534,9 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
private Message<?> createServiceUnavailableResponse() {
if (logger.isDebugEnabled()) {
logger.debug("Endpoint is shutting down; returning status " + HttpStatus.SERVICE_UNAVAILABLE);
logger.debug("Endpoint is stopped; returning status " + HttpStatus.SERVICE_UNAVAILABLE);
}
return this.getMessageBuilderFactory().withPayload("Endpoint is shutting down")
return this.getMessageBuilderFactory().withPayload("Endpoint is stopped")
.setHeader(org.springframework.integration.http.HttpHeaders.STATUS_CODE, HttpStatus.SERVICE_UNAVAILABLE)
.build();
}
@@ -688,22 +686,10 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
}
}
/**
* Lifecycle
*/
@Override
protected void doStart() {
this.shuttingDown = false;
super.doStart();
}
protected boolean isShuttingDown() {
return this.shuttingDown;
}
@Override
public int beforeShutdown() {
this.shuttingDown = true;
stop();
return this.activeCount.get();
}

View File

@@ -188,7 +188,7 @@
<xsd:documentation><![CDATA[
Used to set the sendTimeout on the underlying MessagingTemplate instance
(org.springframework.integration.core.MessagingTemplate) for sending messages
to the request channel. If not specified this propery will default to "1000"
to the request channel. If not specified this property will default to "1000"
(1 second).
]]></xsd:documentation>
</xsd:annotation>
@@ -198,7 +198,7 @@
<xsd:documentation><![CDATA[
Used to set the receiveTimeout on the underlying MessagingTemplate instance
(org.springframework.integration.core.MessagingTemplate) for receiving messages
from the reply channel. If not specified this propery will default to "1000"
from the reply channel. If not specified this property will default to "1000"
(1 second).
]]></xsd:documentation>
</xsd:annotation>