Java拼装调用soap接口及返回XML转实体类

请求报文

返回报文

1.新建soapclien工具类,也可以自己拼接请求字符串,这里用的事通过SOAPPart构建拼接,对于返回的xml报文我们需要转义

package com.hrsj.dp.mcc.account.esb;

import com.hrsj.dp.mcc.account.esb.model.ESBReturn;
import com.hrsj.dp.mcc.account.esb.model.EsbServiceForERPTaskBean;
import com.hrsj.dp.mcc.account.esb.model.EsbServiceTaskReturnBean;
import com.hrsj.dp.mcc.account.esb.utils.EsbTaskUtils;
import com.hrsj.dp.mcc.account.esb.utils.XStreamXmlBeanUtil;
import org.apache.commons.lang3.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.bind.JAXBException;
import javax.xml.soap.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;

/**
 * @Author:pengfusong
 * @Description:
 * @Date: Create in 10:21 2023/10/26
 * @Modified by :
 */
public class SOAPClientForESB_ERP {


    private static final Logger log = LoggerFactory.getLogger(SOAPClient.class);

    private static final String NAME_SPACE_FOR_WSSE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";

    private static final String NAME_SPACE_FOR_CUX = "http://xmlns.oracle.com/apps/cux/soaprovider/plsql/cux_10_ws_server_prg/";

    private static final String NAME_SPACE_FOR_INV = "http://xmlns.oracle.com/apps/cux/soaprovider/plsql/cux_10_ws_server_prg/invokefmsws/";

    private static final String NAME_SPACE_FOR_PASSWORD = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText";

    /** 通用方法 */
    public static ESBReturn putXmlSoap(EsbServiceForERPTaskBean esbServiceTaskBean, String xmlStr,
                                                      String urlString) {

        log.info("开始调用接口");

//        EsbServiceTaskReturnBean result = new EsbServiceTaskReturnBean();
        ESBReturn result= new ESBReturn();
        try {
            /** 创建连接 */
            SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();
            SOAPConnection connection = soapConnFactory.createConnection();

            /** 创建消息对象 */
            MessageFactory messageFactory = MessageFactory.newInstance();
            SOAPMessage message = messageFactory.createMessage();
            // message.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "UTF-8");

            /** 创建soap消息主体 */
            SOAPPart soapPart = message.getSOAPPart();
            SOAPEnvelope envelope = soapPart.getEnvelope();
            envelope.addNamespaceDeclaration("cux"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值