从应用程序外部配置 JAX-WS @WebServiceRef 客户端

Configure JAX-WS @WebServiceRef client from outside the application

我想从应用程序外部配置托管 JAX-WS 客户端(注入 @WebServiceRef,最好使用 WebLogic 管理控制台。

例如,设置将在 HTTP 请求中发送的用户名和密码,以在执行 Web 服务调用时在服务器上进行身份验证。

明确地说,手动执行需要我实现它,而使用容器提供的功能只需要配置。

我可以使用 SAP NetWeaver 来完成,是否可以使用 WebLogic 来完成?

@Stateless
public class HolidayClientImpl {

    // I want this dependency to be already configured, instead of doing it myself.
    @WebServiceRef
    private MyRemoteService myRemoteService;

}

经过大量搜索后,我没有发现此功能在 WebLogic 中可用。它不存在,至少在版本 10.3.6 和 12 中也不存在。

这意味着您必须实现客户端配置,如下所示:

MyPort port = service.getHTTPPort();
Map<String, Object> requestContext = ((BindingProvider) port).getRequestContext();

// URL
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://www.remoteservice.com/service");

// Timeouts
requestContext.put(BindingProviderProperties.CONNECT_TIMEOUT, 5000);
requestContext.put(BindingProviderProperties.REQUEST_TIMEOUT, 30000);

// Authentication
requestContext.put(BindingProvider.USERNAME_PROPERTY, "user");
requestContext.put(BindingProvider.PASSWORD_PROPERTY, "password");