From a8135f4b54c61a441a857806bb194cc6d61f8a4d Mon Sep 17 00:00:00 2001 From: huangxin Date: Wed, 22 Apr 2020 20:23:38 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0=E8=BF=AA?= =?UTF-8?q?=E6=99=AESOAP=E6=8E=A5=E5=8F=A3=E8=B6=85=E6=97=B6=E5=80=BC?= =?UTF-8?q?=E4=B8=BA1s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/dispose/common/GlobalVar.java | 10 ++++++ .../com/dispose/dispose/impl/DPTechImpl.java | 35 ++++++++++--------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/dispose/common/GlobalVar.java b/src/main/java/com/dispose/common/GlobalVar.java index 98e5a761..83585a72 100644 --- a/src/main/java/com/dispose/common/GlobalVar.java +++ b/src/main/java/com/dispose/common/GlobalVar.java @@ -19,4 +19,14 @@ public class GlobalVar { * The constant USED_VIRTUAL_DISPOSE_MODE. */ public static volatile boolean USED_VIRTUAL_DISPOSE_MODE = false; + + /** + * The constant SOAP_CONNECT_TIMEOUT. + */ + public static final int SOAP_CONNECT_TIMEOUT = 1000; + + /** + * The constant SOAP_RECEIVE_TIMEOUT. + */ + public static final int SOAP_RECEIVE_TIMEOUT = 1000; } diff --git a/src/main/java/com/dispose/dispose/impl/DPTechImpl.java b/src/main/java/com/dispose/dispose/impl/DPTechImpl.java index 27d498d1..421ca070 100644 --- a/src/main/java/com/dispose/dispose/impl/DPTechImpl.java +++ b/src/main/java/com/dispose/dispose/impl/DPTechImpl.java @@ -2,21 +2,27 @@ package com.dispose.dispose.impl; import com.dispose.Interceptor.SoapPasswordCallbackHandler; import com.dispose.common.ConstValue; +import com.dispose.common.GlobalVar; +import com.dispose.config.DisposeConfigure; import com.dispose.dispose.DisposeEntryManager; import com.dispose.dispose.po.DeviceInfo; import com.dispose.pojo.po.DisposeDeviceCapacity; import com.dptech.dispose.AbnormalFlowCleaningServicePortType; import com.dptech.dispose.ArrayOfDetectionObjectDataForService; import com.dptech.dispose.ArrayOfProtectionObjectDataForService; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; +import org.apache.cxf.endpoint.Client; +import org.apache.cxf.frontend.ClientProxy; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; +import org.apache.cxf.transport.http.HTTPConduit; +import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor; import org.apache.wss4j.dom.WSConstants; import org.apache.wss4j.dom.handler.WSHandlerConstants; @@ -26,6 +32,9 @@ import org.apache.wss4j.dom.handler.WSHandlerConstants; */ @Slf4j public class DPTechImpl implements DisposeEntryManager { + @Resource + private DisposeConfigure disposeConfigure; + /** * The Clean type port. */ @@ -52,6 +61,13 @@ public class DPTechImpl implements DisposeEntryManager { jaxWsProxyFactoryBean.getOutInterceptors().add(new WSS4JOutInterceptor(outProps)); this.cleanTypePort = (AbnormalFlowCleaningServicePortType) jaxWsProxyFactoryBean.create(); + + Client proxy = ClientProxy.getClient(this.cleanTypePort); + HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); + HTTPClientPolicy policy = new HTTPClientPolicy(); + policy.setConnectionTimeout(GlobalVar.SOAP_CONNECT_TIMEOUT); // 请求超时 + policy.setReceiveTimeout(GlobalVar.SOAP_RECEIVE_TIMEOUT); //读取超时 + conduit.setClient(policy); } /** @@ -61,21 +77,7 @@ public class DPTechImpl implements DisposeEntryManager { * @param type the type */ public DPTechImpl(String ipAddr, ConstValue.IPAddrType type) { - JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean(); - jaxWsProxyFactoryBean.setServiceClass(AbnormalFlowCleaningServicePortType.class); - jaxWsProxyFactoryBean.setAddress(String.format(ConstValue.SOAPWrapperConst.NAMESPACE_URI, ipAddr)); - - //WS-Security Head - Map outProps = new HashMap<>(); - outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN); - - outProps.put(WSHandlerConstants.USER, "admin"); - outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT); - outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, SoapPasswordCallbackHandler.class.getName()); - - jaxWsProxyFactoryBean.getOutInterceptors().add(new WSS4JOutInterceptor(outProps)); - - this.cleanTypePort = (AbnormalFlowCleaningServicePortType) jaxWsProxyFactoryBean.create(); + this(ipAddr); } /** @@ -229,7 +231,6 @@ public class DPTechImpl implements DisposeEntryManager { * Gets detection object device json. * * @return the detection object device json - * @throws JsonProcessingException the json processing exception */ public String getDetectionObjectDeviceJson() { try {