1/* Copyright (c) 2003,2004, Stefan Haustein, Oberhausen, Rhld., Germany
2 * Copyright (c) 2006, James Seigel, Calgary, AB., Canada
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 * sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The  above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 * IN THE SOFTWARE. */
21
22package org.ksoap2.transport;
23
24import java.util.List;
25import java.io.*;
26
27/**
28 * Interface to allow the abstraction of the raw transport information
29 */
30public interface ServiceConnection {
31
32    public static final int DEFAULT_TIMEOUT = 20000; // 20 seconds
33    public static final int DEFAULT_BUFFER_SIZE = 256 * 1024; // 256 Kb
34
35    /**
36     * Make an outgoing connection.
37     *
38     * @exception IOException
39     */
40    public void connect() throws IOException;
41
42    /**
43     * Disconnect from the outgoing connection
44     *
45     * @exception IOException
46     */
47    public void disconnect() throws IOException;
48
49    /**
50     * Returns to the caller all of the headers that were returned with the
51     * response to the SOAP request. Primarily this gives the caller an
52     * opportunity to save the cookies for later use.
53     *
54     * @return List of HeaderProperty instances that were returned as part of the http response as http header
55     * properties
56     *
57     * @exception IOException
58     */
59    public List getResponseProperties() throws IOException;
60
61    /**
62     * Set properties on the outgoing connection.
63     *
64     * @param propertyName
65     *            the name of the property to set. For HTTP connections these
66     *            are the request properties in the HTTP Header.
67     * @param value
68     *            the string to set the property header to.
69     * @exception IOException
70     */
71    public void setRequestProperty(String propertyName, String value) throws IOException;
72
73    /**
74     * Sets how to make the requests. For HTTP this is typically POST or GET.
75     *
76     * @param requestMethodType
77     *            the type of request method to make the soap call with.
78     * @exception IOException
79     */
80    public void setRequestMethod(String requestMethodType) throws IOException;
81
82    /**
83     * If the length of a HTTP request body is known ahead, sets fixed length
84     * to enable streaming without buffering. Sets after connection will cause an exception.
85     *
86     * @param contentLength the fixed length of the HTTP request body
87     * @see http://developer.android.com/reference/java/net/HttpURLConnection.html
88     **/
89    public void setFixedLengthStreamingMode(int contentLength);
90
91    /**
92     * Open and return the outputStream to the endpoint.
93     *
94     * @exception IOException
95     * @return the output stream to write the soap message to.
96     */
97    public OutputStream openOutputStream() throws IOException;
98
99    /**
100     * Opens and returns the inputstream from which to parse the result of the
101     * soap call.
102     *
103     * @exception IOException
104     * @return the inputstream containing the xml to parse the result from the
105     *         call from.
106     */
107    public InputStream openInputStream() throws IOException;
108
109    /**
110     * @return the error stream for the call.
111     */
112    public InputStream getErrorStream();
113
114    /**
115     * Return the name of the host that is specified as the web service target
116     *
117     * @return Host name
118     */
119    abstract public String getHost();
120
121    /**
122     * Return the port number of the host that is specified as the web service target
123     *
124     * @return Port number
125     */
126    abstract public int getPort();
127
128    /**
129     * Return the path to the web service target
130     *
131     * @return The URL's path
132     */
133    abstract public String getPath();
134}
135