Hi I was wondering if someone could help with this problem.
Basically I have written this lava program to communicate with an apache
server. Everything works fine with the program, it it does not work
exactly in the way I would like it to. What I would like it to send a
request to PUT a file up onto the server and then get response back from
the server saying that the username password entered is correct, and the
(and only then) should the file upload start. My problem is that at the
moment whether the username/password is right or wrong the file upload
happens and if the credentials are wrong it get discarded. Now this
isn't a problem with small files but this application will be dealing
with files 100s of MB large so it will cause unneeded delay and file
uploading if I can't change.
Here is the main part of the program
--8<--
public void doPut(String server, int port, String fileName, String
username, String password) {
HttpClient client;
Credentials defaultcreds;
ArrayList authPrefs;
PutMethod put = null;;
Header[] he;
try {
client = new HttpClient();
authPrefs = new ArrayList(2);
authPrefs.add(AuthPolicy.BASIC);
authPrefs.add(AuthPolicy.DIGEST);
client.getState().setCredentials(new AuthScope(server, port,
AuthScope.ANY_REALM), new UsernamePasswordCredentials(username, password));
client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY,
authPrefs);
client.getParams().setAuthenticationPreemptive(true);
put = !server.endsWith("/") ? new PutMethod(server + "/" + fileName)
: new PutMethod(server + fileName);
put.setDoAuthentication(true);
put.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE,true);
put.setRequestEntity(new FileRequestEntity(new
File(fileName)));
put.addRequestHeader(new Header("Authorization",new
BasicScheme().authenticate(new UsernamePasswordCredentials(username,
password), put)));
System.out.println("FIRST: " + client.executeMethod(put) + " " +
put.getStatusLine());
System.out.println("=====================================================");
System.out.println("Request");
he = put.getRequestHeaders();
for (int i = 0; i < he.length; i++) {
System.out.print(he[i]);
}
System.out.println("=====================================================");
System.out.println("=====================================================");
System.out.println("Response");
he = put.getResponseHeaders();
for (int i = 0; i < he.length; i++) {
System.out.print(he[i]);
}
System.out.println("=====================================================");
System.out.println("\n\nSECOND: " + client.executeMethod(put) + " " +
put.getStatusLine());
System.out.println("=====================================================");
System.out.println("Request");
he = put.getRequestHeaders();
for (int i = 0; i < he.length; i++) {
System.out.print(he[i]);
}
System.out.println("=====================================================");
System.out.println("=====================================================");
System.out.println("Response");
he = put.getResponseHeaders();
for (int i = 0; i < he.length; i++) {
System.out.print(he[i]);
}
System.out.println("=====================================================");
} catch(HttpException e) {
System.out.println("Error " + e);
e.printStackTrace();
} catch(IOException e) {
System.out.println("Error " + e);
e.printStackTrace();
} finally {
if (put != null) {
put.releaseConnection();
}
}
}
--8<--
Thanks for any help given in advanced.
Philip Maciver
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]