春天的帽子链接(HTTPS与HTTP)

时间:2019-01-10 20:42:14

标签: spring rest spring-boot spring-mvc spring-hateoas

我有一个简单的rest服务,当与HATEOS链接一起执行GET操作时,该服务返回响应。当服务部署在服务器上并通过负载平衡器URL(Https)访问时,链接部分包含带有“ http”而不是“ https”的URL。此特定场景的任何示例解决方案/代码都会对我有所帮助。

例如:

如果通过使用url(https://servicename.example.com)执行GET操作,那么我希望链接部分中包含相同的url。但是我收到类似下面的内容。

响应正文:

       {
      "fieldA": null,
      "fieldB": null,
      "links": [
        {
         "rel": "self",
         "href": "http://servicename.example.com" // It has to be https
        }
      ]
     }

下面是将链接添加到将显示给使用者的Rest资源链接的代码行。

 resource.getLinks().add(linkTo(methodOn(ExampleController.class).methodInExampleController(arg a, arg b)).withSelfRel());

暴露给使用者的资源扩展了另一个类“ ResourceSupport”,其中声明了一个名为Links的字段,其类型为List。

资源类示例:

     imnport com.examplepackage.ResourceSupport

     public SampleResource extends ResourceSupport{

        private String fieldA,

        private String fieldB,

        //setters and getters

          }

声明HATEOS链接的类的示例

      import org.springframework.hateoas.Identifiable;
      import org.springframework.hateoas.Link;

      public ResourceSupport implements Identifiable<Link>{

            @JsonInclude(Include.NON_EMPTY)
            private final List<Link> links = new ArrayList();

            @JsonProperty("links")
            public List<Link> getLinks() {
             return this.links;
              }
          }

SPRING HATEOS版本:spring-hateos0.24.0.RELEASE

0 个答案:

没有答案
相关问题