我有一个预先存在的 Web 服务“连接”(SOAP),如果可能的话,我想在不使用 Swing 框架的情况下进行调用。我遵循接触优先开发,使用 cxf/wsdl2java 工具生成我的 java 文件。
我希望从 java 对象中提取用户名和密码并将其放入 SOAP 对象中,然后发送到我的本地主机 Web 服务上。
当将 Connect 对象作为主体发送到“direct:start”时,出现异常...
Caused by: java.lang.IllegalArgumentException: Get the wrong parameter size to invoke the out service, Expect size 2, Parameter size 1. Please check if the message body matches the CXFEndpoint POJO Dataformat request.
我已经检查过第一个参数实际上是传入的 Connect 对象的实例。
我是否需要在其中一个类中添加一些附加注释,测试方法是否无效或
我应该遵循其他模式吗?
public class TestConnectCXF extends CamelTestSupport
{
@Override
protected RouteBuilder createRouteBuilder() throws Exception
{
return new RouteBuilder()
{
String cxfAddressLine = "cxf:http://localhost:8081/nuxeo/webservices/privateadservice?wsdlURL=wsdl/privateadservice.wsdl" //
+ "&dataFormat=POJO" //
+ "&serviceClass=com.sandbox.camelfeed.PrivateAdServiceInterface" //
+ "&serviceName={http://ws.sandboxtest.com/}PrivateAdService" //
+ "&synchronous=true" //
+ "&loggingFeatureEnabled=true" //
+ "&portName={http://ws.sandboxtest.com/}PrivateAdServiceInterfacePort";
@Override
public void configure() throws Exception
{
from("direct:start").to(cxfAddressLine).to("mock:end");
}
};
}
@Test
public void testConnectViaPojo() throws InterruptedException
{
Connect connectToServer = new Connect();
connectToServer.setUserName("FakeUser");
connectToServer.setPassword("scrubbed");
template.sendBody("direct:start", connectToServer);
Thread.sleep(1000);
}
}
我是骆驼和网络服务的新手,因此任何有用的指示将不胜感激。
附加信息
使用骆驼2.10,Java 1.6
从 wsdl2java 生成的类
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "connect", propOrder = {
"userName",
"password"
})
public class Connect {
protected String userName;
protected String password;
public String getUserName() {
return userName;
}
public void setUserName(String value) {
this.userName = value;
}
public String getPassword() {
return password;
}
public void setPassword(String value) {
this.password = value;
}
}
@WebService(targetNamespace = "http://ws.sandboxtest.com/", name = "PrivateAdServiceInterface")
@XmlSeeAlso({ObjectFactory.class})
public interface PrivateAdServiceInterface {
// Omitted Code relating to other web calls
@WebResult(name = "return", targetNamespace = "")
@RequestWrapper(localName = "connect", targetNamespace = "http://ws.sandboxtest.com/", className = "com.sandbox.camelfeed.Connect")
@WebMethod
@ResponseWrapper(localName = "connectResponse", targetNamespace = "http://ws.sandboxtest.com/", className = "com.sandbox.camelfeed.ConnectResponse")
public java.lang.String connect(
@WebParam(name = "userName", targetNamespace = "")
java.lang.String userName,
@WebParam(name = "password", targetNamespace = "")
java.lang.String password
) throws ClientException_Exception;
}
@XmlRegistry
public class ObjectFactory {
{
// Omitted other web calls information
private final static QName _Connect_QNAME = new QName("http://ws.sandboxtest.com/", "connect");
@XmlElementDecl(namespace = "http://ws.sandboxtest.com/", name = "connect")
public JAXBElement<Connect> createConnect(Connect value) {
return new JAXBElement<Connect>(_Connect_QNAME, Connect.class, null, value);
}
}