rest - 使用 Wildfly 的简单 RESTful 端点

标签 rest jakarta-ee curl jboss wildfly

我正在使用 wildfly 从头开始​​运行 javaee Web 应用程序,并且只想公开一些 RESTful Web 服务。我的 Wildfly 应用程序服务器正在以其附带的默认值运行,并且我没有使用任何数据库实体,尽管我确实有一个 persisitance.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 页面。

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

最佳答案

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

关于rest - 使用 Wildfly 的简单 RESTful 端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27625921/

相关文章:

php - Yii2 Rest - 自定义操作和 OPTIONS 方法

java - 如何将 Web 项目拆分为 2 个独立的项目/模块

jakarta-ee - 帮我稳定这个 jRun 配置 (CF9/Win2k3/IIS6)

java - 类具有不受支持的主要或次要版本号

wordpress - WP - 对外部 API 的 cURL 调用停止工作 - cURL 错误 60 : SSL certificate problem: certificate has expired

rest - 在正文或 URI 中指定 REST API PUT 请求的 DTO ID?

web-services - ServiceStack过程逻辑分离

rest - 有什么安全的方法可以在 SPA 的客户端保留 rest auth token 吗?

c++ - gdb 显示奇怪的堆栈跟踪

curl - Jive REST API 返回 {"code":401 ,"message" :"Bad credentials"} using Basic Auth