从 xfire 客户端调用 axis2 Web 服务:未找到操作的端点引用 (EPR)

发布于 2024-08-22 02:43:30 字数 2109 浏览 10 评论 0原文

我需要通过 https 从 xfire 客户端使用 ws-security (用户名令牌)调用 axis2 Web 服务。我可以通过 xfire 动态客户端 进行练习,但是 wsdl 基本客户端(即生成来自 wsdl 的 java 存根)。有人能指出我可能出了什么问题吗(存根、ws-security 或其他)?

例外:

线程“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);
}

I need to call axis2 web service with ws-security (username token) from xfire client over https. I could do the exercise via xfire dynamic client, but no luck with wsdl base client (i.e. generate java stub from wsdl). Could anybody point me out what could be wrong (stub, ws-security something else)?

Exception:

Exception in thread "main"
org.codehaus.xfire.XFireRuntimeException:
Could not invoke service.. Nested
exception is
org.codehaus.xfire.fault.XFireFault:
The endpoint reference (EPR) for the
Operation not found is
https://localhost/services/DataServiceSample2
and the WSA Action =
org.codehaus.xfire.fault.XFireFault:
The endpoint reference (EPR) for the
Operation not found is
https://localhost/services/DataServiceSample2
and the WSA Action =

Code:

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);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

阿楠 2024-08-29 02:43:30

请尝试将 localhost 替换为运行服务的计算机的 IP 地址。 您可以

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

尝试像这样指定 IP 地址。

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

请注意,使用不明确的参数传送代码被认为是不好的做法。因此,在测试之后,您需要将硬编码的 IP 地址替换为一些可以轻松配置的变量。

Please try replacing the localhost with ip address of the machine where your service is running. Instead of

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

You can try specifying the ip address like this

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

Please note that it is considered bad practice to ship code with ambiguous parameters. So after testing it you will need to replace hard coded ip address with some variable which can be easily configured.

那些过往 2024-08-29 02:43:30

我在 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);

I'm missing "SOAPAction" parameter in HTTP header. You could set it directly as

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

AFAIK in XFire client it could be archived in such way:

    Map m = new HashMap();
    m.put("SOAPAction", "urn:executeXml");
    client.setProperty(CommonsHttpMessageSender.HTTP_HEADERS, m);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文