如何将 SOAP Web 服务从基于 JDK 的 jax-ws 实现切换到 Metro?

问题描述 投票:0回答:0

我有这个 SOAP 网络服务

请求/响应

    import javax.xml.bind.annotation.XmlElement;
    public class EmployeeRequest {
        private String firstName;
        //getters and setters with annotation @XmlElement on getters
    }

    import javax.xml.bind.annotation.XmlElement;
    public class Employee {
        private int id;
        private String firstName;
   //getters and setters with annotation @XmlElement on getters
    }

接口/实现

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public interface EmployeeService {

    @WebMethod
    Employee getEmployee(EmployeeRequest request);
}

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService(endpointInterface = "org.example.EmployeeService")
public class EmployeeServiceImpl implements EmployeeService {

    @WebMethod
    public Employee getEmployee(EmployeeRequest request) {
        Employee employee = new Employee();
        employee.setId(1);
        employee.setFirstName(request.getFirstName() + ", hello");
        return employee;
    }
}

和主班级

import javax.xml.ws.Endpoint;

public class Main {
    public static void main(String[] args) {
        Endpoint.publish("http://localhost:8080/employeeservice", new EmployeeServiceImpl());
    }
}

它工作正常并使用标准的基于 JDK 的 jax-ws 实现(JAX-WS RI 运行时包),因为我的 pom.xml 中没有任何依赖项。如果我错了,请纠正我。

现在我想尝试 Glassfish Metro 实现(https://stackoverflow.com/a/12670288/11926338):

JAX-WS 是一个 API,而 Metro 是 JAX-WS API;两者都来自 Sun/Oracle,因此是标准的。你可以看到 它们作为接口 (JAX-WS) 和实现接口的类 (地铁),只是在更高的层次上。 Glassfish 还使用 Metro 作为 JAX-WS 的实现。

如何将我的项目切换到 Metro?我尝试添加几个依赖项:

<dependencies>
    <dependency>
        <groupId>org.glassfish.metro</groupId>
        <artifactId>webservices-rt</artifactId>
        <version>4.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.metro</groupId>
        <artifactId>webservices-api</artifactId>
        <version>4.0.2</version>
    </dependency>
</dependencies>

它继续工作,但我不明白正在使用什么实现。

java web-services soap jax-ws java-metro-framework
© www.soinside.com 2019 - 2024. All rights reserved.