小编Lub*_*ubo的帖子

将@RequestBody 中的 HAL URI 映射到 Spring Data Rest 托管实体

我使用 Spring Data JPA 来管理 JPA 实体,Spring Data Rest 将存储库导出到 REST API。

我还在构建一个自定义控制器,我想在其中获取实体的 URI(HAL 链接)并通过CrudRepository.

自定义控制器

@RequestMapping(path = MeLinks.ELEVATE, method = RequestMethod.PUT, consumes = RestMediaTypes.TEXT_URI_LIST_VALUE)
HttpEntity<?> elevate(@RequestBody @Valid CollectionModel<Contact> contact) {
    ...
}
Run Code Online (Sandbox Code Playgroud)

当尝试使用 Content-Type 之PUT类的联系链接时,我可以使用而不是 Contact 对象本身访问链接。http://localhost:8080/contacts/1text/uri-listcontact.getLinks()

Spring Data Rest 是否可以从 URI 自动推断实体?我知道一个内置的,UriToEntityConverter但我如何使用它?

编辑

这是一种有效但并没有真正优雅地解决问题的尝试。

下面的代码初始化 aUriToEntityConverter并将传入的 URI 转换为域对象。

@Autowired
private ApplicationContext applicationContext;

@Autowired
private MappingContext<?, ?> mappingContext;

@RequestMapping(path = MeLinks.ELEVATE, method = RequestMethod.PUT, consumes = RestMediaTypes.TEXT_URI_LIST_VALUE)
HttpEntity<?> …
Run Code Online (Sandbox Code Playgroud)

spring-mvc spring-data spring-data-rest spring-hateoas

7
推荐指数
1
解决办法
927
查看次数

如何使用 Gadling 2.2.0 调用 SOAP Web 服务

我是加特林和斯卡拉的新手。如何使用 Gadling 2.2.0 调用/测试 java SOAP Web 服务?我搜索了谷歌和加特林文档,但找不到任何链接

代码:

    val httpProtocol = http
        .baseURL("http://PUNITP83267L:8081/WebServiceProject/services/MyService")
    val headers_0 = Map(
        "accept-encoding" -> "gzip, deflate",
        "Content-Type" -> "text/xml;charset=UTF-8",
        "SOAPAction" -> "",
        "Content-Length" -> "275",
        "Host" -> "PUNITP83267L:8081",
        "Connection" -> "alive",
        "accept-language" -> "en-US,en;q=0.8",
        "user-agent" -> "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"
    )

    val scn = scenario("SOAPRecordedSimulation")
        .exec(http("simple Soap Request")
        .post("<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">
              <soapenv:Body><greetMeResponse xmlns=\"http://ws.star.fs.infosys.com\">
              <greetMeReturn>Hello uMESH</greetMeReturn></greetMeResponse>
              </soapenv:Body></soapenv:Envelope>\"\r\n")
        .headers(headers_0))
    setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}
Run Code Online (Sandbox Code Playgroud)

soap gatling

5
推荐指数
1
解决办法
6764
查看次数