gpt4 book ai didi

java - Tomcat 管理器脚本部署大型 war 不工作

转载 作者:行者123 更新时间:2023-11-28 23:32:59 27 4
gpt4 key购买 nike

我正在尝试通过使用 Manager-Script servlet 上传 WAR,在 tomcat 8.0.12 中自动部署我的 WAR。

对此 URL 执行 PUT:

http://tomcaserver:8080/manager/text/deploy?path=/myApp&update=true

我的 WAR 大小约为 80mb,我认为这是问题所在。

我使用小型 WAR(大约 500kb)进行了测试,上传没有问题。

我已经尝试在/webapps/manager/WEB-INF/web.xml 中指定 multipart-config,插入:

<servlet>
<servlet-name>Manager</servlet-name>
<servlet-class>org.apache.catalina.manager.ManagerServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<multipart-config>
<!-- 200MB max -->
<max-file-size>209715200</max-file-size>
<max-request-size>209715200</max-request-size>
<file-size-threshold>0</file-size-threshold>
</multipart-config>
</servlet>

此后问题依旧。

我正在使用 Apache HTTPClient 上传,这是个异常(exception):

Exception in thread "main" java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
at org.apache.http.impl.io.SessionOutputBufferImpl.streamWrite(SessionOutputBufferImpl.java:123)
at org.apache.http.impl.io.SessionOutputBufferImpl.flushBuffer(SessionOutputBufferImpl.java:135)
at org.apache.http.impl.io.SessionOutputBufferImpl.write(SessionOutputBufferImpl.java:164)
at org.apache.http.impl.io.ContentLengthOutputStream.write(ContentLengthOutputStream.java:115)
at org.apache.http.entity.mime.content.FileBody.writeTo(FileBody.java:120)
at org.apache.http.entity.mime.AbstractMultipartForm.doWriteTo(AbstractMultipartForm.java:150)
at org.apache.http.entity.mime.AbstractMultipartForm.writeTo(AbstractMultipartForm.java:173)
at org.apache.http.entity.mime.MultipartFormEntity.writeTo(MultipartFormEntity.java:97)
at org.apache.http.impl.DefaultBHttpClientConnection.sendRequestEntity(DefaultBHttpClientConnection.java:155)
at org.apache.http.impl.conn.CPoolProxy.sendRequestEntity(CPoolProxy.java:149)
at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:236)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:121)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:254)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
at br.com.jjw.atualizador.core.Atualizador.deploy(Atualizador.java:175)

这是我的代码:

    String url = "http://tomcatserver:8080/manager/text/deploy?path=/organize&update=true";

HttpPut req = new HttpPut(url);
MultipartEntityBuilder meb = MultipartEntityBuilder.create();
// upload the big war (80mb)
meb.addBinaryBody("attachment", war, ContentType.APPLICATION_OCTET_STREAM, "myApp.war");
req.setEntity(meb.build());

CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("tomcat", "s3cret"));

CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
CloseableHttpResponse resp = client.execute(req); <<<---- EXCEPTION!

我该如何解决这个问题?

最佳答案

问题是您构建文件上传的方式很奇怪。我不知道“附件”会做什么,但 HTTP PUT 是正确的。

试试这个:

String url = "http://tomcatserver:8080/manager/text/deploy?path=/organize&update=true";

HttpPut req = new HttpPut(url);
File war = new File("myApp.war");
req.setEntity(new FileEntity(war, ContentType.APPLICATION_OCTET_STREAM));

CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("tomcat", "s3cret"));

CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
CloseableHttpResponse resp = client.execute(req);

关于java - Tomcat 管理器脚本部署大型 war 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28065133/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com