半盏清暑茶
2021-10-15 10:37
采纳率: 100%
浏览 90

Java应用winrm执行powershell指令(时间比较长),等待接收返回值时报400

项目需要,将压缩文件上传到WINDOWS服务器上,并解压,程序部署在LINUX服务器上;
文件123.zip上传正常进行的,现在执行解压,手动执行指令解压需要3-5分钟(),
部分代码如下:

WinRmClientContext context = null;
try {
    context = WinRmClientContext.newInstance();
    WinRmTool wTool = WinRmTool.Builder.builder("100.xx.xx.xx", "administrator", "123123")
            .authenticationScheme(AuthSchemes.NTLM)
            .port(5985)
            .useHttps(false)
            .context(context)
            .build();
    wTool.setConnectionTimeout(10 * 60 * 1000L);
    wTool.setOperationTimeout(10 * 60 * 1000L);
    WinRmToolResponse wResponse = wTool.executePs("if (Test-Path 'c:\\123.zip'){Expand-Archive -LiteralPath 'c:\\123.zip' -DestinationPath 'c:\\' -Force};Test-Path 'c:\\123'");
    System.out.println(wResponse.getStatusCode());
    System.out.println(wResponse.getStdOut());
        System.out.println(wResponse.getStdErr());
} catch (Exception e) {
    e.printStackTrace();
    System.out.println("exitCode: -1");
} finally {
    if (context != null) {
        context.shutdown();
    }
}

调试执行后,报错如下:

09:53:24.297 [Thread-0] DEBUG io.cloudsoft.winrm4j.client.RetryingProxyHandler - failed task "delete" after 2 attempt(s), rethrowing first exception
java.lang.RuntimeException: failed task "signal" after 2 attempt(s)
    at io.cloudsoft.winrm4j.client.RetryingProxyHandler.invokeWithRetry(RetryingProxyHandler.java:79)
    at io.cloudsoft.winrm4j.client.RetryingProxyHandler.invoke(RetryingProxyHandler.java:31)
    at com.sun.proxy.$Proxy47.signal(Unknown Source)
    at io.cloudsoft.winrm4j.client.ShellCommand.releaseCommand(ShellCommand.java:212)
    at io.cloudsoft.winrm4j.client.ShellCommand.execute(ShellCommand.java:102)
    at io.cloudsoft.winrm4j.winrm.WinRmTool.executeCommand(WinRmTool.java:398)
    at io.cloudsoft.winrm4j.winrm.WinRmTool.executePs(WinRmTool.java:422)
    at io.cloudsoft.winrm4j.winrm.WinRmTool.executePs(WinRmTool.java:413)
    at com.inspur.util.WindowsCommandUtil.lambda$0(WindowsCommandUtil.java:296)
    at java.lang.Thread.run(Thread.java:745)
    Suppressed: java.lang.RuntimeException: failed task "delete" after 2 attempt(s)
        at io.cloudsoft.winrm4j.client.RetryingProxyHandler.invokeWithRetry(RetryingProxyHandler.java:79)
        at io.cloudsoft.winrm4j.client.RetryingProxyHandler.invoke(RetryingProxyHandler.java:31)
        at com.sun.proxy.$Proxy47.delete(Unknown Source)
        at io.cloudsoft.winrm4j.client.ShellCommand.close(ShellCommand.java:219)
        at io.cloudsoft.winrm4j.winrm.WinRmTool.executeCommand(WinRmTool.java:401)
        ... 4 more
    Caused by: javax.xml.ws.WebServiceException: Could not send Message.
        at org.apache.cxf.jaxws.JaxWsClientProxy.mapException(JaxWsClientProxy.java:183)
        at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:145)
        at com.sun.proxy.$Proxy46.delete(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at io.cloudsoft.winrm4j.client.RetryingProxyHandler.invokeWithRetry(RetryingProxyHandler.java:44)
        ... 8 more
    Caused by: org.apache.cxf.transport.http.HTTPException: HTTP response '400: ' when communicating with http://100.xx.xx.xx:5985/wsman
        at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.doProcessResponseCode(HTTPConduit.java:1619)
        at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1626)
        at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1571)
        at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1371)
        at org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit$AsyncWrappedOutputStream.close(AsyncHTTPConduit.java:429)
        at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:223)
        at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
        at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:671)
        at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:63)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
        at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:530)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:441)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:356)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:314)
        at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
        at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:140)
        ... 14 more
Caused by: javax.xml.ws.WebServiceException: Could not send Message.
    at org.apache.cxf.jaxws.JaxWsClientProxy.mapException(JaxWsClientProxy.java:183)
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:145)
    at com.sun.proxy.$Proxy46.signal(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at io.cloudsoft.winrm4j.client.RetryingProxyHandler.invokeWithRetry(RetryingProxyHandler.java:44)
    ... 9 more
Caused by: org.apache.cxf.transport.http.HTTPException: HTTP response '400: ' when communicating with http://100.xx.xx.xx:5985/wsman
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.doProcessResponseCode(HTTPConduit.java:1619)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1626)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1571)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1371)
    at org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit$AsyncWrappedOutputStream.close(AsyncHTTPConduit.java:429)
    at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:223)
    at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
    at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:671)
    at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:63)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
    at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:530)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:441)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:356)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:314)
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:140)
    ... 15 more

目前尝试的方向:
1.创建Start-Job后台执行,返回值Job创建成功,但实际并没有执行解压;
2.自定义winrm4j的RetryingProxyHandler,还在探索中;
请教各位,有没有什么好的解决方法?

1条回答 默认 最新

相关推荐 更多相似问题