View Javadoc

1   /*
2    * Copyright 2007 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.transport;
18  
19  import java.io.IOException;
20  import java.net.URI;
21  import java.net.URISyntaxException;
22  
23  import org.springframework.ws.WebServiceMessage;
24  import org.springframework.ws.WebServiceMessageFactory;
25  
26  /**
27   * Represents a point-to-point connection that a client can use for sending {@link WebServiceMessage} objects directly
28   * to a remote party.
29   * <p/>
30   * A <code>WebServiceConnection</code> can be obtained using a {@link WebServiceMessageSender}.
31   *
32   * @author Arjen Poutsma
33   * @see WebServiceMessageSender#createConnection(URI)
34   * @since 1.0.0
35   */
36  public interface WebServiceConnection {
37  
38      /**
39       * Sends the given message using this connection.
40       *
41       * @param message the message to be sent
42       * @throws IOException in case of I/O errors
43       */
44      void send(WebServiceMessage message) throws IOException;
45  
46      /**
47       * Receives a message using the given {@link WebServiceMessageFactory}. This method blocks until it receives, or
48       * returns <code>null</code> when no message is received.
49       *
50       * @param messageFactory the message factory used for reading messages
51       * @return the read message, or <code>null</code> if no message received
52       * @throws IOException in case of I/O errors
53       */
54      WebServiceMessage receive(WebServiceMessageFactory messageFactory) throws IOException;
55  
56      /** Returns the URI for this connection. */
57      URI getUri() throws URISyntaxException;
58  
59      /**
60       * Indicates whether this connection has an error. Typically, error detection is done by inspecting connection error
61       * codes, etc.
62       *
63       * @return <code>true</code> if this connection has an error; <code>false</code> otherwise.
64       */
65      boolean hasError() throws IOException;
66  
67      /**
68       * Returns the error message.
69       *
70       * @return the connection error message, if any; returns <code>null</code> when no error is present
71       * @see #hasError()
72       */
73      String getErrorMessage() throws IOException;
74  
75      /**
76       * Closes this connection.
77       * <p/>
78       * Once a connection has been closed, it is not available for further use. A new connection needs to be created.
79       *
80       * @throws IOException if an I/O error occurs when closing this connection
81       */
82      void close() throws IOException;
83  
84  }