简体   繁体   English

Tomcat管理器脚本部署大战无法正常工作

[英]Tomcat manager script deploy large war not working

I'm trying to automate the deploy of my WAR in tomcat 8.0.12 , by uploading the WAR using the Manager-Script servlet. 我正在尝试使用Manager-Script servlet上传WAR,从而在tomcat 8.0.12中自动部署WAR。

Performing a PUT to this URL: 对这个URL执行PUT:

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

My WAR size is about 80mb, and I think that is the problem. 我的WAR大小约为80mb,我认为这是问题所在。

I tested using a small WAR (about 500kb) and it uploads without problems. 我使用小型WAR(大约500kb)进行了测试,并且上传时没有问题。

I already tried to specify the multipart-config inside the /webapps/manager/WEB-INF/web.xml, inserting this: 我已经尝试在/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>

After this, the problem continues. 此后,问题继续。

I'm using Apache HTTPClient to upload and this is the exception: 我正在使用Apache HTTPClient进行上传,这是一个例外:

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)

This is my code: 这是我的代码:

    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!

How can I solve this? 我该如何解决?

The problem is the weird way in which you have constructed your file upload. 问题是您构建文件上传的方式很奇怪。 I don't know what the "attachment" will do, but the HTTP PUT is correct. 我不知道“附件”会做什么,但是HTTP PUT是正确的。

Try this: 尝试这个:

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM