实例3:返回数组
2009-10-27 11:28
211 查看
Example3 (listCode() return String[]: all logincodes).
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 (should be put in the directory as: %webapp%/web-inf/classes/....)
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){ ... (same as example2)... }
}
4) LoginImpl.java (should be put in the directory of server side as: %webapp%/web-inf/classes/....)
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 String[] listCodes(){
List list = dao.list();
if(list!=null){
String[] codes = new String[list.size()];
for(int i=0;i<list.size();i++){
Tblogin login = (Tblogin) list.get(i);
log.info("the login result: number " + i + ", loginname=" + login.getLogincode().trim().toUpperCase());
codes[i] = login.getLogincode().trim().toUpperCase();
}
return codes;
}else{
log.info("there is no rows in the table Tblogin");
return null;
}
}
}
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:8080/axis/services/LoginService";
Service service = new Service();
Call call = (Call) service.createCall();
QName qn = new QName( "urn:LoginImpl", "Tblogin" );
call.registerTypeMapping(String[].class, qn,
new org.apache.axis.encoding.ser.ArraySerializerFactory(),
new org.apache.axis.encoding.ser.ArrayDeserializerFactory());
call.setTargetEndpointAddress( new java.net.URL(endpointURL) );
call.setOperationName( new QName("http://server.mytest.com.cn", "listCodes") );
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_ANYTYPE);
String[] names = (String[]) call.invoke(new Object[]{});
if(names!=null){
for(int i=0;i<names.length;i++){
String name = names[i];
System.out.println(name);
}
}
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
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 (should be put in the directory as: %webapp%/web-inf/classes/....)
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){ ... (same as example2)... }
}
4) LoginImpl.java (should be put in the directory of server side as: %webapp%/web-inf/classes/....)
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 String[] listCodes(){
List list = dao.list();
if(list!=null){
String[] codes = new String[list.size()];
for(int i=0;i<list.size();i++){
Tblogin login = (Tblogin) list.get(i);
log.info("the login result: number " + i + ", loginname=" + login.getLogincode().trim().toUpperCase());
codes[i] = login.getLogincode().trim().toUpperCase();
}
return codes;
}else{
log.info("there is no rows in the table Tblogin");
return null;
}
}
}
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:8080/axis/services/LoginService";
Service service = new Service();
Call call = (Call) service.createCall();
QName qn = new QName( "urn:LoginImpl", "Tblogin" );
call.registerTypeMapping(String[].class, qn,
new org.apache.axis.encoding.ser.ArraySerializerFactory(),
new org.apache.axis.encoding.ser.ArrayDeserializerFactory());
call.setTargetEndpointAddress( new java.net.URL(endpointURL) );
call.setOperationName( new QName("http://server.mytest.com.cn", "listCodes") );
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_ANYTYPE);
String[] names = (String[]) call.invoke(new Object[]{});
if(names!=null){
for(int i=0;i<names.length;i++){
String name = names[i];
System.out.println(name);
}
}
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
相关文章推荐
- php array_values 返回数组的所有值详解及实例
- Python返回数组/List长度的实例
- JS返回只包含数字类型的数组实例分析
- C/C++ 分割字符并返回字符数组实例
- php each 返回数组中当前的键值对并将数组指针向前移动一步实例
- C/C++ 分割字符并返回字符数组实例
- Activity经典实例:启动其他Activity并使用Bundle存储数组返回结果
- php array_values 返回数组的值实例详解
- php each 返回数组中当前的键值对并将数组指针向前移动一步实例
- 用JS编写一个函数,返回数组中重复出现过的元素(实例)
- php array_values 返回数组的值实例详解
- 给定一个数组和一个值,删除该值的所有实例并返回新长度。
- Android—JNI调用简单实例解析/Eclipse无添加NDK的选项/JNI返回数组
- VB6 用数组作函数参数并返回一个数组的实例
- php array_values 返回数组的所有值详解及实例
- php中json_decode返回数组或对象的实例
- php array_reverse 以相反的顺序返回数组实例代码
- 在C中如何使函数返回数组
- 用document.getElementsByTagName()返回的真的是数组吗?
- 返回空引用(null)还是返回零元素实例?