Camel 无法将交换正文转换为自定义对象

s4n0splo  于 2023-04-11  发布在  Apache
关注(0)|答案(1)|浏览(200)

我正试图转换jwt令牌到对象,以获得使用SpringDSL访问令牌

<to uri="ref:oauthTokenEndpoint" />
        <log message="Auth Token Response is ${body} " loggingLevel="INFO" />
        <choice>
            <when>
                <simple>${header.CamelHttpResponseCode} == '200'</simple>
                <to uri="bean:getResponseCode?method=processOAuthToken" />
                <to uri="direct:sendEventPostServiceCall" />
            </when>
            <otherwise>
              <log message="[POST] Error getting token response code is ${header.CamelHttpResponseCode} " loggingLevel="INFO" />
            </otherwise>
        </choice>

下面是进程代码

TokenResponse tokenResponse =   exchange.getIn().getBody(TokenResponse.class);
    logger.debug("exchange body Token Response "+tokenResponse);
    exchange.getOut().setHeader("jwt", tokenResponse.access_token );

下面是TokenResponse类

public class TokenResponse {

    String token_type;
    String expires_in;
    String ext_expires_in;
    String access_token;
    
    public String getToken_type() {
        return token_type;
    }
    public void setToken_type(String token_type) {
        this.token_type = token_type;
    }
    public String getExpires_in() {
        return expires_in;
    }
    public void setExpires_in(String expires_in) {
        this.expires_in = expires_in;
    }
    public String getExt_expires_in() {
        return ext_expires_in;
    }
    public void setExt_expires_in(String ext_expires_in) {
        this.ext_expires_in = ext_expires_in;
    }
    public String getAccess_token() {
        return access_token;
    }
    public void setAccess_token(String access_token) {
        this.access_token = access_token;
    }
 }

我总是在process方法处得到null。我需要在这里设置任何转换器或JSON ObjectMapper吗?

dgiusagp

dgiusagp1#

我发现,这是在处理令牌之前记录的问题,一旦我删除了下面的记录语句
我可以在exchange.getIn().getBody...中接收令牌

相关问题