zoukankan      html  css  js  c++  java
  • spring webservice 搭建出现的异常处理。异常: NAMESPACE_ERR: An attempt is made to create or change an object in a way whi

    异常:NAMESPACE_ERR: An attempt is made to create or change an object in a way whi---- 这是我自己写客户端调用webservice 控制台显示的部分异常代码。

    或者直接通过soapUI 调用:

    异常信息如下

    No adapter for endpoint [public org.jdom.Element com.mycompany.hr.ws.HolidayEndpoint.handleHolidayRequest(org.jdom.Element) throws java.lang.Exception]: Is your endpoint annotated with @Endpoint, or does it implement a supported interface like MessageHandler or PayloadEndpoint?

    官方搭建 spring webserivce 项目的文档:  http://docs.spring.io/spring-ws/site/reference/html/tutorial.html  官方的使用webservice 的案例 是个员工休假的webservice系统,采用domj 做endpoint的元素mapping

    出现错误的原因:

    http://stackoverflow.com/questions/11683468/no-adapter-for-endpoint-sws

    I think the problem lies here jira.springsource.org/browse/… There's a bug in endpoint mapping for JDOM elements 

     

    solution 复制黏贴如下: 将 jdom2 取代jdom

    This is the working solution to your problem:

    add this dependencies to your pom.xml

    enter image description here

    Change the imports in your source for jdom to jdom2

    And this is the updated version of HolidayEndpoint:

    package com.mycompany.ws_template.endpoint;
    
    import com.mycompany.ws_template.service.HumanResource;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import org.jdom2.JDOMException;
    import org.jdom2.Namespace;
    import org.jdom2.Element;
    import org.jdom2.filter.Filters;
    import org.jdom2.xpath.XPathExpression;
    import org.jdom2.xpath.XPathFactory;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.ws.server.endpoint.annotation.Endpoint;
    import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
    import org.springframework.ws.server.endpoint.annotation.RequestPayload;
    
    
    @Endpoint
    public class HolidayEndpoint {
    
    private static final String NAMESPACE_URI = "http://www.mycompany.com/holiday-service/schemas/holiday-request";
    
    private XPathExpression<Element> startDateExpression;
    private XPathExpression<Element> endDateExpression;
    private XPathExpression<Element> nameExpression;
    private XPathExpression<Element> surnameExpression;
    
    @Autowired private HumanResource holidayService;
    
    public HolidayEndpoint() throws JDOMException {
    
        Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI);
    
        XPathFactory xpathFactory = XPathFactory.instance();
        startDateExpression = xpathFactory.compile("//hr:StartDate", Filters.element(), null, namespace);
        endDateExpression = xpathFactory.compile("//hr:EndDate", Filters.element(), null, namespace);
        nameExpression = xpathFactory.compile("//hr:EmployeeName", Filters.element(), null, namespace);
        surnameExpression = xpathFactory.compile("//hr:EmployeeSurname", Filters.element(), null, namespace);
    }
    
    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "HolidayRequest")
    public void handleHolidayRequest(@RequestPayload Element holidayRequest) throws Exception {
    
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date startDate = sdf.parse(startDateExpression.evaluate(holidayRequest).get(0).getValue());
        Date endDate = sdf.parse(endDateExpression.evaluate(holidayRequest).get(0).getValue());
        String name = nameExpression.evaluate(holidayRequest).get(0).getValue() + surnameExpression.evaluate(holidayRequest).get(0).getValue();
    
        holidayService.bookHoliday(startDate, endDate, name);
    }
    
    }
  • 相关阅读:
    使用CustomValidate自定义验证控件
    C#中金额的大小写转换
    Andriod出错之Unable to build: the file dx.jar was not loaded from the SDK folder!
    VC 编写的打字练习
    机房工作笔记Ping只有单向通
    web服务协同学习笔记(1)
    Dll 学习3 将MDI子窗口封装在DLL中
    机房工作学习文件共享
    Andriod出错之Failed to find an AVD compatible with target 'Android 2.2'
    Andriod出错之wrapper was not properly loaded first
  • 原文地址:https://www.cnblogs.com/IamThat/p/4622426.html
Copyright © 2011-2022 走看看