首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Jboss下载/保存附件

使用Jboss下载/保存附件
EN

Stack Overflow用户
提问于 2021-01-22 21:25:34
回答 1查看 86关注 0票数 0

我有一个Jboss命令,我试图使用DMR库在Java中实现它。这个步骤涉及下载附件(显示/保存),但是在任何地方都没有可用的文档。任何帮助都是非常感谢的。

我试图转换为DMR的CLI命令:

代码语言:javascript
复制
attachment display --operation=/deployment=app.war:read-content(path=META-INF/MANIFEST.MF)

下面是我的操作对象,但是无法提供显示/保存附件的命令

代码语言:javascript
复制
ModelNode request = new ModelNode();
request.get(ClientConstants.OP_ADDR).add(ClientConstants.DEPLOYMENT, "app.war");
request.get(ClientConstants.OP).set(ClientConstants.READ_CONTENT_OPERATION);
request.get(ClientConstants.PATH).set("META-INF/MANIFEST.MF");

这个DMR操作产生的全部结果是

代码语言:javascript
复制
{
    "outcome" => "success",
    "result" => {"uuid" => "1f45b2bf-8402-4b46-a721-3e3f23db5d80"},
    "response-headers" => {"attached-streams" => [{
        "uuid" => "1f45b2bf-8402-4b46-a721-3e3f23db5d80",
        "mime-type" => "text/plain"
    }]}
}

是否有编辑操作或使用操作中返回的uuid从流下载附件的方法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-23 00:09:17

我也没有看到任何关于这方面的明确文件。然而,您需要使用的是获取流的OperationResponse。下面是一个例子。

代码语言:javascript
复制
public class ReadContent {

    public static void main(final String[] args) throws Exception {

        try (ModelControllerClient client = ModelControllerClient.Factory.create("localhost", 9990)) {
            try (
                    StreamEntry entry = readContent(client, "kitchensink.war", "META-INF/MANIFEST.MF");
                    InputStream in = entry.getStream();
            ) {
                int len;
                final byte[] buffer = new byte[256];
                while ((len = in.read(buffer)) != -1) {
                    System.out.write(buffer, 0, len);
                }
            }
        }
    }

    private static StreamEntry readContent(final ModelControllerClient client, final String deploymentName, final String path) throws IOException {
        final ModelNode address = Operations.createAddress("deployment", deploymentName);
        final ModelNode op = Operations.createOperation(ClientConstants.READ_CONTENT_OPERATION, address);
        op.get(ClientConstants.PATH).set(path);

        // Execute the operation
        final OperationResponse response = client.executeOperation(Operation.Factory.create(op), OperationMessageHandler.logging);

        // Get the response node to evaluate the outcome
        final ModelNode outcome = response.getResponseNode();
        if (Operations.isSuccessfulOutcome(outcome)) {
            // Read the result and get the UUID the stream is attached to
            final String uuid = Operations.readResult(outcome).get(ClientConstants.UUID).asString();
            return response.getInputStream(uuid);
        }

        // The operation has failed, raise and exception with the failure description
        throw new RuntimeException("Failed to read the content: " + Operations.getFailureDescription(outcome).asString());
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65852963

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档