Home > Java, SOA Suite > EJB3 web service context path in WebLogic 11g

EJB3 web service context path in WebLogic 11g

EJB3 web services are great. Simply slap on a @WebService annotation, deploy and it works. A few additional annotations can improve the interface. However, with WebLogic 11g the service endpoint becomes http://server:port/ClassName/ServiceName, where ClassName is the name of the session bean and ServiceName comes from the annotation. This is a bit ugly, the class name of the session bean is an implementation detail and should not be exposed.

Fortunately there is a solution and it keeps the code portable. First, define a generic webservices.xml file with the minimum required information for the web service:

<?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>
  <webservice-description-name>SomeService</webservice-description-name>
  <port-component>
    <port-component-name>SomeServicePort</port-component-name>
        <wsdl-port xmlns:ws="http://someserver.com/SomeService">
          ws:SomeServicePort</wsdl-port>
        <service-endpoint-interface>
          com.someserver.ws.SomeServiceRemote
        </service-endpoint-interface>
        <service-impl-bean>
          <ejb-link>SomeService</ejb-link>
        </service-impl-bean>
    </port-component>
  </webservice-description>
</webservices>


Then add a weblogic-webservices.xml file:

<?xml version = '1.0' encoding = 'UTF-8'?>
<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"
  xmlns="http://www.bea.com/ns/weblogic/weblogic-webservices">
  <webservice-description>
    <webservice-description-name>
      SomeService
    </webservice-description-name>
    <webservice-type>JAXWS</webservice-type>
    <port-component>
      <port-component-name>SomeServicePort</port-component-name>
      <service-endpoint-address>
        <webservice-contextpath>/SomeService</webservice-contextpath>
        <webservice-serviceuri>/SomeOperation</webservice-serviceuri>
      </service-endpoint-address>
      <wsdl>
        <exposed>true</exposed>
      </wsdl>
    </port-component>
  </webservice-description>
</weblogic-webservices>


This will bind the web service to the address http://server:port/SomeService/SomeOperation.

Advertisements
Categories: Java, SOA Suite
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: