You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by Jason Harrop <jh...@bigpond.net.au> on 2001/01/13 13:29:40 UTC
WebdavClient.startSession and openConnection()
Hi
I have a servlet that tries to set up a session in the usual way:
client = new WebdavClient();
client.startSession(h, p);
If I put this in the the servlet's init() method, it sometimes fails, with:
Start session : Host:127.0.0.1 Port:80
Unable to connect to remote host: Connection refused
(because Tomcat/Slide not yet ready to accept connections)
When it fails, later calls to client.executeMethod attempt to re-open
the connection. These fail:
Reopen connection : Host: Port:-1
Error processing a command: java.lang.IllegalArgumentException: port out
range:-1
This would not happen, if
public void startSession(String host, int port)
throws UnknownHostException, IOException {
if (debug > 0)
System.out.println("Start session : Host:" + host
+ " Port:" + port);
state = new State();
socket = new Socket(host, port);
this.sessionHost = host;
this.sessionPort = port;
}
read instead:
public void startSession(String host, int port)
throws UnknownHostException, IOException {
if (debug > 0)
System.out.println("Start session : Host:" + host
+ " Port:" + port);
state = new State();
this.sessionHost = host;
this.sessionPort = port;
socket = new Socket(host, port);
}
cheers,
Jason
Re: WebdavClient.startSession and openConnection()
Posted by "Park, Sung-Gu" <je...@thinkfree.com>.
For easy,
/**
* WebdavClient constructor.
*/
public WebdavClient() {
startSession();
}
/**
* WebdavClient constructor.
*/
public WebdavClient(URL url) {
startSession(url.getHost(),
url.getPort() == -1 ? 80 : url.getPort());
}
/**
* WebdavClient constructor.
*/
public WebdavClient(URL url, String user, String password) {
startSession(url.getHost(),
url.getPort() == -1 ? 80 : url.getPort());
setCredentials(new Credentials(user, password));
}
/**
* Get the session host
*/
public String getHost() {
return sessionHost;
}
/**
* Get the session port
*/
public int getPort() {
return sessionPort;
}
/**
* Get the state for lock information
*/
public State getState() {
return state;
}
/**
* Set the state for lock information
*/
public void setState(State state) {
this.state = state;
}
=======================================
For correction with throws Exception and using WebdavException
/**
* Start a session.
*/
public void startSession() {
state = new State();
this.sessionHost = "localhost";
this.sessionPort = 80;
}
/**
* Start a session.
*/
public void startSession(String host, int port) {
if (debug > 0)
System.out.println("Start session : Host:" + host
+ " Port:" + port);
state = new State();
this.sessionHost = host;
this.sessionPort = port;
}
protected void openConnection() throws WebdavException {
try {
if (socket == null) {
if (debug > 0)
System.out.println("Reopen connection : Host:" +
sessionHost
+ " Port:" + sessionPort);
socket = new Socket(this.sessionHost, this.sessionPort);
}
input = socket.getInputStream();
output = socket.getOutputStream();
} catch (UnknownHostException uhe) {
throw new WebdavException
("Unable to connect to remote host: Unknown Host");
} catch (IllegalArgumentException iae) {
throw new WebdavException
("Unable to connect to remote host: Out of port");
} catch (ConnectException ce) {
throw new WebdavException
("Unable to connect to remote host: Connection refused");
} catch (IOException e) {
// Connection is probably half closed
// Closing the connection and trying again
try {
socket.close();
socket = new Socket(this.sessionHost, this.sessionPort);
input = socket.getInputStream();
output = socket.getOutputStream();
} catch (Exception ignored) {
}
} catch (Exception e) {
}
}
==> It's easy to make a coding for WebdavClient().
The client code is needed to handle WebdavException...
----- Original Message -----
From: "Jason Harrop" <jh...@bigpond.net.au>
To: <sl...@jakarta.apache.org>
Sent: Saturday, January 13, 2001 9:29 PM
Subject: WebdavClient.startSession and openConnection()
| Hi
|
| I have a servlet that tries to set up a session in the usual way:
|
| client = new WebdavClient();
| client.startSession(h, p);
|
| If I put this in the the servlet's init() method, it sometimes fails,
with:
|
| Start session : Host:127.0.0.1 Port:80
| Unable to connect to remote host: Connection refused
|
| (because Tomcat/Slide not yet ready to accept connections)
|
| When it fails, later calls to client.executeMethod attempt to re-open
| the connection. These fail:
|
| Reopen connection : Host: Port:-1
| Error processing a command: java.lang.IllegalArgumentException: port out
| range:-1
|
| This would not happen, if
|
| public void startSession(String host, int port)
| throws UnknownHostException, IOException {
|
| if (debug > 0)
| System.out.println("Start session : Host:" + host
| + " Port:" + port);
|
| state = new State();
| socket = new Socket(host, port);
| this.sessionHost = host;
| this.sessionPort = port;
|
| }
|
| read instead:
|
| public void startSession(String host, int port)
| throws UnknownHostException, IOException {
|
| if (debug > 0)
| System.out.println("Start session : Host:" + host
| + " Port:" + port);
|
| state = new State();
| this.sessionHost = host;
| this.sessionPort = port;
| socket = new Socket(host, port);
|
| }
|
| cheers,
|
| Jason
|