webx3中(wdetail)处理淘客的一个pipeline:
@Autowired
private HttpServletRequest request;
@Override
public void invoke(final PipelineContext pipelineContext) throws Exception {
final String ttid = request.getParameter(RUNDATA_SPID);
final String pid = ttidMappingPid.get(ttid);
if (StringUtils.isNotBlank(pid)) {
request.getParameterMap().put(TK_PID_PREFIX, pid);
request.getParameterMap().put(TK_APP_ID, "12003897");
}
pipelineContext.invokeNext();
}
请仔细的看一下,该代码有什么问题没?
有,request.getParameterMap().put(TK_PID_PREFIX, pid);会抛异常的。。。
java.lang.UnsupportedOperationException
at java.util.AbstractMap.put(AbstractMap.java:186)
at
request.getParameterMap() 这里返回的是一个 com.alibaba.citrus.service.requestcontext.parser.impl.ParserRequestContextImpl$ParameterMap
private class ParameterMap extends AbstractMap<String, String[]> {
*/
public V put(K key, V value) {
throw new UnsupportedOperationException();
}
修改方法:
rundata.getParameters().add(key, value)
rundata.getParameters()返回的是com.alibaba.citrus.service.requestcontext.parser.impl.ParameterParserImpl 有对应的params操作。。
回头看了看httpserlet.getParameterMap
java.util.Map getParameterMap()
Returns a java.util.Map of the parameters of this request. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.
Returns:
an immutable java.util.Map containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array.
所以很明显,我们的webx在这一点上还是很尊重servlet规范的