Change ejb3 webservice url in weblogic
I have an EJB3 session bean annotated with @WebService(serviceName="MyServiceName", portName="MyPortName")
. When it is deployed into Weblogic 11g the service endpoint is located at
host:port/BeanClassName/MyServiceName
Is it possible to change the service endpoint address of the webservice? i.e. to
host:port/my/context/roo开发者_开发技巧t/something/MyServiceName
I tried to use the weblogic-webservices.xml deployment descriptor, but it requires the webservices.xml descriptor which requires a WSDL location element, but that should be generated by the server and the location of it differs in the dev and prod environments.
Suppose you have an EJB
package com.example;
@Stateless
@WebService
OrganizationService {...}
First you should write a webservices.xml file for it as follows, since its sections will be referenced back from weblogic-webservices.xml where the actual endpoint configuration is done.
webservices.xml (Caution: by adding webservices.xml webservice annotations in classes are overridden!):
<?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>
Then in the weblogic-webservices.xml you can define whatever endpoint you want.
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>
I found a solution that adds another endpoint to the one generated from a JAX-WS web service by WebLogic.
I have a web service like this (simplified):
@WebService(name = "ClientService",
portName = "ClientService",
serviceName = "ClientService")
public class ClientWebService {
@WebMethod
public ExtClient findClientDetails(String ref) {
// etc.
}
}
The WebLogic endpoint is <context>/ClientService
but I want it to be <context>/client/01
.
In web.xml
I have:
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>WebServiceServlet</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>WebServiceServlet</servlet-name>
<url-pattern>/client/01</url-pattern>
</servlet-mapping>
Now WebLogic offers the web service at both endpoints.
Specifying the URI in web.xml
is needed because the JAX-WS library in WebLogic ignores endpoint specifications in sun-jaxws.xml
. (In contrast, GlassFish only exposes enpoints that are specified in sun-jaxws.xml
.)
精彩评论