我想在共享点在线生成一个文件,我使用此代码,但是我仍然有一个例外java.net.ConnectException: Connection timed out: connect
有什么想法吗?
public static CopySoap getPort(String username, String password) {
Copy service = new Copy();
CopySoap port = service.getCopySoap();
BindingProvider bp = (BindingProvider) port;
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"https://mysite/sites/_vti_bin/Copy.asmx");
return port;
}
答案 0 :(得分:0)
public static void createDocument(CopySoap port) throws Exception {
String url = "https://mysite/sites/Documents partages/test.txt";
String sourceUrl = "C:\\TEMP\\test.txt";
File file=new File(sourceUrl);
DestinationUrlCollection urls = new DestinationUrlCollection();
urls.getString().add(url);
byte[] content = readAll(file);
FieldInformation titleInfo = new FieldInformation ();
titleInfo.setDisplayName("Title");
titleInfo.setType(FieldType.TEXT);
titleInfo.setValue("Test Doc");
FieldInformationCollection infos = new FieldInformationCollection ();
infos.getFieldInformation().add(titleInfo);
CopyResultCollection results = new CopyResultCollection ();
Holder<CopyResultCollection> resultHolder = new Holder<CopyResultCollection>(results);
Holder<Long> longHolder = new Holder<Long>(new Long(-1));
port.copyIntoItems(sourceUrl, urls, infos, content, longHolder, resultHolder);
logger.debug("Long holder: " + longHolder.value);
//do something meaningful here
for (CopyResult copyResult : resultHolder.value.getCopyResult()) {
logger.debug("Destination: " + copyResult.getDestinationUrl());
logger.debug("Error Message: " + copyResult.getErrorMessage());
logger.debug("Error Code: " + copyResult.getErrorCode());
if(copyResult.getErrorCode() != CopyErrorCode.SUCCESS)
throw new Exception("Upload failed for: " + copyResult.getDestinationUrl() + " Message: "
+ copyResult.getErrorMessage() + " Code: " + copyResult.getErrorCode() );
}