View Javadoc

1   /*
2    * Copyright 2005 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.ws.context;
18  
19  import java.io.IOException;
20  import java.io.InputStream;
21  
22  import org.springframework.ws.WebServiceMessage;
23  import org.springframework.ws.server.EndpointInterceptor;
24  
25  /**
26   * Context holder for message requests.
27   * <p/>
28   * Contains both the message request as well as the response. Response message are usually lazily created (but do not
29   * have to be).
30   * <p/>
31   * Also contains properties, which can be used to by {@link EndpointInterceptor interceptors} to pass information on to
32   * endpoints.
33   *
34   * @author Arjen Poutsma
35   * @since 1.0.0
36   */
37  public interface MessageContext {
38  
39      /**
40       * Returns the request message.
41       *
42       * @return the request message
43       */
44      WebServiceMessage getRequest();
45  
46      /**
47       * Indicates whether this context has a response.
48       *
49       * @return <code>true</code> if this context has a response; <code>false</code> otherwise
50       */
51      boolean hasResponse();
52  
53      /**
54       * Returns the response message. Creates a new response if no response is present.
55       *
56       * @return the response message
57       * @see #hasResponse()
58       */
59      WebServiceMessage getResponse();
60  
61      /**
62       * Sets the response message.
63       *
64       * @param response the response message
65       * @throws IllegalStateException if a response has already been created
66       * @since 1.5.0
67       */
68      void setResponse(WebServiceMessage response);
69  
70      /**
71       * Removes the response message, if any.
72       *
73       * @since 1.5.0
74       */
75      void clearResponse();
76  
77      /**
78       * Reads a response message from the given input stream.
79       *
80       * @param inputStream the stream to read the response from
81       * @throws IOException           in case of I/O errors
82       * @throws IllegalStateException if a response has already been created
83       */
84      void readResponse(InputStream inputStream) throws IOException;
85  
86      /**
87       * Sets the name and value of a property associated with the <code>MessageContext</code>. If the
88       * <code>MessageContext</code> contains a value of the same property, the old value is replaced.
89       *
90       * @param name  name of the property associated with the value
91       * @param value value of the property
92       */
93      void setProperty(String name, Object value);
94  
95      /**
96       * Gets the value of a specific property from the <code>MessageContext</code>.
97       *
98       * @param name name of the property whose value is to be retrieved
99       * @return value of the property
100      */
101     Object getProperty(String name);
102 
103     /**
104      * Removes a property from the <code>MessageContext</code>.
105      *
106      * @param name name of the property to be removed
107      */
108     void removeProperty(String name);
109 
110     /**
111      * Check if this message context contains a property with the given name.
112      *
113      * @param name the name of the property to look for
114      * @return <code>true</code> if the <code>MessageContext</code> contains the property; <code>false</code> otherwise
115      */
116     boolean containsProperty(String name);
117 
118     /**
119      * Return the names of all properties in this <code>MessageContext</code>.
120      *
121      * @return the names of all properties in this context, or an empty array if none defined
122      */
123     String[] getPropertyNames();
124 
125 }