无法将交换主体转换为自定义对象

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

我正在尝试将 jwt 令牌转换为对象以使用 spring DSL 获取访问令牌

 <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 吗?

apache-camel spring-camel camel-http
1个回答
0
投票

我发现,在处理令牌之前记录是有问题的,一旦我删除了以下记录语句,

我能够在

exchange.getIn().getBody...

中收到代币
© www.soinside.com 2019 - 2024. All rights reserved.