我需要调用Axis2 Web服务用的WS-Security(用户名令牌)从Xfire客户端通过https。我可以做这项运动时通过 XFire软件动态客户,但与WSDL基础客户端没有运气(即产生从WSDL的Java存根)。可能有人点我出了什么可能是错误的(存根,WS-Security的其它东西)?

例外:

  

异常在线程“主”   org.codehaus.xfire.XFireRuntimeException:   不能援引服务..嵌套   例外的是   org.codehaus.xfire.fault.XFireFault:   用于端点引用(EPR)   操作没有发现是   的https://本地主机/服务/ DataServiceSample2   与WSA动作=   org.codehaus.xfire.fault.XFireFault:   用于端点引用(EPR)   操作没有发现是   的https://本地主机/服务/ 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);
}
有帮助吗?

解决方案 2

我缺少“SOAPAction”参数在HTTP头中。你可以直接将其设置为

HttpsURLConnection conn;
...
conn.setRequestProperty("SOAPAction", "urn:executeXml");

AFAIK在Xfire客户端它可以被以这样的方式归档:

    Map m = new HashMap();
    m.put("SOAPAction", "urn:executeXml");
    client.setProperty(CommonsHttpMessageSender.HTTP_HEADERS, m);

其他提示

请尝试更换本地主机替换您的服务正在运行的机器的IP地址。代替

factory.create(serviceModel,"https://localhost:9443/services/DataServiceSample2");

您可以尝试指定这样的IP地址

factory.create(serviceModel,"https://192.168.2.18:9443/services/DataServiceSample2");

请注意,它被认为是不好的做法,不明确的参数船代码。所以测试之后,你会需要一些变量,它可以很容易地配置,以取代硬编码的IP地址。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top