解决方案 »
- 中文乱码!!!求救!!————用JSTL 引用(import)外网页面时中文乱码怎么解决??
- myeclipse中hibernate逆向工程生产实体类问题
- 请教一个关于输入输出到txt文件的问题
- 在struts里使用泛型,谁用过,老是实例不了
- 急,Cxf的序列化问题!
- java执行sql server的select count的效率,怎么样写,效率最高?
- struts中request不能得到已保存的对象
- java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]用户 'sa' 登录失败。原因: 未与信任 SQL Server 连接
- 如何删除List中指定列
- 高手请进来,郁闷了好些阵子也,高手呀! --------------?????
- 求和公式 ∑ 没上下标时的含义
- 如何用java判断浏览器类型?
服务端实体对象:public class LineName implements java.io.Serializable {
private String lineid;
private String linename;
//getter and setter....
}
实体集对象,包装对象集:@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Lines")
public class Lines{
private List<LineName> lines;
private LineName[] lineArr;
private HashMap<String, LineName> maps;
//getter and setter....
List对象,包装ArrayList:@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "listObject", propOrder = { "list" })
public class ListObject {
@XmlElement(nillable = true)
protected List<Object> list;
public List<Object> getList() {
if (list == null) {
list = new ArrayList<Object>();
}
return this.list;
}
public void setList(ArrayList<Object> list) {
this.list = list;
}
}
服务接口:@WebService
public interface ITicketing_Service {
public ArrayList getLineAndStationList(String type,String str,String nc);
}
服务实现类:public ListObject getLineAndStationList(String type, String str,String nc) {
ArrayList<Object> list = new ArrayList<Object>();
TicketService_Logic logic = new TicketService_Logic();
Lines l = new Lines();
if(type.equals("1")){
//list = logic.getLineList(str);
List<LineName> lines = new ArrayList<LineName>();
for(int i=0;i<10;i++){
LineName line = new LineName();
line.setLineid("0001"+i);
line.setLinename("北京线"+i);
lines.add(line);
}
l.setLines(lines);
list.add("0");
list.add(l);
}
ListObject listObject = new ListObject();
listObject.setList(list);
return listObject;
}
客户端调用服务代码:public class TicketServiceClient {
public static void main(String[] args){
TicketServiceClient.doSpringClient();
// System.out.println(TicketServiceClient.doNormalClient("Michael",90));
}
private static ArrayList doSpringClient(){
// 加载客户端的配置定义
ApplicationContext context =
new FileSystemXmlApplicationContext("src/com/ws/client/beanRefClient.xml");
// 获取定义的 Web Service Bean
ITicketing_Service ticketingService = (ITicketing_Service)context.getBean("ticketServiceClient");
//1
ListObject l1 = (ListObject) ticketingService.getLineAndStationList("1", "", "");
List<Object> linesinfo = l1.getList();
System.out.println(linesinfo.get(0));
Lines lines = (Lines) linesinfo.get(1);
for (LineName line : lines.getLines()) {
System.out.println(line.getLineid());
System.out.println(line.getLinename());
}
}
服务端spring配置文件:beanRefServer.xml<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.0.xsd"
default-lazy-init="false">
<!-- Import Apache CXF Bean Definition -->
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/> <jaxws:endpoint id="ticketing_Service"
implementor="com.ws.server.impl.Ticketing_Service"
address="/Ticketing_Service" />
<bean id="Lines" name="Lines" class="com.ws.server.entity.Lines"></bean>
<bean id="Stations" name="Stations" class="com.ws.server.entity.Stations"></bean>
<bean id="Sellagents" name="Sellagents" class="com.ws.server.entity.Sellagents"></bean>
<bean id="Waitstations" name="Waitstations" class="com.ws.server.entity.Waitstations"></bean>
<bean id="BusSeats" name="BusSeats" class="com.ws.server.entity.BusSeats"></bean>
<bean id="PricesTypes" name="PricesTypes" class="com.ws.server.entity.PricesTypes"></bean>
<bean id="BusPrices" name="BusPrices" class="com.ws.server.entity.BusPrices"></bean>
<bean id="TicketBuses" name="TicketBuses" class="com.ws.server.entity.TicketBuses"></bean>
</beans>
客户端spring配置文件:beanRefClient.xml<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<!-- Import Apache CXF Bean Definition -->
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<!-- <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/> -->
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<!-- Ticketing_Service Client -->
<jaxws:client id="ticketServiceClient"
serviceClass="com.ws.server.ITicketing_Service"
address="http://localhost:8888/NewPtmanager/Ticketing_Service"/>
<bean id="Lines" name="Lines" class="com.ws.server.entity.Lines"></bean>
<bean id="Stations" name="Stations" class="com.ws.server.entity.Stations"></bean>
<bean id="Sellagents" name="Sellagents" class="com.ws.server.entity.Sellagents"></bean>
<bean id="Waitstations" name="Waitstations" class="com.ws.server.entity.Waitstations"></bean>
<bean id="BusSeats" name="BusSeats" class="com.ws.server.entity.BusSeats"></bean>
<bean id="PricesTypes" name="PricesTypes" class="com.ws.server.entity.PricesTypes"></bean>
<bean id="BusPrices" name="BusPrices" class="com.ws.server.entity.BusPrices"></bean>
<bean id="TicketBuses" name="TicketBuses" class="com.ws.server.entity.TicketBuses"></bean></beans>