response.readentity(string.class)读取响应失败

vd8tlhqk  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(515)

最近我突然遇到了一个readentityapi的问题。我已经附上pom.xml和使用的代码可以有人帮我找到这里的问题,代码是阅读的回应

Response serverResponse = executeRequest(httpPost, log);
String responseData = serverResponse.readEntity(String.class);

我得到的错误是

java.lang.IllegalStateException: Method not supported on an outbound message.
    at org.glassfish.jersey.message.internal.OutboundJaxrsResponse.readEntity(OutboundJaxrsResponse.java:144)

pom.xml文件

<dependencies>
        <!-- https://mvnrepository.com/artifact/com.ibm.mfp/adapter-maven-api -->
        <dependency>
            <groupId>com.ibm.mfp</groupId>
            <artifactId>adapter-maven-api</artifactId>
            <version>8.0.2018071507</version>
            <scope>provided</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>3.0.4.RELEASE</version>
            <type>jar</type>
        </dependency>

        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-io -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.3.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.9.7</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.ibm.mfp/mfp-java-token-validator -->
        <dependency>
            <groupId>com.ibm.mfp</groupId>
            <artifactId>mfp-java-token-validator</artifactId>
            <version>8.0.2017020112</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.ibm.mfp/mfp-security-checks-base -->
        <dependency>
            <groupId>com.ibm.mfp</groupId>
            <artifactId>mfp-security-checks-base</artifactId>
            <version>8.0.2018030404</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.5</version>
        </dependency>
<!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api -->
<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.0.1</version>
</dependency>

错误消息:
嵌套的异常是java.lang.abstractmethoderror:javax/ws/rs/core/response.readentity(ljava/lang/class;)ljava/lang/object;,状态=500

zfciruhq

zfciruhq1#

我通过使用

String responseData = serverResponse.getEntity().toString();

而不是

String responseData = serverResponse.readEntity(String.class);

这与我们形成回应的方式有关。我在操纵React

Response.ResponseBuilder responseBuilder = Response
                .status(serverResponse.getStatusLine().getStatusCode())               
                .entity(responseData != null && !responseData.isEmpty() ? responseData : "{}");

然后我用 String responseData = serverResponse.readEntity(String.class); 当我把readentity改为getentity时,它对我来说很好。

相关问题