Skip to content

Commit 997b935

Browse files
committed
SWS-164
1 parent 97b0984 commit 997b935

14 files changed

+131
-45
lines changed

core/pom.xml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
24
<parent>
35
<artifactId>spring-ws</artifactId>
46
<groupId>org.springframework.ws</groupId>
@@ -48,10 +50,6 @@
4850
</exclusion>
4951
</exclusions>
5052
</dependency>
51-
<dependency>
52-
<groupId>org.springframework</groupId>
53-
<artifactId>spring-aop</artifactId>
54-
</dependency>
5553
<dependency>
5654
<groupId>org.springframework</groupId>
5755
<artifactId>spring-mock</artifactId>

core/src/main/java/org/springframework/ws/server/endpoint/AbstractDom4jPayloadEndpoint.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@
3838
public abstract class AbstractDom4jPayloadEndpoint extends TransformerObjectSupport implements PayloadEndpoint {
3939

4040
public final Source invoke(Source request) throws Exception {
41-
DocumentResult dom4jResult = new DocumentResult();
42-
transform(request, dom4jResult);
43-
Element requestElement = dom4jResult.getDocument().getRootElement();
41+
Element requestElement = null;
42+
if (request != null) {
43+
DocumentResult dom4jResult = new DocumentResult();
44+
transform(request, dom4jResult);
45+
requestElement = dom4jResult.getDocument().getRootElement();
46+
}
4447
Document responseDocument = DocumentHelper.createDocument();
4548
Element responseElement = invokeInternal(requestElement, responseDocument);
4649
return responseElement != null ? new DocumentSource(responseElement) : null;

core/src/main/java/org/springframework/ws/server/endpoint/AbstractDomPayloadEndpoint.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@ public final Source invoke(Source request) throws Exception {
6363
documentBuilderFactory = createDocumentBuilderFactory();
6464
}
6565
DocumentBuilder documentBuilder = createDocumentBuilder(documentBuilderFactory);
66-
Document requestDocument = documentBuilder.newDocument();
67-
DOMResult domResult = new DOMResult(requestDocument);
68-
transform(request, domResult);
69-
Element requestElement = (Element) requestDocument.getFirstChild();
66+
Element requestElement = null;
67+
if (request != null) {
68+
Document requestDocument = documentBuilder.newDocument();
69+
DOMResult domResult = new DOMResult(requestDocument);
70+
transform(request, domResult);
71+
requestElement = (Element) requestDocument.getFirstChild();
72+
}
7073
Document responseDocument = documentBuilder.newDocument();
7174
Element responseElement = invokeInternal(requestElement, responseDocument);
7275
if (responseElement != null) {

core/src/main/java/org/springframework/ws/server/endpoint/AbstractJDomPayloadEndpoint.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@
3737
public abstract class AbstractJDomPayloadEndpoint extends TransformerObjectSupport implements PayloadEndpoint {
3838

3939
public final Source invoke(Source request) throws Exception {
40-
JDOMResult jdomResult = new JDOMResult();
41-
transform(request, jdomResult);
42-
Element requestElement = jdomResult.getDocument().getRootElement();
40+
Element requestElement = null;
41+
if (request != null) {
42+
JDOMResult jdomResult = new JDOMResult();
43+
transform(request, jdomResult);
44+
requestElement = jdomResult.getDocument().getRootElement();
45+
}
4346
Element responseElement = invokeInternal(requestElement);
4447
return responseElement != null ? new JDOMSource(responseElement) : null;
4548
}

core/src/main/java/org/springframework/ws/server/endpoint/AbstractSaxPayloadEndpoint.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,39 @@
3737
public abstract class AbstractSaxPayloadEndpoint extends TransformerObjectSupport implements PayloadEndpoint {
3838

3939
/**
40-
* Invokes the provided <code>ContentHandler</code> and <code>LexicalHandler</code> on the given request. After
41-
* parsing has been done, the provided response is returned.
40+
* Invokes the provided <code>ContentHandler</code> on the given request. After parsing has been done, the provided
41+
* response is returned.
4242
*
4343
* @see #createContentHandler()
4444
* @see #getResponse(org.xml.sax.ContentHandler)
4545
*/
4646
public final Source invoke(Source request) throws Exception {
47-
ContentHandler contentHandler = createContentHandler();
48-
SAXResult result = new SAXResult(contentHandler);
49-
transform(request, result);
47+
ContentHandler contentHandler = null;
48+
if (request != null) {
49+
contentHandler = createContentHandler();
50+
SAXResult result = new SAXResult(contentHandler);
51+
transform(request, result);
52+
}
5053
return getResponse(contentHandler);
5154
}
5255

5356
/**
5457
* Returns the SAX <code>ContentHandler</code> used to parse the incoming request payload. A new instance should be
5558
* created for each call, because of thread-safety. The content handler can be used to hold request-specific state.
59+
* <p/>
60+
* If an incoming message does not contain a payload, this method will not be invoked.
5661
*
5762
* @return a SAX content handler to be used for parsing
5863
*/
5964
protected abstract ContentHandler createContentHandler() throws Exception;
6065

6166
/**
62-
* Returns the response to be given, if any. This method is called after the request payload has been parse using
63-
* the SAX <code>ContentHandler</code>. The passed <code>ContentHandler</code> is created by
64-
* <code>createContentHandler</code>: it can be used to hold request-specific state.
67+
* Returns the response to be given, if any. This method is called after the request payload has been parsed using
68+
* the SAX <code>ContentHandler</code>. The passed <code>ContentHandler</code> is created by {@link
69+
* #createContentHandler()}: it can be used to hold request-specific state.
70+
* <p/>
71+
* If an incoming message does not contain a payload, this method will be invoked with <code>null</code> as content
72+
* handler.
6573
*
6674
* @param contentHandler the content handler used to parse the request
6775
*/

core/src/main/java/org/springframework/ws/server/endpoint/AbstractXomPayloadEndpoint.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,12 @@ public final Source invoke(Source request) throws Exception {
112112

113113
private Source invokeUsingReflection(Source request) throws Exception {
114114
try {
115-
Result xomResult = createXomResult();
116-
transform(request, xomResult);
117-
Element requestElement = getRequestElement(xomResult);
118-
115+
Element requestElement = null;
116+
if (request != null) {
117+
Result xomResult = createXomResult();
118+
transform(request, xomResult);
119+
requestElement = getRequestElement(xomResult);
120+
}
119121
Element responseElement = invokeInternal(requestElement);
120122
return responseElement != null ? createXomSource(responseElement) : null;
121123
}
@@ -134,20 +136,21 @@ private Source invokeUsingReflection(Source request) throws Exception {
134136
}
135137

136138
private Source invokeUsingTransformation(Source request) throws Exception {
137-
logger.debug("Using transformations");
138139
Element requestElement = null;
139-
if (request instanceof DOMSource) {
140-
requestElement = handleDomSource(request);
141-
}
142-
else if (request instanceof SAXSource) {
143-
requestElement = handleSaxSource(request);
144-
}
145-
else if (request instanceof StreamSource) {
146-
requestElement = handleStreamSource(request);
147-
}
148-
else {
149-
throw new IllegalArgumentException(
150-
"Source [" + request.getClass().getName() + "] is neither SAXSource, DOMSource, nor StreamSource");
140+
if (request != null) {
141+
if (request instanceof DOMSource) {
142+
requestElement = handleDomSource(request);
143+
}
144+
else if (request instanceof SAXSource) {
145+
requestElement = handleSaxSource(request);
146+
}
147+
else if (request instanceof StreamSource) {
148+
requestElement = handleStreamSource(request);
149+
}
150+
else {
151+
throw new IllegalArgumentException("Source [" + request.getClass().getName() +
152+
"] is neither SAXSource, DOMSource, nor StreamSource");
153+
}
151154
}
152155
Element responseElement = invokeInternal(requestElement);
153156
if (responseElement != null) {

core/src/main/java/org/springframework/ws/server/endpoint/PayloadEndpoint.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@
2020

2121
/**
2222
* Defines the basic contract for Web Services interested in just the message payload.
23-
*
24-
* <p>The main entrypoint is {@link #invoke(Source)}, which gets invoked with the contents of the requesting message.
23+
* <p/>
24+
* The main entrypoint is {@link #invoke(Source)}, which gets invoked with the contents of the requesting message.
2525
*
2626
* @author Arjen Poutsma
2727
*/
2828
public interface PayloadEndpoint {
2929

3030
/**
31-
* Invokes an operation.
31+
* Invokes the endpoint with the given request payload, and possibly returns a response.
3232
*
33-
* @param request the request message
34-
* @return the response message, may be <code>null</code>
33+
* @param request the payload of the request message, may be <code>null</code>
34+
* @return the payload of the response message, may be <code>null</code> to indicate no response
3535
* @throws Exception if an exception occurs
3636
*/
3737
Source invoke(Source request) throws Exception;

core/src/test/java/org/springframework/ws/server/endpoint/AbstractPayloadEndpointTestCase.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ public void testNoResponse() throws Exception {
4141
assertNull("Response source returned", resultSource);
4242
}
4343

44+
public void testNoRequest() throws Exception {
45+
endpoint = createNoRequestEndpoint();
46+
Source resultSource = endpoint.invoke(null);
47+
assertNull("Response source returned", resultSource);
48+
}
49+
4450
protected final void testSource(Source requestSource) throws Exception {
4551
Source responseSource = endpoint.invoke(requestSource);
4652
assertNotNull("No response source returned", responseSource);
@@ -52,4 +58,6 @@ protected final void testSource(Source requestSource) throws Exception {
5258
protected abstract PayloadEndpoint createNoResponseEndpoint() throws Exception;
5359

5460
protected abstract PayloadEndpoint createResponseEndpoint() throws Exception;
61+
62+
protected abstract PayloadEndpoint createNoRequestEndpoint() throws Exception;
5563
}

core/src/test/java/org/springframework/ws/server/endpoint/Dom4jPayloadEndpointTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,15 @@ protected Element invokeInternal(Element requestElement, Document responseDocume
4343
};
4444
}
4545

46+
protected PayloadEndpoint createNoRequestEndpoint() throws Exception {
47+
return new AbstractDom4jPayloadEndpoint() {
48+
49+
protected Element invokeInternal(Element requestElement, Document responseDocument) throws Exception {
50+
assertNull("RequestElement passed", requestElement);
51+
return null;
52+
}
53+
};
54+
}
55+
4656

4757
}

core/src/test/java/org/springframework/ws/server/endpoint/DomPayloadEndpointTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,13 @@ protected Element invokeInternal(Element requestElement, Document responseDocume
4343
};
4444
}
4545

46+
protected PayloadEndpoint createNoRequestEndpoint() throws Exception {
47+
return new AbstractDomPayloadEndpoint() {
4648

49+
protected Element invokeInternal(Element requestElement, Document responseDocument) throws Exception {
50+
assertNull("RequestElement passed", requestElement);
51+
return null;
52+
}
53+
};
54+
}
4755
}

0 commit comments

Comments
 (0)