chetan kalegowda commented on Mar 26, 2013

Re: Adding a file

Hi I am new to Lotus connection. I Have requirement to perform antivirus scan on file uploaded in our project.

We want to upload file to IBM Lotus connection server using apache abdera API. I am able to hit the lotus connection server set for our application.

I am also able to get nonce key from our lotus server but I am not able to upload File to the server.

I have tried different overloaded Post method of AbdearClient but all methods give same http code 302 ans status text is coming as found.

The code I am using is as below.

FileInputStream fis = new File("H:\\Sample.pdf");

//credential

UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(

"username", "pwd");

String auth = BasicScheme.authenticate(credentials, "UTF-8");

Abdera abdera = new Abdera();

AbderaClient client = new AbderaClient(abdera);

try {

client.addCredentials(SERVER_URI, "", "", credentials);

} catch (URISyntaxException e) {

e.printStackTrace();

}

RequestOptions requestOptions = client.getDefaultRequestOptions();

requestOptions.setAuthorization(auth);

ClientResponse response = null;

//nonce key

response = client.get(SERVER_URI+"basic/api/nonce",requestOptions);

String nonce = response.getDecodedHeader("X-Update-Nonce");

RequestEntity reqEnt = new InputStreamRequestEntity(fis, "application/pdf");

requestOptions.setContentType("application/pdf");

requestOptions.setSlug(uploadFile.getName());

requestOptions.setHeader("X-HTTP-Method-Override", "POST");

requestOptions.setHeader("X-Update-Nonce", nonce);

requestOptions.setFollowRedirects(true);

response = client.post(SERVER_URI++"basic/api/myuserlibrary/feed",reqEnt,requestOptions);

In the above code. get method returns success status as 200 and I get nonce key. But Post method is returning status as 302 and file is

not uploaded on server. Can any tell me if am missing something or is another way of uploading file to lotus connection using apache abdera?

Please help me.