我对此感到疑惑:使用Interceptor检查一些SOAP标头,如何中止拦截器链但仍然向用户发出错误?
抛出一个错误对输出有效,但请求仍在处理中,我宁愿不让所有服务检查消息上下文中的某些标志.
中止"message.getInterceptorChain().abort();" 真的中止所有处理,但是也没有任何东西返回给客户端.
什么是正确的方法?
public class HeadersInterceptor extends AbstractSoapInterceptor {
public HeadersInterceptor() {
super(Phase.PRE_LOGICAL);
}
@Override
public void handleMessage(SoapMessage message) throws Fault {
Exchange exchange = message.getExchange();
BindingOperationInfo bop = exchange.getBindingOperationInfo();
Method action = ((MethodDispatcher) exchange.get(Service.class)
.get(MethodDispatcher.class.getName())).getMethod(bop);
if (action.isAnnotationPresent(NeedsHeaders.class)
&& !headersPresent(message)) {
Fault fault = new Fault(new Exception("No headers Exception"));
fault.setFaultCode(new QName("Client"));
try {
Document doc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().newDocument();
Element detail = doc.createElementNS(Soap12.SOAP_NAMESPACE, "mynamespace");
detail.setTextContent("Missing some headers...blah");
fault.setDetail(detail);
} catch (ParserConfigurationException e) {
}
// bad: message.getInterceptorChain().abort();
throw fault; …Run Code Online (Sandbox Code Playgroud) 我有一个更复杂的JQ表达式,用于处理对象数组。
输入看起来像这样:
[
{ "key": "1", "value": "value 1"},
{ "key": "2", "value": "value 2"},
{ "key": "1", "value": "value 3"},
]
Run Code Online (Sandbox Code Playgroud)
我想要得到的是:
{
"1": { "values": ["value 1", "value 3"] },
"2": { "values": ["value 2"] }
}
Run Code Online (Sandbox Code Playgroud)
或者,对于我的用例:
{
"1": [ "value 1", "value 3" ],
"2": [ "value 2" ]
}
Run Code Online (Sandbox Code Playgroud)
也可以。
我已经尝试过使用它,… | { (.key): [.value] }但是结果是(以后没有出现任何意外),以后出现的键只会覆盖已经存在的键。我要完成的工作类似于“创建新的键/值对或将.value添加到已经存在的'values'数组中”。
我正在尝试将Mootools(Request.JSON)与JSF一起使用 - 主要是因为我前段时间在CakePHP中编写了一个类似的应用程序,并希望重用大部分JS部分.
有没有办法使用像无标记facelet这样的请求返回纯文本("application/json")?
我想出的唯一解决方案是使用HttpServlet并将其注册到web.xml中的服务URL.这种方法可以正常返回一个没有任何标记的文件,但我更倾向于使用我注入Spring的ManagedProperties,而不是仅限于WebApplicationContextUtils.
我错过了什么或是推荐的方式吗?