在weblogic中更改ejb3 webservice url

pen*_*ike 7 web-services ejb-3.0

我有一个EJB3会话bean注释@WebService(serviceName="MyServiceName", portName="MyPortName").当它部署到Weblogic 11g中时,服务端点位于

host:port/BeanClassName/MyServiceName

是否可以更改Web服务的服务端点地址?即到

host:port/my/context/root/something/MyServiceName

我尝试使用weblogic-webservices.xml部署描述符,但它需要webservices.xml描述符,该描述符需要WSDL位置元素,但是应该由服务器生成,并且它的位置在dev和prod环境中不同.

pen*_*ike 2

假设您有一个 EJB

package com.example;
@Stateless
@WebService
OrganizationService {...}
Run Code Online (Sandbox Code Playgroud)

首先,您应该为其编写一个 webservices.xml 文件,如下所示,因为它的部分将从完成实际端点配置的 weblogic-webservices.xml 引用回来。

webservices.xml(注意:通过添加 webservices.xml,类中的 webservice 注释将被覆盖!):

<?xml version="1.0" encoding="UTF-8"?>
<webservices xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2">
  <webservice-description>
  <!-- just a label, can be anything you want -->
  <webservice-description-name>MyServiceName</webservice-description-name>
  <port-component>
    <!-- just a label, can be anything you want -->
    <port-component-name>MyServicePort</port-component-name>
        <!-- Target namespace from wsdl -->
        <wsdl-port xmlns:ex="http://example.com/target/name/Space">ex:MyService</wsdl-port>
        <!-- Fully qualified class name of the ejb interface/bean providing the service -->
        <service-endpoint-interface>com.example.OrganizationService</service-endpoint-interface>
        <service-impl-bean>
        <!-- The class name of the bean providing the service -->
          <ejb-link>OrganizationService</ejb-link>
        </service-impl-bean>
    </port-component>
  </webservice-description>
</webservices>
Run Code Online (Sandbox Code Playgroud)

然后在 weblogic-webservices.xml 中您可以定义您想要的任何端点。

weblogic-webservices.xml:

<?xml version='1.0' encoding='UTF-8'?>
<weblogic-webservices xmlns="http://www.bea.com/ns/weblogic/weblogic-webservices" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-webservices http://www.bea.com/ns/weblogic/weblogic-webservices/1.0/weblogic-webservices.xsd">
  <webservice-description>
  <!-- This must match the name given in webservices.xml -->
   <webservice-description-name>MyServiceName</webservice-description-name>
   <webservice-type>JAXWS</webservice-type>
    <port-component>
     <!-- This must match the name given in webservices.xml -->
      <port-component-name>MyServicePort</port-component-name>
      <service-endpoint-address>
        <webservice-contextpath>/myContextPath</webservice-contextpath>
        <webservice-serviceuri>/myServiceURI</webservice-serviceuri>
      </service-endpoint-address>
    </port-component>
  </webservice-description>
</weblogic-webservices>
Run Code Online (Sandbox Code Playgroud)