Jus*_*ick 5 java soap web-services jax-ws
我正在尝试创建一个通用的Web服务,它始终以"OK"响应,无论请求的标题或正文内容如何.我可以在Axis2中用a做这个RawXMLInOutMessageReceiver
,但我更愿意使用JAX-WS(我是全新的).到目前为止,我有一个简单的界面:
@WebService
public interface DummyService {
@WebMethod String processMessage(Object obj);
}
Run Code Online (Sandbox Code Playgroud)
和一个简单的实现:
@WebService(endpointInterface = "com.dummyservice.DummyService")
public class DummyServiceImpl implements DummyService {
@Override
public String processMessage(Object obj) {
return "OK";
}
}
Run Code Online (Sandbox Code Playgroud)
我可以成功发布服务javax.xml.ws.Endpoint#publish(...)
,但是当我用简单的SOAP请求命中时,例如
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<derp/>
</soapenv:Body>
</soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)
我受到了SOAPFault的欢迎Cannot find dispatch method for {}derp
.
是否有可能创建一个通用/愚蠢的Web服务,它将使用JAX-WS确认所有内容?如果是这样,有人会指出我正确的方向吗?
编辑
感谢麦克道尔的小费,我能够做到这一点SOAPHandler
:
public class DummySOAPHandler implements SOAPHandler {
@Override
public boolean handleMessage(MessageContext context) {
return process((SOAPMessageContext) context);
}
@Override
public boolean handleFault(MessageContext context) {
return process((SOAPMessageContext) context);
}
@Override
public void close(MessageContext context) { }
@Override
public Set<QName> getHeaders() {
return null;
}
private boolean process(SOAPMessageContext ctx) {
try {
SOAPMessage message = ctx.getMessage();
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
SOAPBody body = message.getSOAPBody();
if ((Boolean) ctx.get (MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
Iterator<SOAPElement> bodyChildren = body.getChildElements();
while (bodyChildren.hasNext()) {
SOAPElement child = bodyChildren.next();
child.detachNode();
}
body.addBodyElement(envelope.createName("OK"));
message.saveChanges();
}
} catch (SOAPException e) {
e.printStackTrace();
}
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
我希望您的服务期待以下形式:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dum="http://yournamespace/">
<soapenv:Header/>
<soapenv:Body>
<dum:processMessage>
<!-- xsd:anyType -->
</dum:processMessage>
</soapenv:Body>
</soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)
添加?WSDL
到您的端点并检查操作输入 XML 类型和命名空间。
您也许可以使用逻辑处理程序(javadoc)执行某些操作,将传入请求转换为这种形式 - 我还没有尝试过。
归档时间: |
|
查看次数: |
3492 次 |
最近记录: |