From f998b29d2a4ea2fc95e34144de7c91e7ba48d8bb Mon Sep 17 00:00:00 2001 From: yewj Date: Thu, 26 Dec 2024 14:52:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Eservice=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 23 +++++-- .../mipsdl/client/hlfyyy/HlfyyyClient.java | 62 +++++++------------ 2 files changed, 40 insertions(+), 45 deletions(-) diff --git a/pom.xml b/pom.xml index 36f8ebd..bd017e4 100644 --- a/pom.xml +++ b/pom.xml @@ -172,15 +172,26 @@ jna 5.11.0 + - javax.xml.ws - jaxws-api - 2.3.1 + org.apache.axis2 + axis2-kernel + 1.8.0 - com.sun.xml.ws - jaxws-rt - 2.3.1 + org.apache.axis2 + axis2-adb + 1.8.0 + + + org.apache.axis2 + axis2-transport-local + 1.8.0 + + + org.apache.axis2 + axis2-transport-http + 1.8.0 diff --git a/src/main/java/com/glxp/mipsdl/client/hlfyyy/HlfyyyClient.java b/src/main/java/com/glxp/mipsdl/client/hlfyyy/HlfyyyClient.java index 219371d..528b86a 100644 --- a/src/main/java/com/glxp/mipsdl/client/hlfyyy/HlfyyyClient.java +++ b/src/main/java/com/glxp/mipsdl/client/hlfyyy/HlfyyyClient.java @@ -70,6 +70,11 @@ import com.glxp.mipsdl.thirddao.ctqyy.*; import com.glxp.mipsdl.thirddao.hlfyyy.*; import com.glxp.mipsdl.util.*; import lombok.extern.slf4j.Slf4j; +import org.apache.axis2.AxisFault; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.client.Options; +import org.apache.axis2.rpc.client.RPCServiceClient; +import org.apache.ibatis.mapping.ParameterMode; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; @@ -79,12 +84,8 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import javax.xml.namespace.QName; -import javax.xml.soap.*; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.math.BigDecimal; -import java.net.URL; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; @@ -2404,48 +2405,31 @@ public class HlfyyyClient extends CommonHttpClient { } - private static final String WSDL_URL = "http://192.168.158.208:8152/ZoesoftHipService.asmx?WSDL"; - private static final String NAMESPACE = "http://192.168.158.208:8152/"; - private static final String SERVICE_NAME = "saveBuyApplyInfo"; - - - public String callInterface(String msgHeader, String msgBody) throws Exception { - SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); - SOAPConnection connection = soapConnectionFactory.createConnection(); - - try { - MessageFactory messageFactory = MessageFactory.newInstance(); - SOAPMessage soapMessage = messageFactory.createMessage(); - - SOAPPart soapPart = soapMessage.getSOAPPart(); - SOAPEnvelope envelope = soapPart.getEnvelope(); - envelope.addNamespaceDeclaration("tem", NAMESPACE); + // WebService地址 + private static final String METHOD_NAME = "saveBuyApplyInfo"; - SOAPBody soapBody = envelope.getBody(); - - SOAPElement operationElement = soapBody.addChildElement(SERVICE_NAME, "tem"); - - SOAPElement msgHeaderElement = operationElement.addChildElement("as_msgHeader"); - msgHeaderElement.addTextNode(msgHeader); - - SOAPElement msgBodyElement = operationElement.addChildElement("as_msgBody"); - msgBodyElement.addTextNode(msgBody); + private static final String WSDL_URL = "http://192.168.158.208:8152/ZoesoftHipService.asmx?WSDL"; - SOAPElement responseElement = operationElement.addChildElement("rs_response_xml"); + public String callInterface(String msgHeader, String msgBody) throws AxisFault { + // Create RPC Service Client + RPCServiceClient serviceClient = new RPCServiceClient(); + Options options = serviceClient.getOptions(); - log.error("request: {}", soapMessage.toString()); + // Set the target endpoint + EndpointReference targetEPR = new EndpointReference(WSDL_URL); + options.setTo(targetEPR); - soapMessage.saveChanges(); + // Prepare parameters + Object[] params = new Object[]{msgHeader, msgBody, ""}; - SOAPMessage soapResponse = connection.call(soapMessage, WSDL_URL); + // Define return type + Class[] returnTypes = new Class[]{String.class}; - SOAPBody responseBody = soapResponse.getSOAPBody(); - return responseBody.getTextContent(); + // Invoke the web service + Object[] response = serviceClient.invokeBlocking(QName.valueOf(METHOD_NAME), params, returnTypes); - } finally { - connection.close(); - } + // Return the response + return response[0] != null ? response[0].toString() : null; } - }