哪位大侠有没有做过基于spring ws2的webservice啊。今天项目经理就给了我两个xsd文件,要我用spring自带的spring -ws2做一个webservice。哪位大侠有没有用spring里面自带的spring ws2做过啊。若是有的话,麻烦传一个demo给我。邮箱:[email protected](ICBPtoHESB).xsd
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/ESB2ICBP-IN" xmlns:tns="http://www.example.org/ESB2ICBP-IN" elementFormDefault="qualified">
    <complexType name="Ex78352In">
     <sequence>
     <element name="funcCode" type="string"></element>
     <element name="iBAccount" type="string"></element>
     <element name="fromAccount" type="string"></element>
     <element name="cardNo" type="string"></element>
     <element name="cardSsn" type="string"></element>
     <element name="fromCurrencyCode" type="string"></element>
     <element name="fromCurrencyCodeMNEM" type="string"></element>
     <element name="fromAmount" type="decimal"></element>
     <element name="toAccount" type="string"></element>
     <element name="cardNo" type="string"></element>
     <element name="cardSsn" type="string"></element>
     <element name="toCurrencyCode" type="string"></element>
     <element name="toCurrencyCodeMNEM" type="string"></element>
     <element name="amount" type="decimal"></element>
     <element name="exchangeRate" type="decimal"></element>
     <element name="memo" type="string"></element>
     <element name="pbConfirmInd" type="string"></element>
     <element name="stdChrgInd" type="string"></element>
     <element name="flag1" type="string"></element>
     <element name="flag2" type="string"></element>
     </sequence>
    </complexType>    <complexType name="Ex78352Out">
     <sequence>
     <element name="IBAccount" type="string"></element>
     <element name="wdlAccNum" type="string"></element>
     <element name="cardNo" type="string"></element>
     <element name="cardSsn" type="string"></element>
     <element name="wdlAccCcyCode" type="string"></element>
     <element name="wdlAccCcyMnem" type="string"></element>
     <element name="wdlAccCcyTtlAmt" type="decimal"></element>
     <element name="depAccNum" type="string"></element>
     <element name="cardNo" type="string"></element>
     <element name="cardSsn" type="string"></element>
     <element name="depAccCcyCode" type="string"></element>
     <element name="depAccCcyMnem" type="string"></element>
     <element name="depAccCcyAmt" type="decimal"></element>
     <element name="exchRate" type="decimal"></element>
     <element name="wdlAccCcyAmt" type="decimal"></element>
     <element name="memo" type="string"></element>
     <element name="pbConfirmInd" type="string"></element>
     <element name="stdChrgInd" type="string"></element>
     <element name="srcCode" type="string"></element>
     <element name="chrgCcy" type="string"></element>
     <element name="chrgAmount" type="decimal"></element>
     <element name="evqHkdAmt" type="string"></element>
     </sequence>    </complexType>
</schema>
transferAc(CESBtoICBP).xsd
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/ESB2ICBP-IN" xmlns:tns="http://www.example.org/ESB2ICBP-IN" elementFormDefault="qualified">
    <complexType name="TransferAcIn">
     <sequence>
     <element name="funcCode" type="string"></element>
     <element name="iBAccount" type="string"></element>
     <element name="fromAccount" type="string"></element>
     <element name="fromCurrencyCode" type="string"></element>
     <element name="fromCurrencyCodeMNEM" type="string"></element>
     <element name="fromAmount" type="decimal"></element>
     <element name="toAccount" type="string"></element>
     <element name="toCurrencyCode" type="string"></element>
     <element name="toCurrencyCodeMNEM" type="string"></element>
     <element name="amount" type="decimal"></element>
     <element name="exchangeRate" type="decimal"></element>
     <element name="memo" type="string"></element>
     <element name="pbConfirmInd" type="string"></element>
     <element name="stdChrgInd" type="string"></element>
     <element name="flag1" type="string"></element>
     <element name="flag2" type="string"></element>
     </sequence>
    </complexType>    <complexType name="TransferAcOut">
     <sequence>
     <element name="IBAccount" type="string"></element>
     <element name="wdlAccNum" type="string"></element>
     <element name="wdlAccCcyCode" type="string"></element>
     <element name="wdlAccCcyMnem" type="string"></element>
     <element name="wdlAccCcyTtlAmt" type="decimal"></element>
     <element name="depAccNum" type="string"></element>
     <element name="depAccCcyCode" type="string"></element>
     <element name="depAccCcyMnem" type="string"></element>
     <element name="depAccCcyAmt" type="decimal"></element>
     <element name="exchRate" type="decimal"></element>
     <element name="wdlAccCcyAmt" type="decimal"></element>
     <element name="memo" type="string"></element>
     <element name="pbConfirmInd" type="string"></element>
     <element name="stdChrgInd" type="string"></element>
     <element name="srcCode" type="string"></element>
     <element name="chrgCcy" type="string"></element>
     <element name="chrgAmount" type="decimal"></element>
     <element name="evqHkdAmt" type="string"></element>
     </sequence>    </complexType>
</schema>spring wswebserviceencoding

解决方案 »

  1.   

    问题补充:webservice 信息传递是通过xml文件传输的。我现在只做了个传输简单字符串的demo,但传输xml(通过jaxb,或者jomo解析)一直抱异常。
    我的endpoint代码:
    package com.mycompany.hr.ws;import java.text.SimpleDateFormat;
    import java.util.Date;import org.jdom.JDOMException;
    import org.jdom.Namespace;
    import org.jdom.xpath.XPath;
    import org.springframework.ws.server.endpoint.AbstractMarshallingPayloadEndpoint;import com.mycompany.hr.service.IHumanResourceService;public class HolidayEndpoint extends AbstractMarshallingPayloadEndpoint  {
    //定义解析xsd文件变量
    private XPath startDateExpression;
    private XPath endDateExpression;
    private XPath nameExpression;

    //定义服务类
    private IHumanResourceService humanResourceService; public HolidayEndpoint(IHumanResourceService humanResourceService)
    throws JDOMException {

    this.humanResourceService = humanResourceService;

     Namespace namespace = Namespace.getNamespace("hr", "http://com.mycompany/hr/schemas");
         startDateExpression = XPath.newInstance("//hr:StartDate");
         startDateExpression.addNamespace(namespace);
         endDateExpression = XPath.newInstance("//hr:EndDate");
         endDateExpression.addNamespace(namespace);
         nameExpression = XPath.newInstance("concat(//hr:FirstName,' ',//hr:LastName)");
         nameExpression.addNamespace(namespace);
    } protected Object invokeInternal(Object  holidayRequest) throws Exception {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

    Date startDate = dateFormat.parse(startDateExpression
    .valueOf(holidayRequest));

    Date endDate = dateFormat.parse(endDateExpression
    .valueOf(holidayRequest));

    String name = nameExpression.valueOf(holidayRequest);

    humanResourceService.bookHoliday(startDate, endDate, name);

    return null;
    } public void setHumanResourceService(IHumanResourceService humanResourceService) {
    this.humanResourceService = humanResourceService;
    }
    }client代码:/**   
     * @Title: HolidayClient.java 
     * @Package com.mycompany.hr.client.sws 
     * @Description: TODO(用一句话描述该文件做什么) 
     * @author zwzheng  
     * @date 2013-3-13 下午01:32:46 
     * @version V1.0   
     */
    package com.mycompany.hr.client.sws;import java.io.IOException;import javax.xml.transform.Source;import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import org.springframework.core.io.Resource;
    import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
    import org.springframework.xml.transform.ResourceSource;
    import org.springframework.xml.transform.StringResult;/**
     * @ClassName: HolidayClient
     * @Description: TODO(这里用一句话描述这个类的作用)
     * @author zwzheng
     * @date 2013-3-13 下午01:32:46
     */
    public class HolidayClient extends WebServiceGatewaySupport { private Resource request; public void setRequest(Resource request) {
    this.request = request;
    } public static void main(String[] args) throws IOException {
    ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
    "\\applicationContext.xml", HolidayClient.class); HolidayClient holidayClient = (HolidayClient) applicationContext
    .getBean("holidayClient"); holidayClient.holiday();
    } public void holiday() throws IOException { Source requestSource = new ResourceSource(request);

    System.out.println(requestSource.getSystemId());

    StringResult result = new StringResult();

    getWebServiceTemplate().sendSourceAndReceiveToResult(requestSource,
    result);

    System.out.println(result); }}
     运行之后,控制台报异常:
    file:/E:/workspace6.5/spring_ws/WebRoot/WEB-INF/classes/config/holidayRequest.xml
    Exception in thread "main" org.springframework.ws.soap.client.SoapFaultClientException: No unmarshaller registered. Check configuration of endpoint.
    at org.springframework.ws.soap.client.core.SoapFaultMessageResolver.resolveFault(SoapFaultMessageResolver.java:37)
    at org.springframework.ws.client.core.WebServiceTemplate.handleFault(WebServiceTemplate.java:774)
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:600)
    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:537)
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:492)
    at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceiveToResult(WebServiceTemplate.java:436)
    at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceiveToResult(WebServiceTemplate.java:427)
    at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceiveToResult(WebServiceTemplate.java:417)
    at com.mycompany.hr.client.sws.HolidayClient.holiday(HolidayClient.java:54)
    at com.mycompany.hr.client.sws.HolidayClient.main(HolidayClient.java:43)
    若是有高手在线的话,麻烦发份demo给我,邮箱:[email protected],或者加我扣扣:1377404933,不甚感激,不甚感激。在线等啊
      

  2.   

    是要写webservice接口吧?demo还没整理出来、、、
      

  3.   

    demo写出来了,client和server传输的是soap.但现在要做一个spring ws security 的demo,主要是Wss4jSecurityInterceptor配置属性不知道含义,还有在配置Wss4jSecurityInterceptor的时候,要解析一个安全证书(crypto.keystore)我不知道crypto.keystore如何定义,我现在用keytool写了个crypto.keystore ,但是好像没有任何作用.我的spirng-ws-servlet.xml配置如下:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    <bean id="payloadMapping"
    class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
    <property name="endpointMap">
    <map>
    <entry
    key="{http://www.ispring.com/ws/hello}eRequest">
    <ref bean="helloEndpoint" />
    </entry>
    </map>
    </property>
    <!-- -->
    <property name="interceptors">
    <list>
    <ref bean="wss4jSecurityInterceptor" />
    </list>
    </property>
    </bean> <!-- WSS Security interceptor - encrypt entire body of SOAP response -->
    <bean id="wss4jSecurityInterceptor"
    class="org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor">
    <!-- Validation part -->
    <property name="validateRequest" value="true" />
    <property name="validationActions"
    value="Signature Encrypt Timestamp" />
    <property name="validationSignatureCrypto" ref="serverCrypto" />
    <property name="validationDecryptionCrypto" ref="serverCrypto" />
    <property name="validationCallbackHandler"
    ref="validationCallbackHandler" /> <!-- Sign the response -->
    <property name="secureResponse" value="true" />
    <property name="securementActions"
    value="Timestamp Signature Encrypt" />
    <property name="securementSignatureKeyIdentifier"
    value="DirectReference" />
    <property name="securementUsername" value="myName" />
    <property name="securementPassword" value="123456" />
    <property name="securementSignatureCrypto" ref="serverCrypto" />
    <property name="securementEncryptionUser" value="myName" />
    <property name="securementEncryptionKeyIdentifier"
    value="Thumbprint" />
    <property name="securementEncryptionCrypto" ref="serverCrypto" />
    </bean> <bean id="serverCrypto"
    class="org.springframework.ws.soap.security.wss4j.support.CryptoFactoryBean">
    <property name="keyStorePassword" value="123456" />
    <property name="keyStoreLocation"
    value="/WEB-INF/crypto.keystore" />
    </bean> <bean id="validationCallbackHandler"
    class="org.springframework.ws.soap.security.wss4j.callback.KeyStoreCallbackHandler">
    <property name="privateKeyPassword" value="123456" />
    </bean> <bean id="helloEndpoint" class="com.sws.HelloEndPoint">
    <property name="helloService" ref="helloService"></property>
    </bean> <bean id="hello"
    class="org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition">
    <!--  -->
    <property name="wsdl" value="classpath://hello.wsdl"></property>
    <!-- <property name="wsdl" value="/WEB_INF/hello.wsdl"></property> -->
    <!-- <constructor-arg value="/WEB_INF/hello.wsdl"/> -->
    </bean> <bean id="helloService" class="com.sws.HelloServiceImpl"></bean>
    </beans>你有没有很好的例子啊,包含了spring-ws 的security. 有的话,发我 谢谢.
    麻烦加我扣:1377404933 ,方便交流.