SOAP WebService 发布全过程
package com.transnal.ws.cnlif.service;public interface UnifiedAuthService extends java.rmi.Remote {/** * 认证接口 * * 第三方系统将这个Token置入Cookie中 * @param loginId * 用户登陆帐号 * @param password * 用户登陆密码 * @param remoteIp * 用户登陆IP * @return * 认证通过,返回加密后的Token * @throws java.rmi.RemoteException */ public java.lang.String authenticate(java.lang.String loginId, java.lang.String password, java.lang.String remoteIp) throws java.rmi.RemoteException; /** * 验证接口 * * 用户漫游到第三方系统时,第三方系统将Cookie中的loginId和Token提交到统一认证中心进行验证, * 验证该token是否合法。 * * @param loginId * Cookie获取的登陆帐号 * @param token * Cookie中获取的全网通行token * @param remoteIp * 用户登陆IP * @return * @throws java.rmi.RemoteException */ public java.lang.String validate(java.lang.String loginId, java.lang.String token, java.lang.String remoteIp) throws java.rmi.RemoteException; /** * 根据登录ID获取用户基本信息 * @param loginId * @return * @throws java.rmi.RemoteException */ public com.transnal.ws.cnlif.bean.User getUserBaseInfoByLoginId(java.lang.String loginId) throws java.rmi.RemoteException; /** * 注册接口 * * 仅提供简单的手机注册。注册成功,返回一个User对象,否则返回null。 * * @param msisdn * 用户手机号 * @param usertype * 用户类型 * @return * 用户信息 * @throws java.rmi.RemoteException */ public com.transnal.ws.cnlif.bean.User createUserBaseInfoByMsisdn(java.lang.String msisdn, java.lang.String usertype) throws java.rmi.RemoteException; /** * 注册接口 * * @param msisdn * 用户手机号 * @return * 用户信息 * @throws java.rmi.RemoteException */ public com.transnal.ws.cnlif.bean.User createUserBaseInfoByMsisdn(java.lang.String msisdn) throws java.rmi.RemoteException; }
package com.transnal.ws.cnlif.service;public interface UnifiedAuthServiceService extends javax.xml.rpc.Service { public java.lang.String getUnifiedAuthServiceAddress(); public com.transnal.ws.cnlif.service.UnifiedAuthService getUnifiedAuthService() throws javax.xml.rpc.ServiceException; public com.transnal.ws.cnlif.service.UnifiedAuthService getUnifiedAuthService(java.net.URL portAddress) throws javax.xml.rpc.ServiceException; }
package com.transnal.ws.cnlif.service;import java.util.ResourceBundle;@SuppressWarnings("serial")public class UnifiedAuthServiceServiceLocator extendsorg.apache.axis.client.Service implementscom.transnal.ws.cnlif.service.UnifiedAuthServiceService {public UnifiedAuthServiceServiceLocator() {}public UnifiedAuthServiceServiceLocator(org.apache.axis.EngineConfiguration config) {super(config);}public UnifiedAuthServiceServiceLocator(java.lang.String wsdlLoc,javax.xml.namespace.QName sName)throws javax.xml.rpc.ServiceException {super(wsdlLoc, sName);}// Use to get a proxy class for UnifiedAuthServiceprivate java.lang.String UnifiedAuthService_address = ResourceBundle.getBundle("spring-jpa").getString("ws.unifiedAuthServiceAddress");public java.lang.String getUnifiedAuthServiceAddress() {return UnifiedAuthService_address;}// The WSDD service name defaults to the port name.private java.lang.String UnifiedAuthServiceWSDDServiceName = "UnifiedAuthService";public java.lang.String getUnifiedAuthServiceWSDDServiceName() {return UnifiedAuthServiceWSDDServiceName;}public void setUnifiedAuthServiceWSDDServiceName(java.lang.String name) {UnifiedAuthServiceWSDDServiceName = name;}public com.transnal.ws.cnlif.service.UnifiedAuthService getUnifiedAuthService()throws javax.xml.rpc.ServiceException {java.net.URL endpoint;try {endpoint = new java.net.URL(UnifiedAuthService_address);} catch (java.net.MalformedURLException e) {throw new javax.xml.rpc.ServiceException(e);}return getUnifiedAuthService(endpoint);}public com.transnal.ws.cnlif.service.UnifiedAuthService getUnifiedAuthService(java.net.URL portAddress) throws javax.xml.rpc.ServiceException {try {com.transnal.ws.cnlif.service.UnifiedAuthServiceSoapBindingStub _stub = new com.transnal.ws.cnlif.service.UnifiedAuthServiceSoapBindingStub(portAddress, this);_stub.setPortName(getUnifiedAuthServiceWSDDServiceName());return _stub;} catch (org.apache.axis.AxisFault e) {return null;}}public void setUnifiedAuthServiceEndpointAddress(java.lang.String address) {UnifiedAuthService_address = address;}/** * For the given interface, get the stub implementation. If this service has * no port for the given interface, then ServiceException is thrown. */@SuppressWarnings("unchecked")public java.rmi.Remote getPort(Class serviceEndpointInterface)throws javax.xml.rpc.ServiceException {try {if (com.transnal.ws.cnlif.service.UnifiedAuthService.class.isAssignableFrom(serviceEndpointInterface)) {com.transnal.ws.cnlif.service.UnifiedAuthServiceSoapBindingStub _stub = new com.transnal.ws.cnlif.service.UnifiedAuthServiceSoapBindingStub(new java.net.URL(UnifiedAuthService_address), this);_stub.setPortName(getUnifiedAuthServiceWSDDServiceName());return _stub;}} catch (java.lang.Throwable t) {throw new javax.xml.rpc.ServiceException(t);}throw new javax.xml.rpc.ServiceException("There is no stub implementation for the interface: "+ (serviceEndpointInterface == null ? "null": serviceEndpointInterface.getName()));}/** * For the given interface, get the stub implementation. If this service has * no port for the given interface, then ServiceException is thrown. */@SuppressWarnings("unchecked")public java.rmi.Remote getPort(javax.xml.namespace.QName portName,Class serviceEndpointInterface)throws javax.xml.rpc.ServiceException {if (portName == null) {return getPort(serviceEndpointInterface);}java.lang.String inputPortName = portName.getLocalPart();if ("UnifiedAuthService".equals(inputPortName)) {return getUnifiedAuthService();} else {java.rmi.Remote _stub = getPort(serviceEndpointInterface);((org.apache.axis.client.Stub) _stub).setPortName(portName);return _stub;}}public javax.xml.namespace.QName getServiceName() {return new javax.xml.namespace.QName(UnifiedAuthService_address,"UnifiedAuthServiceService");}@SuppressWarnings("unchecked")private java.util.HashSet ports = null;@SuppressWarnings("unchecked")public java.util.Iterator getPorts() {if (ports == null) {ports = new java.util.HashSet();ports.add(new javax.xml.namespace.QName(UnifiedAuthService_address,"UnifiedAuthService"));}return ports.iterator();}/** * Set the endpoint address for the specified port name. */public void setEndpointAddress(java.lang.String portName,java.lang.String address) throws javax.xml.rpc.ServiceException {if ("UnifiedAuthService".equals(portName)) {setUnifiedAuthServiceEndpointAddress(address);} else { // Unknown Port Namethrow new javax.xml.rpc.ServiceException(" Cannot set Endpoint Address for Unknown Port" + portName);}}/** * Set the endpoint address for the specified port name. */public void setEndpointAddress(javax.xml.namespace.QName portName,java.lang.String address) throws javax.xml.rpc.ServiceException {setEndpointAddress(portName.getLocalPart(), address);}}
package com.transnal.ws.cnlif.service;import java.util.ResourceBundle;import com.transnal.ws.cnlif.bean.User;@SuppressWarnings("unchecked")public class UnifiedAuthServiceSoapBindingStub extends org.apache.axis.client.Stub implements UnifiedAuthService {private java.util.Vector cachedSerClasses = new java.util.Vector(); private java.util.Vector cachedSerQNames = new java.util.Vector(); private java.util.Vector cachedSerFactories = new java.util.Vector(); private java.util.Vector cachedDeserFactories = new java.util.Vector(); private java.lang.String username = ResourceBundle.getBundle("spring-jpa").getString("ws.username"); private java.lang.String password = ResourceBundle.getBundle("spring-jpa").getString("ws.password"); static org.apache.axis.description.OperationDesc [] _operations; static { // 此處說明 UnifeedAuthService 接口中 有 5 個方法 _operations = new org.apache.axis.description.OperationDesc[5]; _initOperationDesc1(); } private static void _initOperationDesc1(){ // 設置 UnifeAuthService 中所有的接口 org.apache.axis.description.OperationDesc oper; org.apache.axis.description.ParameterDesc param; oper = new org.apache.axis.description.OperationDesc(); oper.setName("authenticate"); param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("", "loginId"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/encoding/", "string"), java.lang.String.class, false, false); oper.addParameter(param); param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("", "password"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/encoding/", "string"), java.lang.String.class, false, false); oper.addParameter(param); param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("", "remoteIp"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/encoding/", "string"), java.lang.String.class, false, false); oper.addParameter(param); oper.setReturnType(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/encoding/", "string")); oper.setReturnClass(java.lang.String.class); oper.setReturnQName(new javax.xml.namespace.QName("", "authenticateReturn")); oper.setStyle(org.apache.axis.constants.Style.RPC); oper.setUse(org.apache.axis.constants.Use.ENCODED); _operations[0] = oper; oper = new org.apache.axis.description.OperationDesc(); oper.setName("validate"); param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("", "loginId"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/encoding/", "string"), java.lang.String.class, false, false); oper.addParameter(param); param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("", "token"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/encoding/", "string"), java.lang.String.class, false, false); oper.addParameter(param); param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("", "remoteIp"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/encoding/", "string"), java.lang.String.class, false, false); oper.addParameter(param); oper.setReturnType(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/encoding/", "string")); oper.setReturnClass(java.lang.String.class); oper.setReturnQName(new javax.xml.namespace.QName("", "validateReturn")); oper.setStyle(org.apache.axis.constants.Style.RPC); oper.setUse(org.apache.axis.constants.Use.ENCODED); _operations[1] = oper; oper = new org.apache.axis.description.OperationDesc(); oper.setName("getUserBaseInfoByLoginId"); param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("", "loginId"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/encoding/", "string"), java.lang.String.class, false, false); oper.addParameter(param); oper.setReturnType(new javax.xml.namespace.QName("urn:BeanService", "user")); oper.setReturnClass(User.class); oper.setReturnQName(new javax.xml.namespace.QName("", "getUserBaseInfoByLoginIdReturn")); oper.setStyle(org.apache.axis.constants.Style.RPC); oper.setUse(org.apache.axis.constants.Use.ENCODED); _operations[2] = oper; oper = new org.apache.axis.description.OperationDesc(); oper.setName("createUserBaseInfoByMsisdn"); param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("", "msisdn"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/encoding/", "string"), java.lang.String.class, false, false); oper.addParameter(param); param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("", "usertype"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/encoding/", "string"), java.lang.String.class, false, false); oper.addParameter(param); oper.setReturnType(new javax.xml.namespace.QName("urn:BeanService", "user")); oper.setReturnClass(User.class); oper.setReturnQName(new javax.xml.namespace.QName("", "createUserBaseInfoByMsisdnReturn")); oper.setStyle(org.apache.axis.constants.Style.RPC); oper.setUse(org.apache.axis.constants.Use.ENCODED); _operations[3] = oper; oper = new org.apache.axis.description.OperationDesc(); oper.setName("createUserBaseInfoByMsisdn"); param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("", "msisdn"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/encoding/", "string"), java.lang.String.class, false, false); oper.addParameter(param); oper.setReturnType(new javax.xml.namespace.QName("urn:BeanService", "user")); oper.setReturnClass(User.class); oper.setReturnQName(new javax.xml.namespace.QName("", "createUserBaseInfoByMsisdnReturn")); oper.setStyle(org.apache.axis.constants.Style.RPC); oper.setUse(org.apache.axis.constants.Use.ENCODED); _operations[4] = oper; } public UnifiedAuthServiceSoapBindingStub() throws org.apache.axis.AxisFault { this(null); } public UnifiedAuthServiceSoapBindingStub(java.net.URL endpointURL, javax.xml.rpc.Service service) throws org.apache.axis.AxisFault { this(service); super.cachedEndpoint = endpointURL; } @SuppressWarnings("unused") public UnifiedAuthServiceSoapBindingStub(javax.xml.rpc.Service service) throws org.apache.axis.AxisFault { if (service == null) { super.service = new org.apache.axis.client.Service(); } else { super.service = service; } ((org.apache.axis.client.Service)super.service).setTypeMappingVersion("1.2"); java.lang.Class cls; javax.xml.namespace.QName qName;javax.xml.namespace.QName qName2; java.lang.Class beansf = org.apache.axis.encoding.ser.BeanSerializerFactory.class; java.lang.Class beandf = org.apache.axis.encoding.ser.BeanDeserializerFactory.class; java.lang.Class enumsf = org.apache.axis.encoding.ser.EnumSerializerFactory.class; java.lang.Class enumdf = org.apache.axis.encoding.ser.EnumDeserializerFactory.class; java.lang.Class arraysf = org.apache.axis.encoding.ser.ArraySerializerFactory.class; java.lang.Class arraydf = org.apache.axis.encoding.ser.ArrayDeserializerFactory.class; java.lang.Class simplesf = org.apache.axis.encoding.ser.SimpleSerializerFactory.class; java.lang.Class simpledf = org.apache.axis.encoding.ser.SimpleDeserializerFactory.class; java.lang.Class simplelistsf = org.apache.axis.encoding.ser.SimpleListSerializerFactory.class; java.lang.Class simplelistdf = org.apache.axis.encoding.ser.SimpleListDeserializerFactory.class; qName = new javax.xml.namespace.QName("urn:BeanService", "user"); cachedSerQNames.add(qName); cls = User.class; cachedSerClasses.add(cls); cachedSerFactories.add(beansf); cachedDeserFactories.add(beandf); } protected org.apache.axis.client.Call createCall() throws java.rmi.RemoteException { try { org.apache.axis.client.Call _call = super._createCall(); if (super.maintainSessionSet) { _call.setMaintainSession(super.maintainSession); } if (super.cachedUsername != null) { _call.setUsername(super.cachedUsername); } if (super.cachedPassword != null) { _call.setPassword(super.cachedPassword); } if (super.cachedEndpoint != null) { _call.setTargetEndpointAddress(super.cachedEndpoint); } if (super.cachedTimeout != null) { _call.setTimeout(super.cachedTimeout); } if (super.cachedPortName != null) { _call.setPortName(super.cachedPortName); } java.util.Enumeration keys = super.cachedProperties.keys(); while (keys.hasMoreElements()) { java.lang.String key = (java.lang.String) keys.nextElement(); _call.setProperty(key, super.cachedProperties.get(key)); } // All the type mapping information is registered // when the first call is made. // The type mapping information is actually registered in // the TypeMappingRegistry of the service, which // is the reason why registration is only needed for the first call. synchronized (this) { if (firstCall()) { // must set encoding style before registering serializers _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS); _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP11_ENC); for (int i = 0; i < cachedSerFactories.size(); ++i) { java.lang.Class cls = (java.lang.Class) cachedSerClasses.get(i); javax.xml.namespace.QName qName = (javax.xml.namespace.QName) cachedSerQNames.get(i); java.lang.Object x = cachedSerFactories.get(i); if (x instanceof Class) { java.lang.Class sf = (java.lang.Class) cachedSerFactories.get(i); java.lang.Class df = (java.lang.Class) cachedDeserFactories.get(i); _call.registerTypeMapping(cls, qName, sf, df, false); } else if (x instanceof javax.xml.rpc.encoding.SerializerFactory) { org.apache.axis.encoding.SerializerFactory sf = (org.apache.axis.encoding.SerializerFactory) cachedSerFactories.get(i); org.apache.axis.encoding.DeserializerFactory df = (org.apache.axis.encoding.DeserializerFactory) cachedDeserFactories.get(i); _call.registerTypeMapping(cls, qName, sf, df, false); } } } } _call.getMessageContext().setUsername(username); _call.getMessageContext().setPassword(password); return _call; } catch (java.lang.Throwable _t) { throw new org.apache.axis.AxisFault("Failure trying to get the Call object", _t); } } public java.lang.String authenticate(java.lang.String loginId, java.lang.String password, java.lang.String remoteIp) throws java.rmi.RemoteException { if (super.cachedEndpoint == null) { throw new org.apache.axis.NoEndPointException(); } org.apache.axis.client.Call _call = createCall(); _call.setOperation(_operations[0]); _call.setUseSOAPAction(true); _call.setSOAPActionURI(""); _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS); _call.setOperationName(new javax.xml.namespace.QName("http://services.uas.cnlife.com", "authenticate")); setRequestHeaders(_call); setAttachments(_call); try { java.lang.Object _resp = _call.invoke(new java.lang.Object[] {loginId, password, remoteIp}); if (_resp instanceof java.rmi.RemoteException) { throw (java.rmi.RemoteException)_resp; } else { extractAttachments(_call); try { return (java.lang.String) _resp; } catch (java.lang.Exception _exception) { return (java.lang.String) org.apache.axis.utils.JavaUtils.convert(_resp, java.lang.String.class); } } }catch (org.apache.axis.AxisFault axisFaultException) { throw axisFaultException; } } public java.lang.String validate(java.lang.String loginId, java.lang.String token, java.lang.String remoteIp) throws java.rmi.RemoteException { if (super.cachedEndpoint == null) { throw new org.apache.axis.NoEndPointException(); } org.apache.axis.client.Call _call = createCall(); _call.setOperation(_operations[1]); _call.setUseSOAPAction(true); _call.setSOAPActionURI(""); _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS); _call.setOperationName(new javax.xml.namespace.QName("http://services.uas.cnlife.com", "validate")); setRequestHeaders(_call); setAttachments(_call); try { java.lang.Object _resp = _call.invoke(new java.lang.Object[] {loginId, token, remoteIp}); if (_resp instanceof java.rmi.RemoteException) { throw (java.rmi.RemoteException)_resp; } else { extractAttachments(_call); try { return (java.lang.String) _resp; } catch (java.lang.Exception _exception) { return (java.lang.String) org.apache.axis.utils.JavaUtils.convert(_resp, java.lang.String.class); } } } catch (org.apache.axis.AxisFault axisFaultException) { throw axisFaultException; } } public User getUserBaseInfoByLoginId(java.lang.String loginId) throws java.rmi.RemoteException { if (super.cachedEndpoint == null) { throw new org.apache.axis.NoEndPointException(); } org.apache.axis.client.Call _call = createCall(); _call.setOperation(_operations[2]); _call.setUseSOAPAction(true); _call.setSOAPActionURI(""); _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS); _call.setOperationName(new javax.xml.namespace.QName("http://services.uas.cnlife.com", "getUserBaseInfoByLoginId")); setRequestHeaders(_call); setAttachments(_call); try { java.lang.Object _resp = _call.invoke(new java.lang.Object[] {loginId}); if (_resp instanceof java.rmi.RemoteException) { throw (java.rmi.RemoteException)_resp; } else { extractAttachments(_call); try { return (User) _resp; } catch (java.lang.Exception _exception) { return (User) org.apache.axis.utils.JavaUtils.convert(_resp, User.class); } } } catch (org.apache.axis.AxisFault axisFaultException) { throw axisFaultException; } } public User createUserBaseInfoByMsisdn(java.lang.String msisdn, java.lang.String usertype) throws java.rmi.RemoteException { if (super.cachedEndpoint == null) { throw new org.apache.axis.NoEndPointException(); } org.apache.axis.client.Call _call = createCall(); _call.setOperation(_operations[3]); _call.setUseSOAPAction(true); _call.setSOAPActionURI(""); _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS); _call.setOperationName(new javax.xml.namespace.QName("http://services.uas.cnlife.com", "createUserBaseInfoByMsisdn")); setRequestHeaders(_call); setAttachments(_call); try { java.lang.Object _resp = _call.invoke(new java.lang.Object[] {msisdn, usertype}); if (_resp instanceof java.rmi.RemoteException) { throw (java.rmi.RemoteException)_resp; } else { extractAttachments(_call); try { return (User) _resp; } catch (java.lang.Exception _exception) { return (User) org.apache.axis.utils.JavaUtils.convert(_resp, User.class); } } }catch (org.apache.axis.AxisFault axisFaultException) { throw axisFaultException; } } public User createUserBaseInfoByMsisdn(java.lang.String msisdn) throws java.rmi.RemoteException { if (super.cachedEndpoint == null) { throw new org.apache.axis.NoEndPointException(); } org.apache.axis.client.Call _call = createCall(); _call.setOperation(_operations[4]); _call.setUseSOAPAction(true); _call.setSOAPActionURI(""); _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS); _call.setOperationName(new javax.xml.namespace.QName("http://services.uas.cnlife.com", "createUserBaseInfoByMsisdn")); setRequestHeaders(_call); setAttachments(_call); try { java.lang.Object _resp = _call.invoke(new java.lang.Object[] {msisdn}); if (_resp instanceof java.rmi.RemoteException) { throw (java.rmi.RemoteException)_resp; } else { extractAttachments(_call); try { return (User) _resp; } catch (java.lang.Exception _exception) { return (User) org.apache.axis.utils.JavaUtils.convert(_resp, User.class); } } } catch (org.apache.axis.AxisFault axisFaultException) { throw axisFaultException; } }}
public boolean userIsExist(String username) {[color=red]UnifiedAuthService [/color]service;try {service = new [color=red]UnifiedAuthServiceServiceLocator[/color]().getUnifiedAuthService();User user = service.getUserBaseInfoByLoginId(username);if (user != null) {return true;}} catch (Exception e) {}return false;}