我需要通过https从xfire客户端使用ws-security(用户名令牌)调用axis2 Web服务。我可以通过xfire dynamic client进行练习,但是没有运气wsdl基本客户端(即从wsdl生成java存根)。任何人都可以指出我可能出错的地方(存根,ws-安全别的东西)?
例外:
线程“main”中的异常 org.codehaus.xfire.XFireRuntimeException: 无法调用服务..嵌套 例外是 org.codehaus.xfire.fault.XFireFault: 端点引用(EPR) 未找到的操作是 https://localhost/services/DataServiceSample2 和WSA行动= org.codehaus.xfire.fault.XFireFault: 端点引用(EPR) 未找到的操作是 https://localhost/services/DataServiceSample2 和WSA行动=
代码:
public static void main(String[] args) throws MalformedURLException {
ProtocolSocketFactory easy = new EasySSLProtocolSocketFactory();
Protocol protocol = new Protocol("https", easy, 9443);
Protocol.registerProtocol("https", protocol);
ObjectServiceFactory serviceFactory = new ObjectServiceFactory();
serviceFactory.setStyle("message");
Service serviceModel = serviceFactory.create(DataServiceSample2PortType.class);
XFireProxyFactory factory = new XFireProxyFactory();
DataServiceSample2PortType service = (DataServiceSample2PortType) factory.create(serviceModel, "https://localhost:9443/services/DataServiceSample2");
Client client = Client.getInstance(service);
client.addOutHandler(new DOMOutHandler());
Properties properties = new Properties();
properties.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
properties.setProperty(WSHandlerConstants.USER, "admin");
properties.setProperty(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
properties.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, PasswordHandler.class.getName());
client.addOutHandler(new WSS4JOutHandler(properties));
sab.TopCustomerResponse topCustomersInCalifornia = service.topCustomersInCalifornia(null);
}
答案 0 :(得分:0)
请尝试使用运行服务的计算机的IP地址替换 localhost 。而不是
factory.create(serviceModel,"https://localhost:9443/services/DataServiceSample2");
您可以尝试像这样指定IP地址
factory.create(serviceModel,"https://192.168.2.18:9443/services/DataServiceSample2");
请注意,使用含糊不清的参数发送代码被视为不良做法。因此,在测试之后,您需要将硬编码的IP地址替换为可以轻松配置的变量。
答案 1 :(得分:0)
我在HTTP标头中缺少“SOAPAction
”参数。您可以将其直接设置为
HttpsURLConnection conn;
...
conn.setRequestProperty("SOAPAction", "urn:executeXml");
XFire客户端中的AFAIK可以通过以下方式存档:
Map m = new HashMap();
m.put("SOAPAction", "urn:executeXml");
client.setProperty(CommonsHttpMessageSender.HTTP_HEADERS, m);