我工作的一个支架应用,我的支架应用总是通过HTTP headers.And传递一些参数叫我在休息的应用程序的过滤器,其被调用为每个请求和如下所示检索来自HTTP标头的参数。
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpServletRequest=(HttpServletRequest) request;
String email = httpServletRequest.getHeader("user-email");
String userName = httpServletRequest.getHeader("user-name");
chain.doFilter(request, response);
}
我又将剩下的应用程序调用使用弹簧的SOAP服务integration.And代码调用SOAP服务是如下。
@RequestMapping(value = "/projects", method = RequestMethod.GET, produces = "application/json")
public @ResponseBody List<Project> getProject(HttpServletRequest httpRequest) {
GetAuthorizedWebSendTransferProjects request = new GetAuthorizedWebSendTransferProjects();
GetAuthorizedWebSendTransferProjectsResponse response = gw.getResponse(request);
JAXBElement<ArrayOfProjectContainer> arr = response.getGetAuthorizedWebSendTransferProjectsResult();
ArrayOfProjectContainer arr1 = arr.getValue();
List<ProjectContainer> arr2 = arr1.getProjectContainer();
List<Project> projects = getPopulatedProjectList(arr2);
return projects;
}
应用程序的context.xml
<int:chain input-channel="requestChannel" output-channel="outputChannel">
<int-ws:header-enricher>
<int-ws:soap-action
value="http://tempuri.org/IPermissionService/GetAuthorizedWebSendTransferProjects"/>
</int-ws:header-enricher>
<int-ws:outbound-gateway
uri="http://10.255.2.51/PermissionService.svc?wsdl" marshaller="marshaller"
unmarshaller="marshaller" interceptor="addHttpHeaderInterceptor"/>
</int:chain>
我也有一个拦截器添加参数以HTTP标头是一个静态数据。
@Override
public boolean handleRequest(MessageContext messageContext)
throws WebServiceClientException {
TransportContext context = TransportContextHolder.getTransportContext();
HttpUrlConnection connection = (HttpUrlConnection) context.getConnection();
HttpURLConnection connection1= connection.getConnection();
connection1.addRequestProperty("user-email","ws_user1@biopacstest.domain");
connection1.addRequestProperty("user-name","ws_user1");
return true;
}
但是,我需要通过“用户电子邮件”和“用户名”,而不是动态的静态的,即,这是我在过滤器中已接收的数据。 任何人都可以帮我解决这个问题。 提前致谢。