在PolicyCenter中创建一个基本的REST API。

huangapple go评论107阅读模式
英文:

Creating a basic REST API in PolicyCenter

问题

I am trying to create a basic HelloWorld REST API in PolicyCenter. I am getting an Internal Server Error from the GET /apis endpoint (from the com.guidewire.pl.rest.docs.ApiListGenerator) and my new endpoint returns 404 Not Found. I am not sure what is missing, and I don't see any clues in the logs. Any hints are welcome.

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)",
...
}

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
英文:

I am trying to create a basic HelloWorld REST API in PolicyCenter. I am getting an Internal Server Error from the GET /apis's endpoint (from the com.guidewire.pl.rest.docs.ApiListGenerator) and my new endpoint returns 404 Not Found. I am not sure what is missing and I don't see any clues in the logs. Any hints are welcome.

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)", 
    ...

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

答案1

得分: 5

我很高兴看到您已解决了您的问题,但我想提醒您产品文档已更新,包括广泛的关于这个主题的文档。如果您前往Guidewire社区的Guidewire文档并搜索“配置REST API”,您将找到关于如何构建映射器和更新程序,将请求/响应负载映射到Guidewire类型,几乎不需要代码或根本不需要代码的文档,以及如何管理身份验证、如何通过IRestDispatchPlugin调度插件执行预处理和后处理,以及有关日志记录的最佳实践,如何本地化您的响应负载等等的全面文档。

英文:

I'm glad to see you've resolved your issue, but I wanted to bring to your attention that the product documentation has been updated to include extensive documentation on this topic. If you go to the Guidewire Docs from the Guidewire Community and search for "Configuring REST APIs", you will find comprehensive docs on topics such as how to build mappers and updaters which map to and from request/response payloads to Guidewire types with minimal or no code required, how to manage authentication, how to perform pre and post processing via the IRestDispatchPlugin dispatch plugin, best practices around logging, how to localize your response payloads, and much more.

答案2

得分: 0

经过一番查找,我找到了关于Swagger格式的文档,其中提到了basePath作为一个必需的属性。在添加了这个属性之后,我的API开始工作了(使用了不同的URL)。

英文:

After some digging I was able to find the documentation on the Swagger format, which mentioned basePath as a required property. After adding this, my API started working (with a different URL).

huangapple
  • 本文由 发表于 2023年2月14日 00:09:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75438418.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定