尝试向我的宁静服务收到的每个请求添加标头。下面的入站http拦截器被调用,但不会添加标头。http请求拦截器 - 使用cxf的restful web服务
package com.client.interceptors;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
public class ClientInterceptor extends AbstractPhaseInterceptor<Message> {
public ClientInterceptor() {
super(Phase.PRE_INVOKE); // Put this interceptor in this phase
System.out.println("inside constructor");
}
public void handleMessage(Message msg) throws Fault {
// process the message
System.out.println("inside interceptor");
Map<String, List> headers = (Map<String, List>) msg
.get(Message.PROTOCOL_HEADERS);
headers.put("token",
Collections.singletonList("abcd1234xyz56sa"));
msg.put(Message.PROTOCOL_HEADERS, headers);
}
}
这是如何实现的?
但是你调用宁静的web服务? – Krishna 2014-09-22 05:15:48
是的,这是一个简单的GET服务,我从浏览器调用 – skonka 2014-09-22 05:20:01
如果你只是想从浏览器中醒来,那么你可以使用工具为同一个海报:) – Krishna 2014-09-22 05:21:59