开发者社区> 问答> 正文

创建bucket报错

根据官方提供的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

展开
收起
飞墨言逝 2014-12-03 14:29:24 21187 0
5 条回答
写回答
取消 提交回答
  • 回 3楼飞墨言逝的帖子
    请问你新建的是java项目还是web项目
    2015-12-08 16:21:56
    赞同 展开评论 打赏
  • 回2楼nightleslie的帖子
    您好!请问您这个问题是怎么解决的?
    2015-10-21 09:04:41
    赞同 展开评论 打赏
  • 回2楼nightleslie的帖子
    我那个问题解决了,我是在原来的框架上加入的jar包然后运行的之上代码,后来又重新创建了一个项目,发现问题就没有了,不知道是怎么回事
    2014-12-04 10:15:32
    赞同 展开评论 打赏
  • Re创建bucket报错
    我这边使用2.0.0的sdk跑你提供的代码,是报这样的错,是有明确ErrorMessage的。

    Exception in thread "main" [ErrorCode]:BucketAlreadyExists, [Message]:The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.
        [RequestId]:547EEE883F363A8B6EC03B48
        at com.aliyun.oss.internal.OSSExceptionFactory.create(OSSExceptionFactory.java:22)
        at com.aliyun.oss.internal.OSSErrorResponseHandler.handle(OSSErrorResponseHandler.java:47)
        at com.aliyun.oss.common.comm.ServiceClient.handleResponse(ServiceClient.java:291)
        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:85)
        at com.aliyun.oss.OSSClient.createBucket(OSSClient.java:205)
        at com.aliyun.oss.OSSClient.createBucket(OSSClient.java:193)
        at tmp.OSSClientTest.main(OSSClientTest.java:89)

    请问你有重试过吗?

    -------------------------

    Re创建bucket报错
    可能是引入的其他jar包(比如解析xml的报)版本不一致,导致实际使用的不是sdk要求的jar包,从而导致报错。
    仅仅是猜测,还是要看具体的场景。
    2014-12-03 19:08:28
    赞同 展开评论 打赏
  • http://bbs.aliyun.com/read/149100.html?spm=5176.7114037.1996646101.4.FmJ7TA&pos=2

    不知能不解决你的问题  ,我不懂,纯帮忙
    2014-12-03 17:50:10
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载