Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在tomcat上以编程方式部署web服务_Java_Apache_Web Services_Tomcat_Jax Rs - Fatal编程技术网

Java 在tomcat上以编程方式部署web服务

Java 在tomcat上以编程方式部署web服务,java,apache,web-services,tomcat,jax-rs,Java,Apache,Web Services,Tomcat,Jax Rs,我正在尝试创建一个服务,在tomcat服务器上部署WAR文件。该类将输入作为WAR文件的路径,并在以下运行的类完成代码后自动将其部署到tomcat服务器。请帮我做这个。另外,我不想在上传WAR时使用SFTP,而是使用put请求在tomcat上部署WAR文件。我见过使用FTP或SFTP的例子,但这是我不需要的。我的服务已经托管在tomcat上,它将自动托管提供给它的WAR文件 public class DeployManager { static CredentialsProvider cred

我正在尝试创建一个服务,在tomcat服务器上部署WAR文件。该类将输入作为WAR文件的路径,并在以下运行的类完成代码后自动将其部署到tomcat服务器。请帮我做这个。另外,我不想在上传WAR时使用SFTP,而是使用put请求在tomcat上部署WAR文件。我见过使用FTP或SFTP的例子,但这是我不需要的。我的服务已经托管在tomcat上,它将自动托管提供给它的WAR文件

public class DeployManager {

static CredentialsProvider credsProvider = new BasicCredentialsProvider();;

public static void main(String args[]) throws ClientProtocolException, IOException {
    /*
     * warning only ever AuthScope.ANY while debugging with these settings
     * the tomcat username and pw are added to EVERY request
     */

    credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("tomcat", "s3cret"));
    deploy();
    // undeploy();
}

private static void deploy() throws ClientProtocolException, IOException {
    String url = "http://localhost:8080/manager/text/deploy?path=C:/Users/Jainesh_Trivedi/Desktop/WAR/AutohostDemo1_1145.war";
    File file = new File("C:\\Users\\Jainesh_Trivedi\\Desktop\\WAR\\AutohostDemo1_1145.war");

    HttpPut req = new HttpPut(url);
    MultipartEntityBuilder meb = MultipartEntityBuilder.create();
    meb.addTextBody("Sample", "C:\\Users\\Jainesh_Trivedi\\Desktop\\WAR\\AutohostDemo1_1145.war");

    // "application/octect-stream"
    meb.addBinaryBody("attachment", file, ContentType.APPLICATION_OCTET_STREAM, file.getName());

    req.setEntity(meb.build());
    String response = executeRequest(req, credsProvider);

    System.out.println("Response : " + response);
}

public static void undeploy() throws ClientProtocolException, IOException {
    String url = "http://localhost:8080/manager/text/undeploy?path=/deployMe";
    HttpGet req = new HttpGet(url);
    String response = executeRequest(req, credsProvider);
    System.out.println("Response : " + response);
}

private static String executeRequest(HttpRequestBase requestBase, CredentialsProvider credsProvider)
        throws ClientProtocolException, IOException {
    CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
    InputStream responseStream = null;
    String res = null;
    HttpResponse response = client.execute(requestBase);
    HttpEntity responseEntity = response.getEntity();
    responseStream = responseEntity.getContent();

    BufferedReader br = new BufferedReader(new InputStreamReader(responseStream));
    StringBuilder sb = new StringBuilder();
    String line;
    while ((line = br.readLine()) != null) {
        sb.append(line);
        sb.append(System.getProperty("line.separator"));
    }
    br.close();
    res = sb.toString();

    return res;
}
}
错误是:

    INFO: I/O exception (java.net.SocketException) caught when processing request: Connection reset by peer: socket write error
Nov 24, 2015 10:39:23 AM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request
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(Unknown Source)
    at java.net.SocketOutputStream.write(Unknown Source)
    at org.apache.http.impl.io.SessionOutputBufferImpl.streamWrite(SessionOutputBufferImpl.java:117)
    at org.apache.http.impl.io.SessionOutputBufferImpl.flushBuffer(SessionOutputBufferImpl.java:129)
    at org.apache.http.impl.io.SessionOutputBufferImpl.write(SessionOutputBufferImpl.java:158)
    at org.apache.http.impl.io.ContentLengthOutputStream.write(ContentLengthOutputStream.java:114)
    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:156)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.http.impl.conn.CPoolProxy.invoke(CPoolProxy.java:138)
    at com.sun.proxy.$Proxy0.sendRequestEntity(Unknown Source)
    at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:237)
    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:122)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:254)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:177)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:77)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:95)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
    at com.autohost.java.DeployManager.executeRequest(DeployManager.java:68)
    at com.autohost.java.DeployManager.deploy(DeployManager.java:51)
    at com.autohost.java.DeployManager.main(DeployManager.java:35)

如果我正确理解了您的问题,您正在尝试重新创建

yes类型的@user2560528,我的服务将把输入作为WAR文件的路径,并将其托管在服务器上