I am trying to upload documents to SharePoint using Copy.copyIntoItems web service. Please find my code below.
String userName = "*******";
String password = "********";
Copy service = new Copy();
port = service.getCopySoap();
BindingProvider bp = (BindingProvider) port;
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName);
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
String destURL = "http://sharepoint.com/Shared Documents/test.txt";
DestinationUrlCollection destUrlCollection = new DestinationUrlCollection();
destUrlCollection.getString().add(destURL);
Holder<Long> longHolder = new Holder<Long>(new Long(-1));
CopyResultCollection results = new CopyResultCollection ();
Holder<CopyResultCollection> resultHolder = new Holder<CopyResultCollection>(results);
File file = new File("C:\\test.txt");
int size = (int) file.length();
byte[] content = new byte[size];
DataInputStream dis = new DataInputStream(new FileInputStream(file));
int read = 0;
int numRead = 0;
while (read < content.length && (numRead = dis.read(content, read,
content.length - read)) >= 0) {
read = read + numRead;
}
FieldInformationCollection fieldInformationCollection = new FieldInformationCollection() ;
port.copyIntoItems(file.getName(), destUrlCollection,fieldInformationCollection, content,longHolder, resultHolder);
Code works fine on the site that allows anonymous access. But fails on the site that doesn't allow anonymous access. I also tried setting the Authenticator.setDefault. But no use. Problem is, I don't get any error messages on the screen. But the document is not getting loaded to sharepoint.
Any help will be appreciated.
Got my problem. problme is: eventhough i have provided credentials in my java program, the program is taking the credentials with which I am logged into my computer, which makes the program to fail. Any idea as how to fix this issue?