Skip to content

Commit

Permalink
#66: Need an API to set socket timeout for URLConnection that SAAJ us…
Browse files Browse the repository at this point in the history
…es (#117)


Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
  • Loading branch information
lukasj committed Dec 10, 2021
1 parent d3d2dc5 commit 9e5803c
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions api/src/main/java/jakarta/xml/soap/SOAPConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
package jakarta.xml.soap;


import java.net.URLConnection;

/**
* A point-to-point connection that a client can use for sending messages
* directly to a remote party (represented by a URL, for instance).
Expand All @@ -35,6 +37,9 @@
*/
public abstract class SOAPConnection implements AutoCloseable {

private int readTimeout;
private int connectTimeout;

/**
* Sends the given message to the specified endpoint and blocks until
* it has returned the response.
Expand Down Expand Up @@ -70,6 +75,59 @@ public SOAPMessage get(Object to)
throw new UnsupportedOperationException("All subclasses of SOAPConnection must override get()");
}

/**
* Sets the read timeout to a specified timeout, in milliseconds.
* A timeout of zero is interpreted as an infinite timeout.
*
* @param timeout an {@code int} that specifies the timeout value to be used in milliseconds
* @throws IllegalArgumentException if the timeout parameter is negative
* @since 3.0
*/
public void setConnectTimeout(int timeout) {
if (timeout < 0) {
throw new IllegalArgumentException("timeout can not be negative");
}
connectTimeout = timeout;
}

/**
* Returns setting for connect timeout.
* {@code 0} implies infinite timeout
*
* @return an {@code int} that indicates the connect timeout value in milliseconds
* @since 3.0
*/
public int getConnectTimeout() {
return connectTimeout;
}

/**
* Sets the read timeout to a specified timeout, in milliseconds.
* A timeout of zero is interpreted as an infinite timeout.
*
* @param timeout an {@code int} that specifies the timeout value to be used in milliseconds
* @throws IllegalArgumentException if the timeout parameter is negative
* @since 3.0
*/
public void setReadTimeout(int timeout) {
if (timeout < 0) {
throw new IllegalArgumentException("timeout can not be negative");
}
readTimeout = timeout;

}

/**
* Returns setting for read timeout.
* {@code 0} implies infinite timeout
*
* @return an {@code int} that indicates the read timeout value in milliseconds
* @since 3.0
*/
public int getReadTimeout() {
return readTimeout;
}

/**
* Closes this {@code SOAPConnection} object.
*
Expand Down

0 comments on commit 9e5803c

Please sign in to comment.