从 Spring 应用程序在 weblogic 上使用 jee 部署程序 Web 服务时出现问题(json 格式的错误请求 400 链接)

问题描述 投票:0回答:1

我使用 openFeign 通过发送一个以对象列表作为参数的 Post 请求来攻击 Web,不幸的是目标 Web 服务不理解我发送的 json 格式,因为它需要格式略有不同的 json。看代码:

@FeignClient(name = "clientfeign",url = "http://192.168.x.x:8080")
public interface SIPAERestClient {

    @PostMapping(path = "/api/method-adresse")
    List<TEbourse> checkFonctionnaire(@RequestBody List<TEbourse> demandes);
}

对象:

@Data
@AllArgsConstructor
@NoArgsConstructor
public class TEbourse {
    private int id;
    private String nom;
    private String prenom;
    private String sexe;
    private String date_naissance;
    private String lieu_naissance;
    private String matricule;
    private String statut;
}

格式化 JSON envoyer:

[
      {
      
      "ID": "12",
      "date_naissance": "08/01/84",
      "lieu_naissance": "",
      "matricule": "",
      "nom": "FOUROU",
      "prenom": "DANTES STEVE HERMANN",
      "sexe": "M",
      "statut": ""
   },
      {
      
      "ID": "20",
      "date_naissance": "02/10/98",
      "lieu_naissance": "",
      "matricule": "",
      "nom": "MOUNTOULA  NGALIEME",
      "prenom": "DESNY",
      "sexe": "M",
      "statut": ""
   },
      {
      
      "ID": "152",
      "date_naissance": "27/03/94",
      "lieu_naissance": "",
      "matricule": "",
      "nom": "NGAKOSSO  OBA",
      "prenom": "DIEU  MERCI",
      "sexe": "M",
      "statut": ""
   }
]

另一方面,部署在 webLogic 上的 Web 服务需要一个 json 格式,前面有一个键,当部署在 webLogic 上时,它与 openFeigns 发送的格式相同:

{ "tEbourse":[
      {
      "date_naissance": "08/01/84",
      "ID": "12",
      "lieu_naissance": "",
      "matricule": "",
      "nom": "FOUROU",
      "prenom": "DANTES STEVE HERMANN",
      "sexe": "M",
      "statut": ""
   },
      {
      "date_naissance": "02/10/98",
      "ID": "20",
      "lieu_naissance": "",
      "matricule": "",
      "nom": "MOUNTOULA  NGALIEME",
      "prenom": "DESNY",
      "sexe": "M",
      "statut": ""
   },
      {
      "date_naissance": "27/03/94",
      "ID": "152",
      "lieu_naissance": "",
      "matricule": "",
      "nom": "NGAKOSSO  OBA",
      "prenom": "DIEU  MERCI",
      "sexe": "M",
      "statut": ""
   }
]} 

您对这个问题有何看法?

如何通过 OpenFeign 使用来自 Spring 的类似 JSON 发送请求。

注意:此问题仅在 webLogic 上部署期间出现,但对于 Wildfly 来说一切正常

json spring java-ee-6 weblogic-10.x openfeign
1个回答
0
投票

如果您需要与 openFeigns 相同的格式,您需要为您的

TEbourse
类提供一个包装类。

应该像下面这样。

@Data
@AllArgsConstructor
@NoArgsConstructor
public class TEbourseWrapper {
    private List<TEbourse> tEbourse;
}

在您的休息客户端中执行如下操作。

@FeignClient(name = "clientfeign",url = "http://192.168.x.x:8080")
public interface SIPAERestClient {

    @PostMapping(path = "/api/method-adresse")
    TEbourseWrapper checkFonctionnaire(@RequestBody TEbourseWrapper demandes);
}


© www.soinside.com 2019 - 2024. All rights reserved.