根据官方提供的java sdk创建bucket时报错,初学者,大虾们给看看
1、创建bucket代码
String accessKeyId = "申请的keyid";
String accessKeySecret = "申请的keysecret";
// 初始化一个 OSSClient
OSSClient client = new OSSClient(accessKeyId, accessKeySecret);
String filePath="f:\\osstest\\aa.zip";
// 获取指定文件的输入流
File file = new File(filePath);
InputStream content;
try {
content = new FileInputStream(file);
// 创建上传 Object 的 Metadata
ObjectMetadata meta = new ObjectMetadata();
// 必须设置 ContentLength
meta.setContentLength(file.length());
//创建bucket
client.createBucket("zhangsan");
// 上传 Object.
PutObjectResult result = client.putObject("zhangsan", "photo1.zip", content, meta);
// 打印 ETag
System.out.println(result.getETag());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
2、报错如下
Exception in thread "main" com.aliyun.oss.ClientException: 服务器返回未知错误。
[RequestId]:547EA954EFB62C017688F820
at com.aliyun.oss.internal.OSSExceptionFactory.createInvalidResponseException(OSSExceptionFactory.java:34)
at com.aliyun.oss.internal.OSSErrorResponseHandler.handle(OSSErrorResponseHandler.java:49)
at com.aliyun.oss.common.comm.ServiceClient.handleResponse(ServiceClient.java:289)
at com.aliyun.oss.common.comm.ServiceClient.sendRequestImpl(ServiceClient.java:175)
at com.aliyun.oss.common.comm.ServiceClient.sendRequest(ServiceClient.java:134)
at com.aliyun.oss.internal.OSSOperation.send(OSSOperation.java:68)
at com.aliyun.oss.internal.OSSOperation.send(OSSOperation.java:62)
at com.aliyun.oss.internal.OSSBucketOperation.createBucket(OSSBucketOperation.java:83)
at com.aliyun.oss.OSSClient.createBucket(OSSClient.java:204)
at com.aliyun.oss.OSSClient.createBucket(OSSClient.java:192)
at com.plan.action.Test.main(Test.java:242)
Caused by: com.aliyun.oss.common.parser.ResultParseException: 返回结果无效,无法解析。
at com.aliyun.oss.common.parser.JAXBResultParser.getObject(JAXBResultParser.java:72)
at com.aliyun.oss.internal.OSSErrorResponseHandler.handle(OSSErrorResponseHandler.java:46)
... 9 more
Caused by: javax.xml.bind.JAXBException
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:195)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:381)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
at com.aliyun.oss.common.parser.JAXBResultParser.initJAXBContext(JAXBResultParser.java:89)
at com.aliyun.oss.common.parser.JAXBResultParser.getObject(JAXBResultParser.java:61)
... 10 more
Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:191)
... 15 more
-------------------------
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。