No adapter for endpoint SWS

不想你离开。 提交于 2019-12-04 04:26:03
betelgeuse

This is the working solution to your problem:

add this dependencies to your pom.xml

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);
}

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!