Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem ist not spring. I think you will need a queue with elements containing the request and offering a response. But the response need to block until the element is dequed and processed. So the queue element looks like:</p> <pre><code>public class BlockingPair { private final RequestBodyType request; private ResponseBodyType response; public BlockingPair(RequestBodyType request) { this.request = request; } public RequestBodyType getRequest() { return request; } public ResponseBodyType getResponse() { while (response == null) { Thread.currentThread().sleep(10); } return response; } public void setResponse(ResponseBodyType response) { this.response = response; } } </code></pre> <p>The webservice enqueing creates the BlockingPair with its request body. Than pushes the BlockingPair element to the queue. Afterwards it creates the response getting the response body from the BlockingPair, but blocks.</p> <p>The consumer deques one BlockingPair and sets the response body. From there the webservice continues writing the response.</p> <p>You need three beans: webservice, a blocking queue and the consumer. Both webservice and consumer need the queue as bean property.</p> <p>The queue and the consumer beans need to be planed in the application context (as initilialized by the <code>ContextLoaderListener</code>). The queue needs a bean id to be references by the webservice (which has its own context, but the application context as a parent so the queue reference can be referenced):</p> <p>Part of the <code>web.xml</code>:</p> <pre><code>&lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;classpath:/WEB-INF/applicationContext.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;servlet&gt; &lt;servlet-name&gt;service&lt;/servlet-name&gt; &lt;servlet-class&gt;org.springframework.ws.transport.http.MessageDispatcherServlet&lt;/servlet-class&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;service&lt;/servlet-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre> <p>The <code>applicationContext.xml</code> contains two beans:</p> <pre><code>&lt;bean id="queue" class="java.util.concurrent.LinkedBlockingQueue"/&gt; &lt;bean id="consumer" class="..."&gt; &lt;property name="queue" ref="queue"/&gt; &lt;/bean&gt; </code></pre> <p>The webservice has its own context definition, here <code>service-servlet.xml</code>:</p> <pre><code>&lt;bean id="endpoint" class="org.springframework.ws.server.endpoint....PayloadEndpoint"&gt; &lt;property name="queue" ref="queue"/&gt; &lt;/bean&gt; </code></pre> <p>For more information on defining a spring ws endpoint, see the <a href="http://static.springsource.org/spring-ws/sites/1.5/reference/html/tutorial.html" rel="nofollow noreferrer">spring tutorial</a>.</p> <p>The consumer need to be a background task, so i would prefer <a href="http://www.quartz-scheduler.org/" rel="nofollow noreferrer">quartz</a>, for spring integration see <a href="http://static.springframework.org/spring/docs/2.5.x/reference/scheduling.html" rel="nofollow noreferrer">here</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload