| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421 |
- package cn.com.goldenwater.dcproj.utils;
- import cn.com.goldenwater.dcproj.model.GwComFile;
- import org.apache.axis.client.Call;
- import org.apache.axis.client.Service;
- import org.dom4j.Document;
- import org.dom4j.DocumentException;
- import org.dom4j.Element;
- import org.dom4j.io.SAXReader;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import sun.misc.BASE64Encoder;
- import javax.xml.namespace.QName;
- import java.io.ByteArrayInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.UnsupportedEncodingException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.Iterator;
- import java.util.List;
- /**
- * 用于处理调用 wsdl接口
- */
- public class HttpWSDLUtils {
- private static final Logger logger = LoggerFactory.getLogger(HttpWSDLUtils.class);
- /**
- * wsdl 接口地址
- */
- private static final String END_POINT = "http://10.135.6.4:8080/WaterCenter/webservice/ConvergenceService?wsdl";
- private static final String TARGET_NAMESPACE = "http://tempuri.org/";
- private static final String USER_LOGIN_METHOD = "LoginByAccount" ;
- private static final String DATA_PUSH_METHOD = "pushXml" ;
- private static final String ACCOUNT_NAME = "sljgpt" ;
- private static final String ACCOUNT_PWD = "Sl@jg905%#" ;
- private static final String WEB_FLAG = "WEB198" ;
- public static final String CONTENT_CHARSET = "UTF-8";
- public static String getUserToken(){
- try {
- Service service = new Service();
- Call call = (Call)service.createCall();
- //设置地址
- call.setTargetEndpointAddress(new java.net.URL(END_POINT));
- //设置要调用哪个方法
- call.setOperationName(new QName(TARGET_NAMESPACE, USER_LOGIN_METHOD));// 设置操作的名称。
- //设置参数名 :参数名 ,参数类型:String, 参数模式:'IN' or 'OUT'
- call.addParameter("userid",
- org.apache.axis.encoding.XMLType.XSD_STRING,
- javax.xml.rpc.ParameterMode.IN);// 接口的参数
- call.addParameter("password",
- org.apache.axis.encoding.XMLType.XSD_STRING,
- javax.xml.rpc.ParameterMode.IN);// 接口的参数
- //返回类型
- call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// 设置返回类型
- //调用方法并传递参数
- String result = String.valueOf(call.invoke(new Object[]{ACCOUNT_NAME,ACCOUNT_PWD}));
- logger.error("line 61 LoginByAccount result: " + result);
- return result;
- } catch (Exception e) {
- logger.error("身份验证失败 ",e);
- System.err.println(e.toString());
- return "身份验证失败";
- }
- }
- /**
- * 根据 身份验证串 发送数据信息xml
- * @author lxf
- * @date 2023/12/6 11:14
- */
- public static String pushData(String guid, String xmlStr ){
- try {
- if(null == xmlStr){
- return "没有数据需要推送 line 88";
- }
- System.out.println("HttpWSDLUtils pushData 90 guid : " + guid);
- logger.info("HttpWSDLUtils pushData 91 guid : " + guid);
- Service service = new Service();
- Call call = (Call)service.createCall();
- //设置地址
- call.setTargetEndpointAddress(new java.net.URL(END_POINT));
- //设置要调用哪个方法
- call.setOperationName(new QName(TARGET_NAMESPACE, DATA_PUSH_METHOD));// 设置操作的名称。
- //设置参数名 :参数名 ,参数类型:String, 参数模式:'IN' or 'OUT'
- call.addParameter("guid",
- org.apache.axis.encoding.XMLType.XSD_STRING,
- javax.xml.rpc.ParameterMode.IN);// 接口的参数
- call.addParameter("catalogid",
- org.apache.axis.encoding.XMLType.XSD_STRING,
- javax.xml.rpc.ParameterMode.IN);// 接口的参数
- call.addParameter("xmlstr",
- org.apache.axis.encoding.XMLType.XSD_STRING,
- javax.xml.rpc.ParameterMode.IN);// 接口的参数
- //返回类型
- call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// 设置返回类型
- //调用方法并传递参数
- String result = String.valueOf(call.invoke(new Object[]{guid,WEB_FLAG,xmlStr}));
- System.out.println("HttpWSDLUtils pushData 112 result is " + result);
- logger.info("HttpWSDLUtils pushData 113 result is " + result);
- InputStream is = new ByteArrayInputStream(result.getBytes("UTF-8"));
- SAXReader reader = new SAXReader();
- Document doc = reader.read(is);
- Element root = doc.getRootElement();
- Iterator<Element> rootIterator = root.elementIterator();
- while (rootIterator.hasNext()){
- Element element= rootIterator.next();
- System.out.println("HttpWSDLUtils pushData 121 result is " + element.asXML());
- String nodeName = element.getName();
- System.out.println("node name: " + nodeName);
- System.out.println("node data: " + element.getData());
- if("flag".equals(nodeName)){
- String text = element.getText();
- if("true".equals(text)){
- result = "推送成功";
- }else {
- result = "推送失败";
- }
- System.out.println("HttpWSDLUtils pushData 132 result: " +text);
- logger.info("HttpWSDLUtils pushData 133 result: " +text);
- }
- }
- is.close();
- return result;
- } catch (Exception e) {
- System.err.println(e.toString());
- logger.info("HttpWSDLUtils pushData 141 Exception: " +e.getMessage());
- return "推送数据失败";
- }
- }
- /**
- * 把数据库的数据转换化为xml报文 增加
- * @author lxf
- * @date 2023/12/6 11:25
- */
- public static String getAddXmlStr(List<GwComFile> comFileList) {
- if(null == comFileList || comFileList.isEmpty()){
- return null;
- }
- StringBuffer xmlSB = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
- xmlSB.append("<table>");
- for(GwComFile comFile : comFileList){
- xmlSB.append("<row type=\"add\">");
- // 设置字段
- xmlSB.append("<id name=\"主键\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getId());
- xmlSB.append("]]></id>");
- xmlSB.append("<file_title name=\"文件标题\" isattachment=\"true\"><![CDATA[");
- xmlSB.append(comFile.getFilePath().replace("\\","/").substring(7));
- xmlSB.append("]]></file_title>");
- xmlSB.append("<key_word name=\"关键词\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getKeyWord());
- xmlSB.append("]]></key_word>");
- xmlSB.append("<file_type name=\"音频视频文本图片等\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getFileType());
- xmlSB.append("]]></file_type>");
- xmlSB.append("<abs name=\"摘要\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getAbs());
- xmlSB.append("]]></abs>");
- xmlSB.append("<file_name name=\"原始文件名(包含扩展名)\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getFileName());
- xmlSB.append("]]></file_name>");
- xmlSB.append("<file_size name=\"文件大小\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getFileSize());
- xmlSB.append("]]></file_size>");
- xmlSB.append("<file_ext name=\"文件扩展名\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getFileExt());
- xmlSB.append("]]></file_ext>");
- xmlSB.append("<file_path name=\"文件路径\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getFilePath());
- xmlSB.append("]]></file_path>");
- xmlSB.append("<thumbnail_url name=\"缩略图路径\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getThumbnailUrl());
- xmlSB.append("]]></thumbnail_url>");
- xmlSB.append("<biz_type name=\"业务类型\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getBizType());
- xmlSB.append("]]></biz_type>");
- xmlSB.append("<biz_id name=\"业务id\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getBizId());
- xmlSB.append("]]></biz_id>");
- xmlSB.append("<longitude name=\"移动app时有用\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getLongitude());
- xmlSB.append("]]></longitude>");
- xmlSB.append("<latitude name=\"移动app时有用\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getLatitude());
- xmlSB.append("]]></latitude>");
- xmlSB.append("<create_by name=\"创建人\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getCreateBy());
- xmlSB.append("]]></create_by>");
- // 请填写时间格式为:【yyyy/MM/dd HH:mm:ss】的数据
- xmlSB.append("<create_date name=\"创建日期\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(Date2Str(comFile.getCreateDate(),"yyyy-MM-dd HH:mm:ss"));
- xmlSB.append("]]></create_date>");
- xmlSB.append("<update_by name=\"最后修改人\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getUpdateBy());
- xmlSB.append("]]></update_by>");
- // 请填写时间格式为:【yyyy/MM/dd HH:mm:ss】的数据
- xmlSB.append("<update_date name=\"最后修改日期\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(Date2Str(comFile.getUpdateDate(),"yyyy-MM-dd HH:mm:ss"));
- xmlSB.append("]]></update_date>");
- xmlSB.append("<sn name=\"序号\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getSn());
- xmlSB.append("]]></sn>");
- xmlSB.append("<down_num name=\"下载次数\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getDownNum());
- xmlSB.append("]]></down_num>");
- xmlSB.append("<top name=\"是否置顶\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getTopValue());
- xmlSB.append("]]></top>");
- // 请填写时间格式为:【yyyy/MM/dd HH:mm:ss】的数据
- xmlSB.append("<top_date name=\"置顶日期\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(Date2Str(comFile.getTopDate(),"yyyy-MM-dd HH:mm:ss"));
- xmlSB.append("]]></top_date>");
- xmlSB.append("<filename name=\"附件名称\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getFileName());
- xmlSB.append("]]></filename>");
- xmlSB.append("</row>");
- }
- xmlSB.append("</table>");
- return xmlSB.toString();
- }
- /**
- * 把数据库的数据转换化为xml报文 删除
- * @author lxf
- * @date 2023/12/6 11:25
- */
- public static String getDeleteXmlStr(List<GwComFile> comFileList) {
- if(null == comFileList || comFileList.isEmpty()){
- return null;
- }
- StringBuffer xmlSB = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
- xmlSB.append("<table>");
- for(GwComFile comFile : comFileList){
- xmlSB.append("<row type=\"delete\">");
- // 设置字段
- xmlSB.append("<id name=\"主键\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getId());
- xmlSB.append("]]></id>");
- xmlSB.append("<file_title name=\"文件标题\" isattachment=\"true\"><![CDATA[");
- xmlSB.append(comFile.getFilePath().replace("\\","/").substring(7));
- xmlSB.append("]]></file_title>");
- xmlSB.append("<key_word name=\"关键词\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getKeyWord());
- xmlSB.append("]]></key_word>");
- xmlSB.append("<file_type name=\"音频视频文本图片等\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getFileType());
- xmlSB.append("]]></file_type>");
- xmlSB.append("<abs name=\"摘要\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getAbs());
- xmlSB.append("]]></abs>");
- xmlSB.append("<file_name name=\"原始文件名(包含扩展名)\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getFileName());
- xmlSB.append("]]></file_name>");
- xmlSB.append("<file_size name=\"文件大小\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getFileSize());
- xmlSB.append("]]></file_size>");
- xmlSB.append("<file_ext name=\"文件扩展名\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getFileExt());
- xmlSB.append("]]></file_ext>");
- xmlSB.append("<file_path name=\"文件路径\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getFilePath());
- xmlSB.append("]]></file_path>");
- xmlSB.append("<thumbnail_url name=\"缩略图路径\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getThumbnailUrl());
- xmlSB.append("]]></thumbnail_url>");
- xmlSB.append("<biz_type name=\"业务类型\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getBizType());
- xmlSB.append("]]></biz_type>");
- xmlSB.append("<biz_id name=\"业务id\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getBizId());
- xmlSB.append("]]></biz_id>");
- xmlSB.append("<longitude name=\"移动app时有用\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getLongitude());
- xmlSB.append("]]></longitude>");
- xmlSB.append("<latitude name=\"移动app时有用\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getLatitude());
- xmlSB.append("]]></latitude>");
- xmlSB.append("<create_by name=\"创建人\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getCreateBy());
- xmlSB.append("]]></create_by>");
- // 请填写时间格式为:【yyyy/MM/dd HH:mm:ss】的数据
- xmlSB.append("<create_date name=\"创建日期\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(Date2Str(comFile.getCreateDate(),"yyyy-MM-dd HH:mm:ss"));
- xmlSB.append("]]></create_date>");
- xmlSB.append("<update_by name=\"最后修改人\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getUpdateBy());
- xmlSB.append("]]></update_by>");
- // 请填写时间格式为:【yyyy/MM/dd HH:mm:ss】的数据
- xmlSB.append("<update_date name=\"最后修改日期\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(Date2Str(comFile.getUpdateDate(),"yyyy-MM-dd HH:mm:ss"));
- xmlSB.append("]]></update_date>");
- xmlSB.append("<sn name=\"序号\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getSn());
- xmlSB.append("]]></sn>");
- xmlSB.append("<down_num name=\"下载次数\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getDownNum());
- xmlSB.append("]]></down_num>");
- xmlSB.append("<top name=\"是否置顶\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getTopValue());
- xmlSB.append("]]></top>");
- // 请填写时间格式为:【yyyy/MM/dd HH:mm:ss】的数据
- xmlSB.append("<top_date name=\"置顶日期\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(Date2Str(comFile.getTopDate(),"yyyy-MM-dd HH:mm:ss"));
- xmlSB.append("]]></top_date>");
- xmlSB.append("<filename name=\"附件名称\" isattachment=\"false\"><![CDATA[");
- xmlSB.append(comFile.getFileName());
- xmlSB.append("]]></filename>");
- xmlSB.append("</row>");
- }
- xmlSB.append("</table>");
- return xmlSB.toString();
- }
- public static String Date2Str(Date date, String pattern) {
- if (date == null) {
- date = new Date() ;
- }
- SimpleDateFormat time = new SimpleDateFormat(pattern);
- time.setTimeZone(DateUtils.zone);
- return time.format(date);
- }
- public static String base64Encode(String source){
- if(StringUtils.isEmpty(source)){
- return source;
- }
- sun.misc.BASE64Encoder base64Encoder = new BASE64Encoder();
- try {
- String encoderStr = base64Encoder.encode(source.getBytes(CONTENT_CHARSET)) ;
- return encoderStr;
- } catch (UnsupportedEncodingException e) {
- logger.error("BASE64Encoder 加密异常",e);
- return null ;
- }
- }
- public static void main(String[] args) {
- String xmlStr= "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response><flag>false</flag><msg>guid已过期</msg></Response>";
- try {
- InputStream is = new ByteArrayInputStream(xmlStr.getBytes("UTF-8"));
- SAXReader reader = new SAXReader();
- Document doc = reader.read(is);
- Element root = doc.getRootElement();
- Iterator<Element> rootIterator = root.elementIterator();
- while (rootIterator.hasNext()){
- Element element2= rootIterator.next();
- System.out.println("HttpWSDLUtils pushData 118 result is " + element2.asXML());
- String nodeName = element2.getName();
- System.out.println("node name: " + nodeName);
- if("flag".equals(nodeName)){
- element2.getData();
- }
- System.out.println("node data: " + element2.getData());
- }
- is.close();
- } catch ( UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }catch (DocumentException e) {
- throw new RuntimeException(e);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- }
|