1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.context;
18
19 import java.io.IOException;
20 import java.io.InputStream;
21
22 import org.springframework.util.Assert;
23 import org.springframework.ws.WebServiceMessage;
24 import org.springframework.ws.WebServiceMessageFactory;
25
26
27
28
29
30
31
32 public class DefaultMessageContext extends AbstractMessageContext {
33
34 private final WebServiceMessageFactory messageFactory;
35
36 private final WebServiceMessage request;
37
38 private WebServiceMessage response;
39
40
41 public DefaultMessageContext(WebServiceMessageFactory messageFactory) {
42 this(messageFactory.createWebServiceMessage(), messageFactory);
43 }
44
45
46
47
48
49 public DefaultMessageContext(WebServiceMessage request, WebServiceMessageFactory messageFactory) {
50 Assert.notNull(request, "request must not be null");
51 Assert.notNull(messageFactory, "messageFactory must not be null");
52 this.request = request;
53 this.messageFactory = messageFactory;
54 }
55
56 public WebServiceMessage getRequest() {
57 return request;
58 }
59
60 public boolean hasResponse() {
61 return response != null;
62 }
63
64 public WebServiceMessage getResponse() {
65 if (response == null) {
66 response = messageFactory.createWebServiceMessage();
67 }
68 return response;
69 }
70
71 public void setResponse(WebServiceMessage response) {
72 checkForResponse();
73 this.response = response;
74 }
75
76 public void clearResponse() {
77 response = null;
78 }
79
80 public void readResponse(InputStream inputStream) throws IOException {
81 checkForResponse();
82 response = messageFactory.createWebServiceMessage(inputStream);
83 }
84
85 public WebServiceMessageFactory getMessageFactory() {
86 return messageFactory;
87 }
88
89 private void checkForResponse() throws IllegalStateException {
90 if (response != null) {
91 throw new IllegalStateException("Response message already created");
92 }
93 }
94 }