Example2 (getting Tblogin object)
1. mysql: database(spring), testing table(spring) (same as Example1)
2. axisclasspath: ...... D:/mydemos/axis_text/src (same as Example1)
3. java codes for server: (D:/mydemos/axis_text/src/)
a) hibernate.cfg.xml (same as Example1)
b) Tblogin.hbm.xml (same as Example1)
c). LoginDaoImpl.java
package cn.com.mytest.dao;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import org.hibernate.Session;
import org.hibernate.HibernateException;
import org.hibernate.Transaction;
import org.hibernate.Query;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
import cn.com.mytest.dao.hibernate.config.SessionFactoryClass;
public class LoginDaoImpl {
private static final Log log = LogFactory.getLog(LoginDaoImpl.class);
public void add(Serializable object){....(same as Example1)}
public List list(){... same as Example1...}
public Object get(Integer loginid){
Session session = null;
Tblogin login = new Tblogin();
try{
session = SessionFactoryClass.currentSession();
login = (Tblogin)session.get(Tblogin.class, loginid);
}catch(HibernateException hex){
log.error("add(Serializable object) error:" + hex.getMessage());
hex.printStackTrace();
}catch(Exception ex){
log.error("add(Serializable object) error:" + ex.getMessage());
ex.printStackTrace();
}finally{
SessionFactoryClass.closeSession();
}
return login;
}
}
4) LoginImpl.java
package cn.com.mytest.server;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import cn.com.mytest.dao.hibernate.Tblogin;
import cn.com.mytest.dao.LoginDaoImpl;
public class LoginImpl {
private static final Log log = LogFactory.getLog(LoginImpl.class);
LoginDaoImpl dao = new LoginDaoImpl();
public List list(){... same as Example1...}
public Integer count(){... same as Example1...}
public Object get(Integer loginid){
if(loginid==null || loginid.intValue()==0) return null;
return dao.get(loginid);
}
}
4. wsdd file: deploy.wsdd (cn/com/mytest/server/deploy.wsdd)
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="LoginService" provider="java:RPC">
<parameter name="className" value="cn.com.mytest.server.LoginImpl"/>
<parameter name="allowedMethods" value="*"/>
<beanMapping qname="myNS:Tblogin" xmlns:myNS="urn:LoginImpl" languageSpecificType="java:cn.com.mytest.dao.hibernate.Tblogin"/>
</service>
</deployment>
wsdd file: undeploy.wsdd(cn/com/mytest/server/undeploy.wsdd) (same as Example10
5) Testing from client:
package cn.com.mytest.client;
import java.util.List;
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class TestClient {
public static void main(String [] args)
{
try {
String endpointURL = "http://localhost:1234/axis/services/LoginService";
Service service = new Service();
Call call = (Call) service.createCall();
QName qn = new QName( "urn:LoginImpl", "Tblogin" );
call.registerTypeMapping(Tblogin.class, qn,
new org.apache.axis.encoding.ser.BeanSerializerFactory(Tblogin.class, qn),
new org.apache.axis.encoding.ser.BeanDeserializerFactory(Tblogin.class, qn));
call.setTargetEndpointAddress( new java.net.URL(endpointURL) );
call.setOperationName( new QName("http://server.mytest.com.cn", "get") );
call.addParameter( "arg1", XMLType.XSD_INTEGER, ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_ANYTYPE);
Tblogin login = (Tblogin) call.invoke(new Object[]{new Integer(3)});
System.out.println("login:=" + login.getLogincode());
} catch (Exception e) {
System.err.println(e.toString());
}
}
}