【问题标题】:Accessing a password-protected WSDL in Weblogic when calling a web service调用 Web 服务时在 Weblogic 中访问受密码保护的 WSDL
【发布时间】:2011-03-11 23:01:44
【问题描述】:

我们正在使用 Spring 和 JAXWS 生成的客户端类来访问 weblogic 部署的应用程序中的 web 服务。定义 Web 服务的 WSDL 是远程的且受密码保护(基本的 http 身份验证)。在单元测试中,只需在 ~/.metro 文件夹中定义一个代理,并在访问时使用 url 和 http 密码即可。 Weblogic 在某些配置文件中是否有类似的技巧?或者有没有其他常见的方法来解决这个问题?

【问题讨论】:

  • ... 是远程且受密码保护的。 如何?基本身份验证?
  • 是的,基本的http认证

标签: web-services ssl wsdl weblogic jax-ws


【解决方案1】:

您可以提供自己的身份验证器。如果 WDSL 本身受到基本 HTTP 身份验证的保护,它就会工作。

@WebServiceRef(wsdlLocation = "https://laka/sito?wsdl")
static XxxService service;

public static void main(String[] args) {

    Authenticator.setDefault(new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("user", "password".toCharArray());
        }
    });

    service = new XxxService();
    Xxx port = service.getXxxPort();

    // invoke webservice and print response
    XxxResponse resp = port.foo();
    System.out.println(resp.toString());

}

【讨论】:

    【解决方案2】:

    根据文档 (Chapter 6. Using Spring Web Services on the Client):

    6.2.1.1.1. HTTP transports

    有两种实现 WebServiceMessageSender 接口用于 通过 HTTP 发送消息。默认 实施是 HttpUrlConnectionMessageSender,哪个 使用 Java 提供的设施 本身。替代方案是 CommonsHttpMessageSender,它使用 Jakarta Commons HttpClient。 使用 如果您需要更高级的,则后者 和易于使用的功能(例如 身份验证,HTTP 连接 池等)。

    (...)

    以下示例显示了如何 覆盖默认配置, 并使用 Commons Http 来 使用 HTTP 进行身份验证 身份验证:

    <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
        <constructor-arg ref="messageFactory"/>
        <property name="messageSender">
            <bean class="org.springframework.ws.transport.http.CommonsHttpMessageSender">
                <property name="credentials">
                    <bean class="org.apache.commons.httpclient.UsernamePasswordCredentials">
                        <constructor-arg value="john"/>
                        <constructor-arg value="secret"/>
                    </bean>
                </property>
            </bean>
        </property>
        <property name="defaultUri" value="http://example.com/WebService"/>
    </bean>
    

    你试过了吗?

    更新:由于您使用的是 JAX-WS 客户端(这不是我从“我们正​​在使用 Spring”中理解的),您可以:

    【讨论】:

    • 看起来不错,但我使用 org.apache.cxf.jaxws.JaxWsProxyFactoryBean 作为 Web 服务客户端 bean,而不是 Spring Web 服务模板(无法让它们与 Weblogic 9.2 和 jaxws 生成客户端存根/类)。有没有办法将两者结合起来?
    • @michuk:Erf,您应该在问题中提及此类细节以获得更好的答案。这也有助于读者不要浪费时间。
    • @Pascal 抱歉,我写道我们使用 JAXB 客户端类。我现在编辑了我的问题以明确声明我们也在使用 jaxws 存根。一段时间以来,我一直在与 jaxws 配置作斗争,包括管道元素。当我设法取得成就时,我会报告。
    • @michuk:我真的想知道 JAXB 的东西是不是一个错字。反正没问题,我实际上并没有浪费那么多时间(尤其是因为我学到了一些关于 Spring 的新东西)但是可以有;)
    • 不幸的是,我未能使其在 Weblogic 9.2 中工作。我在使用用户/密码时遇到了与不使用时不同的异常(404 与带有权限错误消息的 html),但我可以从 Firefox 访问该 Web 服务而没有问题,因此它表明问题在 spring/ 之间的某个地方jaxb 和 weblogic...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多