*/
private void openConnection(String preamble, String postamble)
throws AuthenticationException, CommandAbortedException {
if (hostName == null) {
String locMessage = "The hostname was null, can't continue."; //NOI18N
throw new AuthenticationException("HostIsNull", locMessage); //NOI18N
}
try {
SocketFactory sf = (socketFactory != null) ? socketFactory : SocketFactory.getDefault();
socket = sf.createSocket(hostName, port);
BufferedOutputStream bos =
new BufferedOutputStream(socket.getOutputStream(), 32768);
LoggedDataOutputStream outputStream = new LoggedDataOutputStream(bos);
setOutputStream(outputStream);
BufferedInputStream bis =
new BufferedInputStream(socket.getInputStream(), 32768);
LoggedDataInputStream inputStream = new LoggedDataInputStream(bis);
setInputStream(inputStream);
outputStream.writeBytes(preamble, "US-ASCII");
outputStream.writeBytes(getRepository() + "\n"); //NOI18N
outputStream.writeBytes(userName + "\n"); //NOI18N
outputStream.writeBytes(getEncodedPasswordNotNull() + "\n", "US-ASCII"); //NOI18N
outputStream.writeBytes(postamble, "US-ASCII");
outputStream.flush();
if (Thread.interrupted()) {
reset();
String localMsg = CommandException.getLocalMessage("Client.connectionAborted", null); //NOI18N
throw new CommandAbortedException("Aborted during connecting to the server.", localMsg); // NOI18N
}
// read first 11 bytes only (AUTHENTICATION_SUCCEEDED_RESPONSE\n)
// I observed lock caused by missing '\n' in reponse
// this method then blocks forever
byte rawResponse[] = inputStream.readBytes(AUTHENTICATION_SUCCEEDED_RESPONSE_RAW.length());
String response = new String(rawResponse, "utf8"); // NOI18N
if (Thread.interrupted()) {
reset();
String localMsg = CommandException.getLocalMessage("Client.connectionAborted", null); //NOI18N
throw new CommandAbortedException("Aborted during connecting to the server.", localMsg); // NOI18N
}
if (AUTHENTICATION_SUCCEEDED_RESPONSE_RAW.equals(response)) {
return;
}
if (AUTHENTICATION_FAILED_RESPONSE_RAW.equals(response)) {
String localizedMsg = getLocalMessage("AuthenticationException.badPassword",
null);
throw new AuthenticationException("AuthenticationFailed", //NOI18N
localizedMsg);
}
if (response == null) response = ""; // NOI18N
String locMessage = getLocalMessage("AuthenticationException.AuthenticationFailed", //NOI18N
new Object[]{ response });
throw new AuthenticationException("AuthenticationFailed", //NOI18N
locMessage);
}
catch (AuthenticationException ex) {
reset();
throw ex;
}
catch (ConnectException ex) {
reset();
String locMessage =
getLocalMessage("AuthenticationException.ConnectException", //NOI18N
new Object[]{hostName, Integer.toString(port)});
throw new AuthenticationException("ConnectException", ex, //NOI18N
locMessage);
}
catch (NoRouteToHostException ex) {
reset();
String locMessage =
getLocalMessage("AuthenticationException.NoRouteToHostException", //NOI18N
new Object[]{hostName});
throw new AuthenticationException("NoRouteToHostException", ex, //NOI18N
locMessage);
}
catch (IOException ex) {
reset();
String locMessage =
getLocalMessage("AuthenticationException.IOException", //NOI18N
new Object[]{hostName});
throw new AuthenticationException("IOException", ex, locMessage); //NOI18N
}
/* catch (Throwable t) {
reset();
String locMessage = AuthenticationException.getBundleString(
"AuthenticationException.Throwable"); //NOI18N