1
我正在處理其他應用程序,並且我的其他應用程序總是通過傳遞一些參數通過http headers來調用。而且我的rest應用程序中有一個過濾器被調用每個請求並從http頭中檢索參數,如下所示。如何通過HTTP集成動態使用spring集成傳遞值
@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);
}
我的其他應用程序反過來使用spring集成調用soap服務。並且調用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","[email protected]");
connection1.addRequestProperty("user-name","ws_user1");
return true;
}
但我需要通過「用戶電子郵件」和「用戶名」,而不是動態靜態之一,即,這是我在過濾器中已經接收到的數據。任何人都可以幫助我解決這個問題。提前致謝。