Apache CXF -Установить HTTP-заголовок

Мне нужно установить некоторые поля заголовка http в клиенте Apache CXF:

Я попробовал это через Interceptor:

    public class HttpHeaderInterceptor extends AbstractPhaseInterceptor<Message> {

    private String userId;
    private String xAuthorizeRoles;
    private String host;


    public HttpHeaderInterceptor() {
        super(Phase.POST_PROTOCOL);
    }

    @Override
    public void handleMessage(Message message) throws Fault {
        Map<String, List> headers = (Map<String, List>) message.get(Message.PROTOCOL_HEADERS);
        try {
            System.out.println("HttpHeaderInterceptor Host: " + host + " UserId: " + userId + " X-AUTHORIZE-roles: " + xAuthorizeRoles);
            headers.put("Host", Collections.singletonList(host));
            headers.put("UserId", Collections.singletonList(userId));
            headers.put("X-AUTHORIZE-roles", Collections.singletonList(xAuthorizeRoles));
        } catch (Exception ce) {
            throw new Fault(ce);
        }
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public void setxAuthorizeRoles(String xAuthorizeRoles) {
        this.xAuthorizeRoles = xAuthorizeRoles;
    }

    public void setHost(String host) {
        this.host = host;
    }
}

в моем классе динамического клиента метод:

public void setHttHeaderInterceptor(String userId, String xAuthorizeRoles){
    Client cxfClient = ClientProxy.getClient(this.abgWebServicePort);
    HttpHeaderInterceptor httpHeaderInterceptor = new HttpHeaderInterceptor();
    httpHeaderInterceptor.setHost("example.org");
    httpHeaderInterceptor.setUserId(userId);
    httpHeaderInterceptor.setxAuthorizeRoles(xAuthorizeRoles);
    cxfClient.getOutInterceptors().add(httpHeaderInterceptor);
}

вызывается до того, как я вызову удаленную службу:

Для каждого вызова userId и xAuthorizeRoles должны различаться, но когда я проверяю вызовы через tcpdump, все вызовы имеют одинаковые значения в полях заголовка.

Есть идеи?

16
задан Alex 7 May 2012 в 09:29
поделиться