webservice android 设置head头发送 获取
发布时间:2020-12-16 23:30:47 所属栏目:安全 来源:网络整理
导读:android 发送方法 //里面地址对应上面图片的namespace SoapObject request = new SoapObject("http://webservice.wzkj.com/","hello"); //这个是配置参数 request.addProperty("name","dddddddddddd"); SoapSerializationEnvelope envelope = new SoapSerial
android 发送方法 //里面地址对应上面图片的namespace SoapObject request = new SoapObject("http://webservice.wzkj.com/","hello"); //这个是配置参数 request.addProperty("name","dddddddddddd"); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); Element[] header = new Element[1]; header[0] = new Element().createElement("http://webservice.wzkj.com/","hello"); header[0].setAttribute("http://webservice.wzkj.com/","token","xiebuqing"); envelope.headerOut=header; envelope.bodyOut = request; envelope.setOutputSoapObject(request); // 设置是否调用的是dotNet开发的WebService envelope.dotNet = false; try { //对应图片上的soap:address HttpTransportSE androidHttpTransport = new HttpTransportSE("http://127.0.0.1:8080/wzkj/webservice/helloworld"); //call的第一个参数对应图片上的soapAction="" androidHttpTransport.call("",envelope); SoapObject result = (SoapObject)envelope.bodyIn; //这里我获取第一个数据 System.out.println(result.getProperty(0).toString()); } catch (Exception e) { e.printStackTrace(); } 通过抓包工工具获取到格式 <v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"> <v:Header> <n0:hello n0:token="xiebuqing" xmlns:n0="http://webservice.wzkj.com/" /> </v:Header> <v:Body> <n1:hello id="o0" c:root="1" xmlns:n1="http://webservice.wzkj.com/"> <name i:type="d:string"> dddddddddddd </name> </n1:hello> </v:Body> </v:Envelope> web 端口发送的格式 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header> <tns:RequestSOAPHeader xmlns:tns="http://192.168.1.113:8080/wzkj/webservice/helloworld"> <tns:spId> zhong </tns:spId> <tns:spPassword> guo </tns:spPassword> </tns:RequestSOAPHeader> </soap:Header> <ns2:hello xmlns:ns2="http://webservice.wzkj.com/"> <name> ddd </name> </ns2:hello> </soap:Body> </soap:Envelope> 在head中两个格式不一样需要在获取的时候作解析 /** * @FileName : SOAPAuthIntercepter * @Copy Right : WZKJ Technology Ltd * @Comments : soap认证拦截器 * @Author :liyulong * @Create Date: 2014.6.23 * @Modified By: * @Modified Date: * @Why & What is modified * @version : 1.0 */ package com.wzkj.webservice.auth; import java.util.List; import javax.xml.soap.SOAPException; import javax.xml.soap.SOAPHeader; import javax.xml.soap.SOAPMessage; import org.apache.cxf.binding.soap.SoapHeader; import org.apache.cxf.binding.soap.SoapMessage; import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor; import org.apache.cxf.headers.Header; import org.apache.cxf.interceptor.Fault; import org.apache.cxf.phase.AbstractPhaseInterceptor; import org.apache.cxf.phase.Phase; import org.springframework.beans.factory.annotation.Autowired; import org.w3c.dom.Element; import com.wzkj.core.util.BlowfishUtil; import com.wzkj.web.entity.Ciphertext; import com.wzkj.web.mapper.CipherTextMapper; public class SOAPAuthIntercepter extends AbstractPhaseInterceptor<SoapMessage>{ private SAAJInInterceptor saa = new SAAJInInterceptor(); public String token; @Autowired private CipherTextMapper cipherTextMapper; public SOAPAuthIntercepter(String phase) { super(phase); } public SOAPAuthIntercepter(){ // 指定该拦截器在哪个阶段被激发 super(Phase.PRE_INVOKE); } /** * 处理消息 * */ public void handleMessage(SoapMessage message) throws Fault { SOAPMessage mess = message.getContent(SOAPMessage.class); //判断消息是否为空 if (mess == null) { saa.handleMessage(message); mess = message.getContent(SOAPMessage.class); } SOAPHeader head = null; try { head = mess.getSOAPHeader(); } catch (Exception e) { e.printStackTrace(); } if (head == null) { throw new Fault(new SOAPException("SOAP消息头格式不对!")); } // 获取SOAP消息的全部头 List<Header> headers = message.getHeaders(); if (null == headers || headers.size() < 1) { throw new Fault(new SOAPException("SOAP消息头格式不对!")); } //认证token令牌 if(!checkQnameHeader(headers)){ throw new Fault(new SOAPException("认证失败")); } } /** * 认证token令牌 * @param headers 消息体 * @return boolean */ private boolean checkQnameHeader(List<Header> headers) { SoapHeader soapHeader = (SoapHeader) headers.get(0); Element element = (Element) soapHeader.getObject(); String token = element.getAttribute("n0:token"); Ciphertext cipher = cipherTextMapper.getById(1); BlowfishUtil chiper = new BlowfishUtil(cipher.getKey()); String value = chiper.decryptString(token); return value.equals(cipher.getText()); } public String getToken() { return token; } public void setToken(String token) { this.token = token; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- yum安装gcc报错kernel-headers
- 如何在编译Build.scala时设置SBT使用的scalacOptions?
- shell 读取数据表 并赋值给变量
- scala – 仅用于生成setter的@BeanProperty
- 通过yum升级gcc/g++至版本4.8.2
- angular2中使用ng2-charts (angular-cli创建项目)
- 在angularjs中的ng-bind中使用过滤器后添加更多文本
- angularjs – Angular ng-model在编辑时设置为undefined
- bzoj E. Bash Plays with Functions
- 在当前项目和插件组中找不到前缀’docker’的插件