Wildfly 23 服务器 - 简单的 JAX-WS 部署 - 所有访问 WSDL 的尝试都是“禁止”或“未找到”

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

虽然我对 JAX-WS 并不陌生,(几年前在 Sun Metro JAX-WS RI 中使用过它,但没有出现任何问题)...发生了很多变化,并且我参与了许多其他涉及 REST 端点的 Web 服务项目,过去几年主要使用 Spring Boot。

我现在参与另一个项目,其中服务器堆栈是 Wildfly 23,并且他们正在使用 SOAP Web 服务。我编写了一个简单的 WAR 项目,带有一个实现带注释的 Java 接口的带注释的 Java 类。 (文档中的术语是SEI,已经有几年了)。我只是想了解 JAX-WS 服务如何部署以及如何访问 WSDL。

服务实现类

package com.example.jaxws.ws;

import jakarta.jws.WebMethod;
import jakarta.jws.WebService;
import jakarta.jws.soap.SOAPBinding;
import jakarta.jws.soap.SOAPBinding.Style;

@WebService(
    serviceName = "EmployeeService",
    endpointInterface = "com.example.jaxws.ws.EmployeeService"
)
@SOAPBinding(
    style = Style.DOCUMENT
)
public class EmployeeServiceImpl implements EmployeeService {
    public EmployeeServiceImpl() {
    }

    @WebMethod
    public Employee getEmployee(int id) {
        return null;
    }

    @WebMethod
    public Employee addEmployee(int id, String name) {
        return new Employee(id, name);
    }
}

服务接口:

package com.example.jaxws.ws;

import jakarta.jws.WebMethod;
import jakarta.jws.WebService;
import jakarta.jws.soap.SOAPBinding;

@WebService
@SOAPBinding(style= SOAPBinding.Style.DOCUMENT)
public interface EmployeeService {

    @WebMethod
    Employee getEmployee(int id);
    @WebMethod
    Employee addEmployee(int id, String name);
}

web.xml 文件如下所示(实际上是一个空的默认文件)

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
         version="5.0">

    
</web-app>

另一篇文章说需要一个 jboss-web.xml,(相同位置/WEB-INF)所以添加了这个

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web version="10.0"
           xmlns="http://www.jboss.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_10_0.xsd">

    <context-root>/employee-service</context-root>
</jboss-web>

最后,pom.xml 包含以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>JAXWS_Services</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>JAXWS_Services</name>
    <packaging>war</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.target>11</maven.compiler.target>
        <maven.compiler.source>11</maven.compiler.source>
    </properties>

    <dependencies>
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <version>5.0.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.xml.ws</groupId>
            <artifactId>jakarta.xml.ws-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.3.2</version>
            </plugin>
        </plugins>
    </build>
</project>

WAR 项目被添加到 IntelliJ 中创建 Wildfly 运行配置的服务器实例中。启动服务器显示零错误,创建的上下文根路径与 jboss-web.xml 匹配。然而,导航到上下文根路径上的任何位置都会导致“禁止”错误页面和 WSDL 路径(我认为应该基于我见过的其他代码工作),产生 404 😔)

显然,我错过了一件大事。任何见解将不胜感激。

启动后控制台输出:

Connected to server
[2023-10-31 11:00:37,551] Artifact JAXWS_Services:war: Artifact is being deployed, please wait...
23:00:37,763 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) WFLYSRV0027: Starting deployment of "JAXWS_Services-1.0-SNAPSHOT.war" (runtime-name: "JAXWS_Services-1.0-SNAPSHOT.war")
23:00:39,883 INFO  [org.infinispan.CONTAINER] (ServerService Thread Pool -- 28) ISPN000128: Infinispan version: Infinispan 'Corona Extra' 11.0.9.Final
23:00:39,965 INFO  [org.infinispan.CONFIG] (MSC service thread 1-6) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
23:00:39,968 INFO  [org.infinispan.CONFIG] (MSC service thread 1-6) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
23:00:40,115 INFO  [org.infinispan.PERSISTENCE] (ServerService Thread Pool -- 28) ISPN000556: Starting user marshaller 'org.wildfly.clustering.infinispan.spi.marshalling.InfinispanProtoStreamMarshaller'
23:00:40,452 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 28) WFLYCLINF0002: Started http-remoting-connector cache from ejb container
23:00:40,767 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 8) WFLYUT0021: Registered web context: '/employee-service' for server 'default-server'
23:00:40,852 INFO  [org.jboss.as.server] (management-handler-thread - 1) WFLYSRV0010: Deployed "JAXWS_Services-1.0-SNAPSHOT.war" (runtime-name : "JAXWS_Services-1.0-SNAPSHOT.war")
[2023-10-31 11:00:40,872] Artifact JAXWS_Services:war: Artifact is deployed successfully
[2023-10-31 11:00:40,872] Artifact JAXWS_Services:war: Deploy took 3,321 milliseconds

虽然日志记录显示部署成功并建立了上下文根路径...但我没有看到编码的“Web 服务”实际上在容器中运行的证据。

jboss wildfly jax-ws
1个回答
0
投票

您可能需要升级 WildFly。 WildFly 23 是 Jakarta EE 8 容器。您可能可以使用 WildFly 23 Preview,但我不建议这样做。您应该升级到最新的 WildFly,目前是 30.0.0.Final,这是 Jakarta EE 10 容器。

Jakarta EE 8 仍然使用

javax
命名空间,而 Jakarta EE 9+ 使用
jakarta
命名空间。您的依赖项是 Jakarta EE 9 依赖项,并且您的代码使用
jakarta
命名空间,因此需要 Jakarta EE 9+ 容器。我个人的意见是跳过 Jakarta EE 9.1 并直接进入 Jakarta EE 10。

© www.soinside.com 2019 - 2024. All rights reserved.