在实现过程中,遇到两个问题:

1: schema 写错:

错误: http://myschool.com/schemas/st

正确: http://myschool.com/st/schemas    ---- schemas必须结尾才是schema  这个决定了Namspace

2: Response 对 server 端有 response 返回 需要通过采用jaxb实现

配置如下:

package school.info.pojo;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement; import org.springframework.stereotype.Component; @Component
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class FindByIdResponse { private Student student; public Student getStudent() {
return student;
} public void setStudent(Student student) {
this.student = student;
} }
package school.info.endpoint;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.Namespace;
import org.jdom2.filter.Filters;
import org.jdom2.xpath.XPathExpression;
import org.jdom2.xpath.XPathFactory;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload; import school.info.pojo.FindAllStudentsResponse;
import school.info.pojo.FindByIdResponse;
import school.info.pojo.Student;
import school.info.service.IStudentService;
import school.info.service.StudentService; @Endpoint
public class StudentInfoEndpoint { private static final String namespace_schema="http://myschool.com/st/schemas"; private IStudentService service=new StudentService();; private XPathExpression<Element> ageExpression;
private XPathExpression<Element> nameExpression;
private XPathExpression<Element> passwordExpression;
private XPathExpression<Element> studentIdExpression;
private XPathExpression<Element> levelExpression; public StudentInfoEndpoint() throws JDOMException{
Namespace namespace=Namespace.getNamespace("st",namespace_schema);
XPathFactory xpathFactory = XPathFactory.instance();
studentIdExpression = xpathFactory.compile("//st:StudentId",Filters.element(),null,namespace);
nameExpression = xpathFactory.compile("//st:Name",Filters.element(),null,namespace);
passwordExpression = xpathFactory.compile("//st:Password",Filters.element(),null,namespace);
ageExpression = xpathFactory.compile("//st:Age",Filters.element(),null,namespace);
levelExpression = xpathFactory.compile("//st:Level",Filters.element(),null,namespace);
} @PayloadRoot(namespace = namespace_schema, localPart = "RegisterRequest")
public void handleRegisterRequest(@RequestPayload Element registerRequest){
String name=nameExpression.evaluate(registerRequest).get(0).getValue();
String password=passwordExpression.evaluate(registerRequest).get(0).getValue();
String age_str=ageExpression.evaluate(registerRequest).get(0).getValue();
long age=Long.parseLong(age_str);
String level=levelExpression.evaluate(registerRequest).get(0).getValue();
System.out.println(name+":"+password+":"+age+":"+level);
service.register(name, password, age, level);
}
@PayloadRoot(namespace = namespace_schema, localPart = "UpdateRequest")
public void handleUpdateRequest(@RequestPayload Element updateRequest){
long studentId=Long.parseLong(studentIdExpression.evaluate(updateRequest).get(0).getValue());
String name=nameExpression.evaluate(updateRequest).get(0).getValue();
String password=passwordExpression.evaluate(updateRequest).get(0).getValue();
String age_str=ageExpression.evaluate(updateRequest).get(0).getValue();
long age=Long.parseLong(age_str);
String level=levelExpression.evaluate(updateRequest).get(0).getValue();
service.update(name, password, age, level,studentId);
}
@PayloadRoot(namespace = namespace_schema, localPart = "DeleteRequest")
public void handleDeleteRequest(@RequestPayload Element deleteRequest){
long studentId=Long.parseLong(studentIdExpression.evaluate(deleteRequest).get(0).getValue());
service.delete(studentId);
}
@PayloadRoot(namespace = namespace_schema, localPart = "FindByIdRequest")
@ResponsePayload
public FindByIdResponse handleFindByIdRequest(@RequestPayload Element findByIdRequest){
long studentId=Long.parseLong(studentIdExpression.evaluate(findByIdRequest).get(0).getValue());
Student stu=service.findById(studentId);
FindByIdResponse response=new FindByIdResponse();
response.setStudent(stu);
return response;
}
@PayloadRoot(namespace = namespace_schema, localPart = "FindAllStudentsRequest")
@ResponsePayload
public FindAllStudentsResponse handleFindAllStudentsRequest(@RequestPayload Element FindAllStudentsRequest){
//long studentId=Long.parseLong(studentIdExpression.evaluate(FindAllStudentsRequest).get(0).getValue());
List list=service.findAllStudents();
List<Student> students=new ArrayList<Student>();
Iterator ir=list.iterator();
while(ir.hasNext()){
Object[] tuple=(Object[])ir.next();
Student s=new Student();
s.setStudentId(Long.parseLong(tuple[0].toString()));
s.setName(tuple[1].toString());
s.setLevel(tuple[2].toString());
s.setAge(Long.parseLong(tuple[3].toString()));
s.setPassword(tuple[4].toString());
students.add(s);
}
FindAllStudentsResponse all=new FindAllStudentsResponse();
all.setList(students);
return all;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:st="http://myschool.com/st/schemas" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://myschool.com/stu/definitions" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://myschool.com/st/schemas">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:st="http://myschool.com/st/schemas"
elementFormDefault="qualified"
targetNamespace="http://myschool.com/st/schemas">
<xs:element name="RegisterRequest">
<xs:complexType>
<xs:all>
<xs:element name="Age" type="xs:long"/>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Password" type="xs:string"/>
<xs:element name="Level" type="xs:string"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="UpdateRequest">
<xs:complexType>
<xs:all>
<xs:element name="Student" type="st:StudentType"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="DeleteRequest">
<xs:complexType>
<xs:all>
<xs:element name="StudentId" type="xs:long"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="FindByIdRequest">
<xs:complexType>
<xs:all>
<xs:element name="StudentId" type="xs:long"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="FindByIdResponse">
<xs:complexType>
<xs:all>
<xs:element name="Student" type="st:StudentType"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="FindAllStudentsRequest">
</xs:element>
<xs:element name="FindAllStudentsResponse">
<xs:complexType>
<xs:all>
<xs:element name="list" type="st:StudentTypeList"></xs:element>
</xs:all>
</xs:complexType>
</xs:element>
<xs:complexType name="StudentTypeList">
<xs:sequence>
<xs:element name="Student" type="st:StudentType" maxOccurs="unbounded"></xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="StudentType">
<xs:sequence>
<xs:element name="StudentId" type="xs:long"/>
<xs:element name="Age" type="xs:long"/>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Password" type="xs:string"/>
<xs:element name="Level" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="DeleteRequest">
<wsdl:part element="st:DeleteRequest" name="DeleteRequest"></wsdl:part>
</wsdl:message>
<wsdl:message name="RegisterRequest">
<wsdl:part element="st:RegisterRequest" name="RegisterRequest"></wsdl:part>
</wsdl:message>
<wsdl:message name="FindByIdRequest">
<wsdl:part element="st:FindByIdRequest" name="FindByIdRequest"></wsdl:part>
</wsdl:message>
<wsdl:message name="UpdateRequest">
<wsdl:part element="st:UpdateRequest" name="UpdateRequest"></wsdl:part>
</wsdl:message>
<!-- added -->
<wsdl:message name="FindAllStudentsRequest">
<wsdl:part element="st:FindAllStudentsRequest" name="FindAllStudentsRequest"></wsdl:part>
</wsdl:message>
<wsdl:message name="FindByIdResponse">
<wsdl:part element="st:FindByIdResponse" name="FindByIdResponse"></wsdl:part>
</wsdl:message>
<wsdl:message name="FindAllStudentsResponse">
<wsdl:part element="st:FindAllStudentsResponse" name="FindAllStudentsResponse"></wsdl:part>
</wsdl:message>
<!-- added -->
<wsdl:portType name="StudentService">
<wsdl:operation name="Delete">
<wsdl:input message="st:DeleteRequest" name="DeleteRequest"></wsdl:input>
</wsdl:operation>
<wsdl:operation name="Register">
<wsdl:input message="st:RegisterRequest" name="RegisterRequest"></wsdl:input>
</wsdl:operation>
<wsdl:operation name="FindById">
<wsdl:input message="st:FindByIdRequest" name="FindByIdRequest"></wsdl:input>
<wsdl:output message="st:FindByIdResponse" name="FindByIdResponse"></wsdl:output>
</wsdl:operation>
<wsdl:operation name="Update">
<wsdl:input message="st:UpdateRequest" name="UpdateRequest"></wsdl:input>
</wsdl:operation>
<!-- added -->
<wsdl:operation name="FindAllStudentsRequest">
<wsdl:input message="st:FindAllStudentsRequest" name="FindAllStudentsRequest"></wsdl:input>
<wsdl:output message="st:FindAllStudentsResponse" name="FindAllStudentsResponse"></wsdl:output>
</wsdl:operation>
<!-- added -->
</wsdl:portType>
<wsdl:binding name="StudentServiceSoap11" type="st:StudentService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Delete">
<soap:operation soapAction=""/>
<wsdl:input name="DeleteRequest">
<soap:body use="literal"/>
</wsdl:input>
</wsdl:operation>
<wsdl:operation name="Register">
<soap:operation soapAction=""/>
<wsdl:input name="RegisterRequest">
<soap:body use="literal"/>
</wsdl:input>
</wsdl:operation>
<wsdl:operation name="FindById">
<soap:operation soapAction=""/>
<wsdl:input name="FindByIdRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="FindByIdResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="Update">
<soap:operation soapAction=""/>
<wsdl:input name="UpdateRequest">
<soap:body use="literal"/>
</wsdl:input>
</wsdl:operation>
<!-- added -->
<wsdl:operation name="FindAllStudentsRequest">
<soap:operation soapAction=""/>
<wsdl:input name="FindAllStudentsRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="FindAllStudentsResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<!-- added -->
</wsdl:binding>
<wsdl:service name="StudentServiceService">
<wsdl:port binding="st:StudentServiceSoap11" name="StudentServiceSoap11">
<soap:address location="http://localhost:8080/StudentInformationTool/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

我的实现代码:https://github.com/IamGabrielWu/SpringWebService

spring webservice 开发demo (实现基本的CRUD 数据库采用H2)的更多相关文章

  1. Spring的简单demo

    ---------------------------------------- 开发一个Spring的简单Demo,具体的步骤如下: 1.构造一个maven项目 2.在maven项目的pom.xml ...

  2. Spring MVC + Spring + Mybitis开发Java Web程序基础

    Spring MVC + Spring + Mybitis是除了SSH外的另外一种常见的web框架组合. Java web开发和普通的Java应用程序开发是不太一样的,下面是一个Java web开发在 ...

  3. Spring Security OAuth2 Demo

    Spring Security OAuth2 Demo 项目使用的是MySql存储, 需要先创建以下表结构: CREATE SCHEMA IF NOT EXISTS `alan-oauth` DEFA ...

  4. Webservice开发概念

    一.Web Service基本概念 Web Service由两部分组成 SOAP--Web Service之间的基本通信协议. WSDL--Web Service描述语言,它定义了Web Servic ...

  5. spring.net 在demo中的分析

    1.认识spring.net Spring.NET是一个应用程序框架,其目的是协助开发人员创建企业级的.NET应用程序.它提供了很多方面的功能,比如依赖注入.面向方面编程(AOP).数据访问抽象及AS ...

  6. 基于Myeclipse+Axis2的WebService开发实录

    最近开始学习了下在Myeclipse开发工具下基于WebSerivce的开发,下面将相关相关关键信息予以记录 Myeclipse的安装,本文以Myeclipse2014-blue为开发环境,相关配置执 ...

  7. 使用 Spring HATEOAS 开发 REST 服务--转

    原文地址:https://www.ibm.com/developerworks/cn/java/j-lo-SpringHATEOAS/index.html?ca=drs-&utm_source ...

  8. 天天玩微信,Spring Boot 开发私有即时通信系统了解一下

    1/ 概述 利用Spring Boot作为基础框架,Spring Security作为安全框架,WebSocket作为通信框架,实现点对点聊天和群聊天. 2/ 所需依赖 Spring Boot 版本 ...

  9. 使用 Spring HATEOAS 开发 REST 服务

    使用 Spring HATEOAS 开发 REST 服务 学习博客:https://www.ibm.com/developerworks/cn/java/j-lo-SpringHATEOAS/ htt ...

随机推荐

  1. exynos 4412 eMMC配置及使用方法

    /** ****************************************************************************** * @author    Maox ...

  2. 从java到php

    从大一开始就开始接触java这门语言.但是在这之前也接触了vb,c,asp等等开发语言,唯独java让人感觉严谨,清爽,各种数据之间的不拖泥带水.这才花费更多时间去研究他.但是学着学着,发现他体系的庞 ...

  3. Python编码与解码

    # -*- coding: utf-8 -*- # 直接保存为Python脚本,对照执行结果会好看点. # 实验的内容都是在Python 2.7.x下进行的. # Python3默认采用unicode ...

  4. [原]项目进阶 之 持续构建环境搭建(三)Maven环境搭建

    上次的博文项目进阶 之 持续构建环境搭建(二)Nexus私服器中,我们搭建了一个Nexus的maven私服,这次我们来重点讲解一下Maven的安装和配置.这里说明一下这次的环境搭建,比较基础,但却非常 ...

  5. 标签跳转break和continue

    标签是后面跟有冒号的标识符,例如  label1: 在java中,标签起作用的唯一的地方刚好是在迭代语句之前. “刚好之前”的意思表明,在标签和迭代之间置入热和语句都不好. 而在迭代之前设置标签的唯一 ...

  6. C++ 字符串相关函数

    <转>自:http://zhidao.baidu.com/question/173202165.html 首先就是memcpy表头文件: #include <string.h> ...

  7. UML 小结(5)- 图解 Rational Rose 的详细安装过程

    在学习UML的时候,会用到画图工具:Rotional Rose . 原以为这款软件直接下载下来或者跟朋友那边拷过来就可以直接用了,结果却是没有那么简单,如果读者您也是为了解决这个家伙的安装问题的话,那 ...

  8. Another 20 Docs and Guides for Front-End Developers

    http://www.sitepoint.com/another-20-docs-guides-front-end-developers/?utm_medium=email&utm_campa ...

  9. 不用安装语言包,教你将PS界面语言修改成默认语言(英语)

    地址:http://www.cnblogs.com/Loonger/p/5112020.html 嗯,干脆利落,直接上教程.超简单的方法.(该方法可以随时在你已有语言[非英语]和PS默认语言[英语]之 ...

  10. 把工程部署在tomcat的root路径下

    myeclipse可以右键工程:(eclipse也可以)选择properties->myeclipse->web:把web context-root改成:/然后在用myeclipse部署项 ...