You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在PolicyCenter创建基础REST API遇500与404错误求排查

PolicyCenter HelloWorld REST API 创建问题排查

我正在尝试在PolicyCenter中创建一个基础的HelloWorld REST API,调用GET /apis端点(来自com.guidewire.pl.rest.docs.ApiListGenerator)时出现内部服务器错误,新端点返回404 Not Found。不清楚缺失了哪些配置,日志中也没有相关线索,求排查提示。


请求1:GET http://localhost:8180/pc/rest/apis

{
  "status": 500,
  "errorCode": "java.lang.IllegalArgumentException",
  "cause": {
    "class": "java.lang.IllegalArgumentException",
    "message": "Keys in JsonObject cannot be null"
  },
  "stackTrace": [
    "gw.api.json.JsonObject.validateKey(JsonObject.java:898)",
    "gw.api.json.JsonObject.put(JsonObject.java:849)",
    "com.guidewire.pl.rest.docs.ApiListGenerator.lambda$createApiListJson$2(ApiListGenerator.java:37)",
    "java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)", 
    ...
  ]
}

请求2:GET http://localhost:8180/pc/rest/helloworld

{
  "status": 404,
  "errorCode": "gw.api.rest.exceptions.NotFoundException", 
  "userMessage": "No resource was found at path /helloworld"
}

相关文件内容

文件:modules\configuration\gsrc\myorg\pc\integration\restapi\helloworld\HelloWorldHandler.gs

package myorg.pc.integration.restapi.helloworld    

class HelloWorldHandler {

  public function getHelloWorld() : String {
    return 'Hello, World!'
  }

}

文件:modules\configuration\config\integration\apis\myorg\pc\helloworld\helloworld-1.0.swagger.yaml

swagger: "2.0"
info:
  version: "1.0"
  title: "Hello World API"
x-gw-apihandlers:
  - myorg.pc.integration.restapi.helloworld.HelloWorldHandler
paths:
  /helloworld:
    get:
      summary: "Says 'Hello World'"
      description: "Says 'Hello World'"
      operationId: getHelloWorld
      produces:
        - text/plain
      responses:
        '200':
          description: |
            Successful operation
          schema:
            type: string

文件:modules\configuration\config\integration\apis\published-apis.yaml

apis:
- name: myorg.pc.helloworld.helloworld-1.0
defaultTemplate:
- name: gw.pl.framework.dev_template-1.0

排查提示

  • 校验API名称与文件路径匹配:确认published-apis.yaml中引用的myorg.pc.helloworld.helloworld-1.0是否符合PolicyCenter的API命名规则([org].[app].[api-name].[api-version]),且与Swagger文件的目录结构完全对应。
  • 修复500错误根源:堆栈信息显示JsonObject存在空key,需检查Swagger文件:
    • x-gw-apihandlers中的handler类路径是否拼写正确、类是否存在
    • info部分是否有遗漏的必填字段
    • 可暂时移除自定义API,调用/apis验证是否恢复正常,逐步定位问题配置
  • 确认Handler类部署状态:检查HelloWorldHandler.gs是否已编译,编译后的class文件是否存在于部署目录,包路径与Swagger配置完全一致(大小写、拼写无误差)。
  • 验证模板与路由配置:确认published-apis.yaml中的gw.pl.framework.dev_template-1.0模板存在且配置正确;修改配置后重启PolicyCenter服务,确保配置加载生效。
  • 开启详细日志:将com.guidewire.pl.rest和gw.api.rest的日志级别设为DEBUG,重新调用端点,获取更详细的错误细节。

内容的提问来源于stack exchange,提问作者Andreas Warberg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 15:21:02