【问题标题】:Simple RESTful endpoint using wildfly使用 wildfly 的简单 RESTful 端点
【发布时间】:2015-02-21 22:10:05
【问题描述】:

我正在使用 wildfly 从头开始​​运行 javaee Web 应用程序,并且只想公开一些 RESTful Web 服务。我的 wildfly 应用程序服务器使用它附带的默认设置运行,我没有使用任何数据库实体,尽管我确实有一个 persisiance.xml 来让 wildfly 满意。我的应用程序部署良好,如下面的日志消息所示。

12:50:38,585 INFO  [org.jboss.resteasy.spi.ResteasyDeployment] (MSC service thread 1-5) Deploying javax.ws.rs.core.Application: class org.netbeans.rest.application.config.ApplicationConfig
12:50:38,585 INFO  [org.jboss.resteasy.spi.ResteasyDeployment] (MSC service thread 1-5) Adding class resource os.acquisition.acq.Acquisition from Application class org.netbeans.rest.application.config.ApplicationConfig
12:50:38,588 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-5) JBAS017534: Registered web context: /acq-1.0
12:50:38,712 INFO  [org.jboss.as.server] (management-handler-thread - 29) JBAS018565: Replaced deployment "acq-1.0.war" with deployment "acq-1.0.war"

我的问题是在尝试调用下面的 GET 请求时出现的。 (总是返回 404)

@Path("/acq")
public class Acquisition {

    @GET
    @Path("ping")
    public Response ping(@Context HttpServletRequest req) {
        return Response.ok().entity(GenericResponse.OK).build();
    }

}

我还使用了标准 IDE 生成的 ApplicationConfig.java,它将此服务作为其资源之一。

@javax.ws.rs.ApplicationPath("webresources")
public class ApplicationConfig extends Application {

    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> resources = new java.util.HashSet<>();
        addRestResourceClasses(resources);
        return resources;
    }

    /**
     * Do not modify addRestResourceClasses() method.
     * It is automatically populated with
     * all resources defined in the project.
     * If required, comment out calling this method in getClasses().
     */
    private void addRestResourceClasses(Set<Class<?>> resources) {
        resources.add(os.acquisition.acq.Acquisition.class);
    }

}

我一直在使用简短的 curl 脚本来调用其余服务,并尝试了 @Path 参数和 URL 配置的所有可能组合,但无济于事。

#!/bin/bash
curl -v -X GET http://localhost:8080/acq-1.0/acq/ping

此外,当调用curl -v -X GET http://localhost:8080/acq-1.0/ 时,它会按我的预期返回 index.html 页面。

似乎我在这里遗漏了一些基本的东西。有什么想法吗?

【问题讨论】:

    标签: rest jakarta-ee curl jboss wildfly


    【解决方案1】:

    @ApplicationPath 的值被附加到资源 URI之前各个资源路径。看起来您的 curl 请求缺少“webresources”部分。

    【讨论】:

    • 我在您发布此内容前几秒钟就发现了这一点。我发现很难找到有关该主题的可靠信息。感谢您的回复。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 2020-03-26
    • 1970-01-01
    相关资源
    最近更新 更多