当前位置: 首页 > 知识库问答 >
问题:

Java RESTful 客户端在服务器上运行时无法调用 api。

东方灵均
2023-03-14

我有一个RESTful服务在Java14SpringBoot微服务上运行。我从运行在Java 7应用程序上的客户机调用这个。

+----------------------+          +-------------------------------+
|  Java 7 REST Client  |  ---->   |  Java 14 Spring Boot Service  |
+----------------------+          +-------------------------------+

我有一个调用api的RESful客户端。当我从testmain方法调用它时,它成功工作,我得到了预期的结果,客户端和服务器上没有错误。

问题

当我在JBoss中启动Java7(Struts)应用程序,并通过同一个RESTful客户端调用api时,我收到了错误。

在 Java 14 服务器上:

java.lang.StackOverflowError: null
    at com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer.findName(ByteQuadsCanonicalizer.java:576) ~[jackson-core-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.findName(UTF8StreamJsonParser.java:2266) ~[jackson-core-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.parseLongName(UTF8StreamJsonParser.java:1875) ~[jackson-core-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.parseMediumName2(UTF8StreamJsonParser.java:1839) ~[jackson-core-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.parseMediumName(UTF8StreamJsonParser.java:1796) ~[jackson-core-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._parseName(UTF8StreamJsonParser.java:1731) ~[jackson-core-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:761) ~[jackson-core-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:646) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:893) ~[jackson-databind-2.11.0.jar:2.11.0]
    at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:652) ~[jackson-databind-2.11.0.jar:2.11.0]

在Java 7 Struts应用程序客户端上:

17:13:48,498 ERROR [stderr] (http--0.0.0.0-8443-1) Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/JsonMappingException$Reference
17:13:48,499 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:541)
17:13:48,499 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:143)
17:13:48,499 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:464)
17:13:48,499 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:525)
17:13:48,499 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:143)
17:13:48,499 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:464)
17:13:48,499 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:525)
17:13:48,499 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:143)
17:13:48,499 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:464)
17:13:48,500 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:525)
17:13:48,500 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:143)
17:13:48,500 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:464)
17:13:48,500 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:525)
17:13:48,500 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:143)
17:13:48,500 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:464)
17:13:48,500 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:525)
17:13:48,500 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:143)
17:13:48,500 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:464)
...

我认为这个问题是因为当Struts Java 7客户机在JBoss中运行时,类路径与主类路径是不同的。

问题

在 JBoss 中运行时,如何解决此问题并成功调用 api?

我尝试将以下依赖项添加到客户端和服务器,这没有区别。

    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.11.1</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.11.1</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.11.1</version>
    </dependency>

更多信息:

Java 7 REST客户端:

private static ApprovalResponse callSubmitApprovals(String endpointUrl, ApprovalRequest approvalRequest, String token) {
    //System.out.println(endpointUrl);
    try {
        ClientResource cr = new ClientResource(endpointUrl);
        ChallengeResponse challengeResponse = new ChallengeResponse(ChallengeScheme.HTTP_OAUTH_BEARER);
        challengeResponse.setRawValue(token);
        cr.setChallengeResponse(challengeResponse);

        Request req = cr.getRequest();
        Series<Header> headerValue = new Series<>(Header.class);
        req.getAttributes().put(HeaderConstants.ATTRIBUTE_HEADERS, headerValue);

        Representation representation = cr.post(approvalRequest);
        String json = representation.getText();
        //System.out.println(json);

        // now convert the response to java
        ObjectMapper objectMapper = new ObjectMapper();
        ApprovalResponse approvalResponse = objectMapper.readValue(json, ApprovalResponse.class);
        //System.out.println(approvalResponse);
        System.out.println(approvalResponse.getApprovalId());

        return approvalResponse;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

它在这一行失败:

Representation representation = cr.post(approvalRequest);

Spring Boot (Java 14)资源:

@RestController
public class ApprovalSubmitResource {

    @Autowired
    ApprovalSubmitService approvalSubmitService;

    @PostMapping(value = "/rest/approvals-submit", consumes=MediaType.APPLICATION_JSON_VALUE, produces={MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
    public @ResponseBody ResponseEntity<ApprovalResponse> submit(@RequestHeader(name="Authorization") String token, @RequestBody ApprovalRequest approvalRequest) {
        ApprovalResponse approvalResponse = approvalSubmitService.submit(approvalRequest);
        approvalResponse.setApprovalId("test id from server");
        return ResponseEntity.ok(approvalResponse);
    }
}

更多信息:

我发现了问题所在,但我不确定如何解决它。

当我执行以下操作时:

        Gson gson = new Gson();
        String approvalRequestJsonStr = gson.toJson(approvalRequest);

当我运行JBoss时,使用批准请求,将对象转换为JSON时出现异常。

Caused by: java.lang.StackOverflowError
18:40:26,836 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.stream.JsonWriter.peek(JsonWriter.java:350)
18:40:26,836 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.stream.JsonWriter.beforeName(JsonWriter.java:565)
18:40:26,836 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.stream.JsonWriter.writeDeferredName(JsonWriter.java:386)
18:40:26,836 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.stream.JsonWriter.value(JsonWriter.java:402)
18:40:26,836 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.TypeAdapters$13.write(TypeAdapters.java:353)
18:40:26,836 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.TypeAdapters$13.write(TypeAdapters.java:337)
18:40:26,836 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
18:40:26,836 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89)
18:40:26,837 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195)
18:40:26,837 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.ObjectTypeAdapter.write(ObjectTypeAdapter.java:105)
18:40:26,837 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
18:40:26,837 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96)
18:40:26,837 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60)
18:40:26,837 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
18:40:26,837 ERROR [stderr] (http--0.0.0.0-8443-1)  at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89)
...

共有1个答案

祝灼光
2023-03-14

我通过不使用json而是使用xml作为有效负载来解决这个问题:

客户

    try {
        ClientResource cr = new ClientResource(endpointUrl);
        ChallengeResponse challengeResponse = new ChallengeResponse(ChallengeScheme.HTTP_OAUTH_BEARER);
        challengeResponse.setRawValue(token);
        cr.setChallengeResponse(challengeResponse);

        Request req = cr.getRequest();
        Series<Header> headerValue = new Series<>(Header.class);
        req.getAttributes().put(HeaderConstants.ATTRIBUTE_HEADERS, headerValue);

        XStream xstream = new XStream();
        xstream.alias("approvalRequest", ApprovalRequest.class);
        String xmlString = xstream.toXML(approvalRequest);

        ApprovalResponse approvalResponse = cr.post(xmlString, ApprovalResponse.class);

        System.out.println(approvalResponse.getApprovalId());

        return approvalResponse;
    } catch (Exception e) {
        e.printStackTrace();
    }

服务器

@PostMapping(value = "/rest/approvals-submit", consumes=MediaType.APPLICATION_JSON_VALUE, produces={MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
public @ResponseBody ResponseEntity<ApprovalResponse> submit(@RequestHeader(name="Authorization") String token, @RequestBody String approvalRequestXML) {
    System.out.println("ApprovalSubmitResource: "+approvalRequestXML);
    XStream xstream = new XStream();
    xstream.allowTypesByWildcard(new String[] {
            "com.nexct.approvalservice.**"
    });
    xstream.alias("approvalRequest", ApprovalRequest.class);
    ApprovalRequest approvalRequest = (ApprovalRequest) xstream.fromXML(approvalRequestXML);

    System.out.println("ApprovalSubmitResource approvalRequest: "+approvalRequest);
    System.out.println("ApprovalSubmitResource: "+approvalRequest.getMessageToEvaluator());
    //ApprovalResponse approvalResponse = approvalSubmitService.submit(approvalRequest);
    ApprovalResponse approvalResponse = new ApprovalResponse();
    System.out.println("ApprovalSubmitResource: "+approvalResponse);
    approvalResponse.setApprovalId("test id from server");
    return ResponseEntity.ok(approvalResponse);
}
 类似资料:
  • 问题内容: 我想在两个或更多不同的node.js应用程序服务器之间启用基于套接字的p2p通信。我正在使用socket.io处理给定服务器与其服务的Web应用程序之间的所有此类通信- 但我正在寻找的是一种服务器与服务器之间进行通信的方法。 我最初以为它像这样简单: 但是,事实证明,服务器端socket.io实现没有提供“连接”方法,仅提供了侦听方法。 为什么是这样?为什么不能将节点应用程序服务器视为

  • 我想在一些计算机之间建立点对点连接,这样用户就可以在没有外部服务器的情况下聊天和交换文件。我最初的想法如下: 我在服务器上制作了一个中央服务器插座,所有应用程序都可以连接到该插座。此ServerSocket跟踪已连接的套接字(客户端),并将新连接的客户端的IP和端口提供给所有其他客户端。每个客户端都会创建一个新的ServerSocket,所有客户端都可以连接到它。 换句话说:每个客户端都有一个Se

  • 我已经看了很长一段时间了,在互联网上浏览了所有不同的帖子,看看是否能找到有相同问题的人,但不知为什么,我似乎是唯一有这个问题的人。 我有一个ASP。net核心服务器,运行Grpc的基本迎宾服务。使用程序“BloomRPG”调用此服务器效果很好,而且响应时间也很长。然而,当我试图从自己编写的(非常基本的)客户机上执行同样的操作时,我会遇到以下错误: 在客户机上: dbug:Grpc。网客户内部的Gr

  • 编译 本例涉及到多模块 Maven 项目的组织 在例子 chapter2 目录下,执行 mvn clean package 输出如下 Listing 2.6 Build Output chapter2>mvn clean package [INFO] Scanning for projects... [INFO] -----------------------------------------

  • 我无法连接到我的节点。js服务器。当通过节点使用http web服务器在本地运行它时,它工作得很好,但是当连接到外部时,它会加载<code>socket.io。js文件很好,但当尝试使用套接字时,它会从URL中删除端口,无法连接。 而不是在网络请求中执行此操作: http://external-domain.com:3000/socket.io/?EIO=3 它是这样做的: http://exte

  • 下面的代码片段显示了如何在gRPC AspNet核心应用程序中启用gRPC web: 客户端应用程序的代码如下所示: