3 Developing JAX-WS Web Services
This chapter includes the following topics:
-
Developing WebLogic Web Services Starting From Java: Main Steps
-
Developing WebLogic Web Services Starting From a WSDL File: Main Steps
-
Updating the Stubbed-out JWS Implementation Class File Generated By wsdlc
-
Configuring the Server Address Specified in the Dynamic WSDL
-
Integrating Web Services Into the WebLogic Split Development Directory Environment
Overview of the WebLogic Web Service Programming Model
The WebLogic web services programming model centers around JWS files—Java files that use JWS annotations to specify the shape and behavior of the web service—and Ant tasks that execute on the JWS file. JWS annotations are based on the metadata feature, introduced in Version 5.0 of the JDK (specified by JSR-175 at http://www.jcp.org/en/jsr/detail?id=175
) and include standard annotations defined by Web Services Metadata for the Java Platform specification (JSR-181), described at http://www.jcp.org/en/jsr/detail?id=181
, the JAX-WS specification (JSR-224), described at http://jax-ws.java.net
, as well as additional ones. For a complete list of JWS annotations that are supported, see Web Service Annotation Support in WebLogic Web Services Reference for Oracle WebLogic Server. For additional detailed information about this programming model, see The Programming Model—Metadata Annotations.
Web services can be created using two development methods: bottom-up or top-down. Bottom-up development refers to the process of developing a web service from the underlying Java implementation using SOAP. Top-development describes the development of a web service from the WSDL source.
The following sections describe the high-level steps for iteratively developing a web service, either starting from Java (bottom-up) or starting from an existing WSDL file (top-down):
-
Developing WebLogic Web Services Starting From Java: Main Steps
-
Developing WebLogic Web Services Starting From a WSDL File: Main Steps
Iterative development refers to setting up your development environment in such a way so that you can repeatedly code, compile, package, deploy, and test a web service until it works as you want. The WebLogic web service programming model uses Ant tasks to perform most of the steps of the iterative development process. Typically, you create a single build.xml
file that contains targets for all the steps, then repeatedly run the targets, after you have updated your JWS file with new Java code, to test that the updates work as you expect.
In addition to the command-line tools described in this section, you can use an IDE, such as Oracle JDeveloper or Oracle Enterprise Pack for Eclipse (OEPE), to develop web services. For more information, see Using Oracle IDEs to Build Web Services in Understanding WebLogic Web Services for Oracle WebLogic Server.
Configuring Your Domain For Advanced Web Services Features
When creating or extending a domain, you can apply the WebLogic Advanced Web Services for JAX-WS Extension template (oracle.wls-webservice-jaxws-template.jar) to configure automatically the resources required to support the following advanced web service features:
-
Asynchronous messaging, as described in Developing Asynchronous Clients.
-
Web services reliable messaging, as described in Using Web Services Reliable Messaging.
-
Message buffering, as described in Configuring Message Buffering for Web Services.
-
Security using WS-SecureConversation, as described in Configuring Message-level Security in Securing WebLogic Web Services for Oracle WebLogic Server.
Note:
To configure your domain for SOAP over JMS transport, see Configuring the WebLogic Server Domain for JMS Transport.
Use of the WebLogic Advanced Web Services for JAX-WS Extension template is only required when you need to ensure recoverability of advanced web services. The extension template configures the following resources that support recoverability by enabling WebLogic Server to retain critical state information in the event of a server failure:
-
JMS queues for storing reliable messaging requests.
-
Default web service persistence configuration that provides a built-in, high-performance storage solution for web services.
The benefits of using the WebLogic Advanced Web Services for JAX-WS Extension template include:
-
Web services and clients, by default, use the reliable and high performance WebLogic storage solution.
-
Web services that use reliable messaging can buffer incoming asynchronous requests to increase fault tolerance and better absorb load. (This feature is enabled by default.)
-
Messages between web services and clients can be configured such that they are fault-tolerant and recoverable in the event of a client failure, service failure, or both.
If you do not use the WebLogic Advanced Web Services for JAX-WS Extension template, you can still develop using the advanced features, but with a reduced quality of service, as describe below:
-
By default, the state of an advanced web service is stored in memory; in the event of server failure, the data will be lost.
-
Web services will not buffer incoming asynchronous requests when using reliable messaging.
-
Web services and clients will not be recoverable in the event of a failure; any in-flight requests between them will be lost.
For more information, see Resources Required by Advanced Web Service Features.
Note:
If you do not apply the WebLogic Advanced Web Services for JAX-WS Extension template to support recoverability:
-
You must ensure that buffering is disabled for web services reliable messaging on the destination server. For more information, see Configuring a Non-buffered Destination for a Web Service.
-
Quality of service features that you have configured for your web service may not be in effect. In this case, a message will be logged to the sever log to indicate the feature has been disabled.
Although use of this extension template is not required, it makes the configuration of the required resources much easier. Alternatively, you can manually configure the resources required for these advanced features using the Oracle WebLogic Server Administration Console or WLST.
The following procedures describe how to configure a domain automatically for the advanced web services features. For more detailed instructions about using the Configuration Wizard to create and update WebLogic Server domains, see Creating a WebLogic Domain in Creating WebLogic Domains Using the Configuration Wizard.
Resources Required by Advanced Web Service Features
Table 3-1 lists the resources that are defined automatically when using the WebLogic Advanced Web Services for JAX-WS Extension template.
If you do not apply the extension template, you need to configure the resources manually using the Oracle WebLogic Server Administration Console or WLST. Be sure to configure JMS targeting according to best practices defined in Best Practices for JMS Beginners and Advanced Users in Administering JMS Resources for Oracle WebLogic Server. Specifically:
-
Configure a JMS server, Store-and-forward (SAF) service agent, and persistent store on each WebLogic Server. In a cluster, target each to a local migratable target (not the server). The host server's "default migratable target" is sufficient in most cases.
-
Target JMS modules to a cluster (or single server if not using a clustered environment).
-
Create exactly one subdeployment per module, and populate the subdeployment with the applicable JMS servers or SAF agents only, not the servers.
-
Target JMS destinations to the subdeployment (referred to as Advanced Targeting in the WebLogic Server Administration Console). JMS destinations must never use the default targeting option.
The following variables are used in the table:
-
server_designator specifies an ID that is generated automatically by the configuration framework. Typically, this ID is of the format
auto_
number
. -
uniqueID specifies unique numeric ID that is generated automatically by the configuration framework. Typically, this ID is a numeric value, such as
1234
. -
server_name specifies the user-specified name of the server.
Note:
At runtime, you should not change the name of resources; otherwise, you may experience runtime errors or data loss.
Table 3-1 Resources Required by Advanced Web Services Features
Resource Name | Resource Type | Description |
---|---|---|
|
JMS Module |
Defines a JMS module that defines the JMS resources needed for advanced web services. All associated targets (JMS servers targeted to a server) on this JMS module will be used to support JAX-WS web services. All servers to which this module is targeted must have the proper web services resources configured. Oracle recommends that you target this module to all servers in the domain. Note: You must configure the JMS module as a Uniform Distributed Destination (UDD). Any queues that are used by web services on JAX-WS must be Uniform Distributed Queues. Otherwise, an exception is thrown. To configure distributed destinations manually and for more information, see Using Distributed Destination in Developing JMS Applications for Oracle WebLogic Server. |
|
File store |
Specifies the file store, or physical store, used by the WebLogic Server to handle the I/O operations to save and retrieve data from the physical storage (such as file, DBMS, and so on). A separate file store is configured on each Managed Server targeted by the Note: Oracle recommends targeting the file store to a migratable target. To configure the file stores manually, see Using Custom File Stores in Administering the WebLogic Persistent Store. |
|
JMS server |
Specifies the JMS server management container. A separate JMS Server is configured on each Managed Server targeted by When configuring the JMS server, Oracle recommends the following:
To configure the JMS server manually, see JMS Configuration in Administering JMS Resources for Oracle WebLogic Server. |
|
JMS subdeployment |
Specifies the JMS subdeployment targeting the JMS servers defined on all Managed Servers in the cluster. To configure the JMS subdeployment manually, see Configure subdeployments in JMS system modules in Oracle WebLogic Server Administration Console Online Help. |
|
Work Manager |
Enables an application to execute multiple work items concurrently within a container. One Work Manager is generated for the domain and targeted to all servers to which the Note: You should not change the name of the Work Manager resource. To configure Work Managers manually, see Description of the Work Manager API in Developing CommonJ Applications for Oracle WebLogic Server. |
|
SAF service agent |
Provides highly available JMS message production. A separate SAF agent is configured on each Managed Server, as specified by In a single server domain, the SAF agent is named When configuring the SAF agent, Oracle recommends that you set realistic quotas on each JMS server. For more information, see Tuning WebLogic JMS in Tuning Performance of Oracle WebLogic Server. To configure SAF service agents, see Understanding the Store-and-Forward Service in Administering the Store-and-Forward Service for Oracle WebLogic Server. |
|
JMS queue |
Specifies the queue used for buffered requests. A separate queue is configured on each Managed Server, as specified by In a single server domain, the queue is named To configure the queues manually, see Configure queues in Oracle WebLogic Server Administration Console Online Help. |
|
JMS queue |
Specifies the error queue used for In a single server domain, the queue is named To configure the queues manually, see Configure queues in Oracle WebLogic Server Administration Console Online Help. |
|
JMS queue |
Specifies the queue used for buffered responses. A separate queue is configured on each Managed Server, as specified by In a single server domain, the queue is named To configure the queues manually, see Configure queues in Oracle WebLogic Server Administration Console Online Help. |
|
JMS queue |
Specifies the error queue used for In a single server domain, the queue is named To configure the queues manually, see Configure queues in Oracle WebLogic Server Administration Console Online Help. |
|
Logical store |
Defines the logical store. A separate logical store is configured on each Managed Server targeted by To configure the logical store manually, see Configuring the Logical Store. |
Configuring a Domain for Advanced Web Service Features Using the Configuration Wizard
The following sections describe how to configure a domain for advanced web service features.
Creating a Domain With the Web Services Extension Template
To create a domain that is automatically configured for the advanced web service features:
-
Start the Configuration Wizard.
-
In the Welcome window, select Create a new WebLogic domain.
-
Click Next.
-
Select Generate a domain configured automatically to support the following products and select WebLogic Advanced Web Services for JAX-WS Extension.
-
Click Next.
-
Enter the name and location of the domain and click Next.
-
Configure the administrator user name and password and click Next.
-
Configure the server start mode and JDK and click Next.
-
To configure additional servers and clusters:
-
On the Select Optional Configuration screen, at a minimum select Managed Servers, Clusters, and Machines to define the Managed Servers and clusters. Select any other items, as desired, and click Next.
-
Configure the Managed Servers in your environment and click Next.
-
Configure the clusters in your environment and click Next.
-
Assign the managed servers to the clusters on the Assign to Clusters screen and click Next.
-
Configure the machines in your environment and click Next.
-
Target the services defined in the environment to clusters or servers on the Target Services to Clusters or Servers screen and click Next.
Note: Target the
WseeJaxwsJmsModule
JMS module andweblogic.wsee.jaxws.mdb.DispatchPolicy
Work Manager to all servers in the cluster.Servers targeted on this screen will be fully configured for use with advanced web services.
-
Configure additional information on additional configuration screens (if selected in step 9a) and click Next.
-
-
When you reach the Configuration Summary screen, verify the domain details and click Create.
Extending a Domain With the Web Services Extension Template
To extend an existing domain so that it is automatically configured for these Web Services features:
-
Start the Configuration Wizard.
-
In the Welcome window, select Extend an Existing WebLogic Domain.
-
Click Next.
-
Select the domain to which you want to apply the extension template.
-
Click Next.
-
Select Extend my domain automatically to support the following added products and select WebLogic Advanced Web Services for JAX-WS Extension.
-
Click Next.
-
To configure additional servers and clusters:
-
On the Select Optional Configuration screen, at a minimum select Managed Servers, Clusters, and Machines to define the Managed Servers and clusters. Select any other items, as desired, and click Next.
-
Configure the Managed Servers in your environment and click Next.
-
Configure the clusters in your environment and click Next.
-
Assign the managed servers to the clusters on the Assign to Clusters screen and click Next.
-
Configure the machines in your environment and click Next.
-
Target the services defined in the environment to clusters or servers on the Target Services to Clusters or Servers screen and click Next.
Note: Target the
WseeJaxwsJmsModule
JMS module andweblogic.wsee.jaxws.mdb.DispatchPolicy
Work Manager to all servers in the cluster.Servers targeted on this screen will be fully configured for use with advanced web services.
-
Configure additional information on additional configuration screens (if selected in step 9a) and click Next.
-
-
Verify that you are extending the correct domain, then click Extend.
-
Click Done to exit.
Using WLST to Extend a Domain With the Web Services Extension Template
The following provides an example of how to use WLST to extend a domain using the web services extension template. Specifically, this example demonstrates how to extend a single server domain. It is assumed that you have already created a single server domain. You can add additional servers and clusters to the domain in the location noted in the example script below.
After updating the script and executing it against your domain, all resources will be configured for advanced web service features.
Review the comments provided in the sample for more information. For more information about the WLST commands described, see Understanding the WebLogic Scripting Tool.
Example 3-1 WLST Script to Extend a Domain With the Web Services Extension Template
# Read the domain. readDomain(single_server_domain_dir) # Apply the template to the domain to configure the servers for advanced web service features. installDir = install_directory/wlserver_10.3 templateLocation = install_directory + '/oracle_common/common/templates/wls/oracle.wls-webservice-jaxws-template.jar' addTemplate(templateLocation) # Save and close the domain updateDomain() closeDomain() # Read the domain readDomain(domain_dir) # Optionally create any servers and clusters required in your domain environment. # <Include create calls here . . . > # For example: create('server1','Server') or create('cluster1','Cluster') # Optionally configure the JMS module as a Uniform Distributed Destination (Recommended) setDistDestType('WseeJaxwsJmsModule', 'UDD') # Target WseeJaxwsJmsModule to the desired servers and clusters. assign('JMSSystemResource', 'WseeJaxwsJmsModule', 'Target', server_or_cluster) # Repeat assign call for other servers and clusters in the environment. # Unassign the resource from the Administration Server. unassign('JMSSystemResource', 'WseeJaxwsJmsModule', 'Target', Administration_Server) sys.path.append(domain_dir) applyJAXWS(globals()) # Save and close the domain updateDomain() closeDomain()
Updating Resources Added After Extending Your Domain
Once you have created or extended a domain using the WebLogic Advanced Web Services for JAX-WS Extension template, if you then modify the resources in your domain, you can update the configuration of those resources quickly and easily using the following WLST script.
After updating the script and executing it against your domain, all resources will be configured for advanced web service features.
Review the comments provided in the sample for more information. For more information about the WLST commands described, see Using the WebLogic Scripting Tool in Understanding the WebLogic Scripting Tool.
Example 3-2 WLST Script for Updating Resources Added After Extending Your Domain
# Read the domain. readDomain(domain_dir) # Optionally configure the JMS module as a Uniform Distributed Destination (Recommended) setDistDestType('WseeJaxwsJmsModule', 'UDD') # Target WseeJaxwsJmsModule to the desired servers and clusters. assign('JMSSystemResource', 'WseeJaxwsJmsModule', 'Target', server_or_cluster_name) # Repeat assign call for other servers and clusters in the environment. # Unassign the resource from the Administration Server. unassign('JMSSystemResource', 'WseeJaxwsJmsModule', 'Target', Administration_Server_name) sys.path.append(domain_dir) applyJAXWS(globals()) # Save and close the domain. updateDomain()
Developing WebLogic Web Services Starting From Java: Main Steps
This section describes the general procedure for developing WebLogic web services starting from Java—in effect, coding the JWS file from scratch and later generating the WSDL file that describes the service. See Examples of Developing JAX-WS Web Services for specific examples of this process.
The following procedure is just a recommendation; if you have set up your own development environment, you can use this procedure as a guide for updating your existing environment to develop WebLogic web services.
Note:
This procedure does not use the WebLogic web services split development directory environment. If you are using this development environment, and would like to integrate web services development into it, see Integrating Web Services Into the WebLogic Split Development Directory Environment for details.
Table 3-2 Steps to Develop Web Services Starting From Java
# | Step | Description |
---|---|---|
1 |
Set up the environment. |
Open a command window and execute the |
2 |
Create a project directory. |
The project directory will contain the JWS file, Java source for any user-defined data types, and the Ant |
3 |
Create the JWS file that implements the web service. |
|
4 |
Create user-defined data types. (Optional) |
If your web service uses user-defined data types, create the JavaBeans that describes them. See Programming the User-Defined Java Data Type. |
5 |
Create a basic Ant build file, |
|
6 |
Run the |
The |
7 |
Deploy the web service to WebLogic Server. |
|
8 |
Browse to the WSDL of the web service. |
Browse to the WSDL of the web service to ensure that it was deployed correctly. See Browsing to the WSDL of the Web Service. |
9 |
Test the web service. |
|
10 |
Edit the web service. (Optional) |
To make changes to the web service, update the JWS file, undeploy the web service as described in Deploying and Undeploying WebLogic Web Services, then repeat the steps starting from running the |
See Developing Web Service Clients for information on writing client applications that invoke a web service.
Developing WebLogic Web Services Starting From a WSDL File: Main Steps
This section describes the general procedure for developing WebLogic web services based on an existing WSDL file. See Examples of Developing JAX-WS Web Services, for a specific example of this process.
The procedure is just a recommendation; if you have set up your own development environment, you can use this procedure as a guide for updating your existing environment to develop WebLogic web services.
It is assumed in this procedure that you already have an existing WSDL file.
Note:
This procedure does not use the WebLogic web services split development directory environment. If you are using this development environment, and would like to integrate web services development into it, see Integrating Web Services Into the WebLogic Split Development Directory Environment for details.
Table 3-3 Steps to Develop Web Services Starting From Java
# | Step | Description |
---|---|---|
1 |
Set up the environment. |
Open a command window and execute the |
2 |
Create a project directory. |
The project directory will contain the generated artifacts and the Ant |
3 |
Create a basic Ant build file, |
|
4 |
Put your WSDL file in a directory that the |
For example, you can put the WSDL file in a |
5 |
Run the |
The |
6 |
Update the stubbed-out JWS file generated by the |
The |
7 |
Run the |
Specify the artifacts generated by the |
8 |
Deploy the web service to WebLogic Server. |
|
9 |
Browse to the WSDL of the web service. |
Browse to the WSDL of the web service to ensure that it was deployed correctly. See Browsing to the WSDL of the Web Service. |
10 |
Test the web service. |
|
11 |
Edit the web service. (Optional) |
To make changes to the web service, update the JWS file, undeploy the web service as described in Deploying and Undeploying WebLogic Web Services, then repeat the steps starting from running the |
See Developing Web Service Clients for information on writing client applications that invoke a web service.
Creating the Basic Ant build.xml File
Ant uses build files written in XML (default name build.xml
) that contain a <project>
root element and one or more targets that specify different stages in the web services development process. Each target contains one or more tasks, or pieces of code that can be executed. This section describes how to create a basic Ant build file; later sections describe how to add targets to the build file that specify how to execute various stages of the web services development process, such as running the jwsc
Ant task to process a JWS file and deploying the web service to WebLogic Server.
The following skeleton build.xml
file specifies a default all
target that calls all other targets that will be added in later sections:
<project default="all"> <target name="all" depends="clean,build-service,deploy" /> <target name="clean"> <delete dir="output" /> </target> <target name="build-service"> <!--add jwsc and related tasks here --> </target> <target name="deploy"> <!--add wldeploy task here --> </dftarget> </project>
For detailed information about how to integrate and use Ant tasks in your development environment to program a web service and a client application that invokes the web service, see:
-
Using Oracle WebLogic Server Ant Tasks in Understanding WebLogic Web Services for Oracle WebLogic Server
-
Ant Task Reference in WebLogic Web Services Reference for Oracle WebLogic Server
-
The following sections in Developing Applications for Oracle WebLogic Server:
Running the jwsc WebLogic Web Services Ant Task
The jwsc
Ant task takes as input a JWS file that contains JWS annotations and generates all the artifacts you need to create a WebLogic web service. The JWS file can be either one you coded yourself from scratch or one generated by the wsdlc
Ant task.
The jwsc
-generated artifacts include:
-
JSR-109 web service class file.
-
JAXB data binding artifact class file.
-
All required deployment descriptors, including:
-
Servlet-based web service deployment descriptor file:
web.xml
. -
Ear deployment descriptor files:
application.xml
andweblogic-application.xml
.
Note:
The WSDL file is generated when the service endpoint is deployed.
-
If you are running the jwsc
Ant task against a JWS file generated by the wsdlc
Ant task, the jwsc
task does not generate these artifacts, because the wsdlc
Ant task already generated them for you and packaged them into a JAR file. In this case, you use an attribute of the jwsc
Ant task to specify this wsdlc
-generated JAR file.
After generating all the required artifacts, the jwsc
Ant task compiles the Java files (including your JWS file), packages the compiled classes and generated artifacts into a deployable JAR archive file, and finally creates an exploded Enterprise Application directory that contains the JAR file.
The jwsc
Ant task includes attributes and child elements that enable you to:
-
Process multiple JWS files at once. You can choose to package each resulting web service into its own Web application WAR file, or group all of the web services into a single WAR file.
-
Specify the transports (HTTP/HTTPS or JMS transport) that client applications can use when invoking the web service, as described Specifying the Transport Used to Invoke the Web Service.
-
Update an existing Enterprise Application or Web application, rather than generate a completely new one.
To run the jwsc
Ant task, add the following taskdef
and build-service
target to the build.xml
file:
<taskdef name="jwsc" classname="weblogic.wsee.tools.anttasks.JwscTask" /> <target name="build-service"> <jwsc srcdir="src_directory" destdir="ear_directory" > <jws file="JWS_file" compiledWsdl="WSDLC_Generated_JAR" type="WebService_type"/> </jwsc> </target>
where:
-
ear_directory
-
src_directory
refers to the top-level directory that contains subdirectories that correspond to the package name of your JWS file. -
JWS_file
refers to the full pathname of your JWS file, relative to the value of thesrc_directory
attribute. -
WSDLC_Generated_JAR
refers to the JAR file generated by thewsdlc
Ant task that contains the JWS SEI and data binding artifacts that correspond to an existing WSDL file.Note:
You specify this attribute only in the "starting from WSDL" use case; this procedure is described in Developing WebLogic Web Services Starting From a WSDL File: Main Steps.
-
WebService_type
specifies the type of web service. This value can be set to JAXWS or JAXRPC.
The required taskdef
element specifies the full class name of the jwsc
Ant task.
Only the srcdir
and destdir
attributes of the jwsc
Ant task are required. This means that, by default, it is assumed that Java files referenced by the JWS file (such as JavaBeans input parameters or user-defined exceptions) are in the same package as the JWS file. If this is not the case, use the sourcepath
attribute to specify the top-level directory of these other Java files.
See jwsc in the WebLogic Web Services Reference for Oracle WebLogic Server for complete documentation and examples about the jwsc
Ant task.
Specifying the Transport Used to Invoke the Web Service
The <jws>
child element of jwsc
includes the following optional child elements for specifying the transports (HTTP/S or JMS) that are used to invoke the web service:
-
WLHttpTransport
—Specifies the context path and service URI sections of the URL used to invoke the web service over the HTTP/S transport, as well as the name of the port in the generated WSDL. For more information, see WLHttpTransport in WebLogic Web Services Reference for Oracle WebLogic Server. -
JmsTransportService
—Enables and configures SOAP over JMS transport. Optionally, you can configure the destination name, destination type, delivery mode, request and response queues, and other JMS transport properties. For more information, see Developing JAX-WS Web Services.
The following guidelines describe the usage of the transport elements for the jwsc
Ant task:
-
The transports you specify to
jwsc
always override any corresponding transport annotations in the JWS file. In addition, all attributes of the transport annotation are ignored, even if you have not explicitly specified the corresponding attribute for the transport element, in which case the default value of the transport element attribute is used. -
You can specify both transport elements for a particular JWS file. However, you can specify only one instance of a particular transport element. For example, although you cannot specify two different
<WLHttpTransport>
elements for a given JWS file, you can specify one<WLHttpTransport>
and one<WLJmsTransport>
element. -
The value of the
serviceURI
attribute can be the same when you specify both<WLJMSTransport>
and<WLHttpTransport>
. -
All transports associated with a particular JWS file must specify the same
contextPath
attribute value. -
If you specify more than one transport element for a particular JWS file, the value of the
portName
attribute for each element must be unique among all elements. This means that you must explicitly specify this attribute if you add more than one transport child element to<jws>
, because the default value of the element will always be the same and thus cause an error when running thejwsc
Ant task. -
If you do not specify any transport as either one of the transport elements to the
jwsc
Ant task or a transport annotation in the JWS file, then the web service's default URL corresponds to the default value of theWLHttpTransport
element.
Defining the Context Path of a WebLogic Web Service
There are a variety of places where the context path (also called context root) of a WebLogic web service can be specified. This section describes how to determine which is the true context path of the service based on its configuration, even if it is has been set in multiple places.
In the context of this discussion, a web service context path is the string that comes after the host:port
portion of the web service URL. For example, if the deployed WSDL of a WebLogic web service is as follows:
http://hostname:7001/financial/GetQuote?WSDL
The context path for this web service is financial
.
The following list describes the order of precedence, from most to least important, of all possible context path specifications:
- The
contextPath
attribute of the<module>
element and<jws>
element (when used as a direct child of thejwsc
Ant task.) - The
contextPath
attribute of the<WLHttpTransport>
child elements of<jws>
. - The default value of the context path, which is the name of the JWS file without any extension.
Assume that you update the build.xml
file and add a <WLHttpTransport>
child element to the <jws>
element that specifies the JWS file and set its contextPath
attribute to finance
. The context path of the web service would now be finance
. If, however, you then group the <jws>
element (including its child <WLHttpTransport>
element) under a <module>
element, and set its contextPath
attribute to money
, then the context path of the web service would now be money
.
If you do not specify any contextPath
attribute in either the JWS file or the jwsc
Ant task, then the context path of the web service is the default value: the name of the JWS file without its *.java
extension.
If you group two or more <jws>
elements under a <module>
element and do not set the context path using any of the other options listed above, then you must specify the contextPath
attribute of <module>
to specify the common context path used by all the web services in the module. Otherwise, the default context paths for all the web services in the module are going to be different (due to different names of the implementing JWS files), which is not allowed in a single WAR file.
Examples of Using jwsc
The following build.xml
excerpt shows a basic example of running the jwsc
Ant task on a JWS file:
<taskdef name="jwsc" classname="weblogic.wsee.tools.anttasks.JwscTask" /> <target name="build-service"> <jwsc srcdir="src" destdir="output/helloWorldEar"> <jws file="examples/webservices/hello_world/HelloWorldImpl.java" type="JAXWS"/> </jwsc> </target>
In the example:
-
The Enterprise application will be generated, in exploded form, in
output/helloWorldEar
, relative to the current directory. -
The JWS file is called
HelloWorldImpl.java
, and is located in thesrc/examples/webservices/hello_world
directory, relative to the current directory. This implies that the JWS file is in the packageexamples.webservices.helloWorld
. -
A JAX-WS web service is generated.
The following example is similar to the preceding one, except that it uses the compiledWsdl
attribute to specify the JAR file that contains wsdlc
-generated artifacts (for the "starting with WSDL" use case):
<taskdef name="jwsc" classname="weblogic.wsee.tools.anttasks.JwscTask" /> <target name="build-service"> <jwsc srcdir="src" destdir="output/wsdlcEar"> <jws file="examples/webservices/wsdlc/TemperaturePortTypeImpl.java" compiledWsdl="output/compiledWsdl/TemperatureService_wsdl.jar" type="JAXWS"/> </jwsc> </target>
In the preceding example, the TemperaturePortTypeImpl.java
file is the stubbed-out JWS file that you updated to include your business logic. Because the compiledWsdl
attribute is specified and points to a JAR file, the jwsc
Ant task does not regenerate the artifacts that are included in the JAR.
To actually run this task, type at the command line the following:
prompt> ant build-service
Running the wsdlc WebLogic Web Services Ant Task
The wsdlc
Ant task takes as input a WSDL file and generates artifacts that together partially implement a WebLogic web service. These artifacts include:
-
JWS service endpoint interface (SEI) that implements the web service described by the WSDL file.
-
JWS implementation file that contains a partial (stubbed-out) implementation of the generated JWS SEI. This file must be customized by the developer.
-
JAXB data binding artifacts.
-
Optional Javadocs for the generated JWS SEI.
The wsdlc
Ant task packages the JWS SEI and data binding artifacts together into a JAR file that you later specify to the jwsc
Ant task. You never need to update this JAR file; the only file you update is the JWS implementation class.
To run the wsdlc
Ant task, add the following taskdef
and generate-from-wsdl
targets to the build.xml
file:
<taskdef name="wsdlc" classname="weblogic.wsee.tools.anttasks.WsdlcTask"/> <target name="generate-from-wsdl"> <wsdlc srcWsdl="WSDLFile" destJwsDir="JWS_interface_directory" destImplDir="JWS_implementation_directory" packageName="Package_name" type="WebService_type"/> </target>
where:
-
WSDLFile
refers to the name of the WSDL file from which you want to generate a partial implementation, including its absolute or relative pathname. -
JWS_interface_directory
refers to the directory into which the JAR file that contains the JWS SEI and data binding artifacts should be generated.The name of the generated JAR file is
WSDLFile
_wsdl.jar
, whereWSDLFile
refers to the root name of the WSDL file. For example, if the name of the WSDL file you specify to the file attribute isMyService.wsdl
, then the generated JAR file isMyService_wsdl.jar
. -
JWS_implementation_directory
refers to the top directory into which the stubbed-out JWS implementation file is generated. The file is generated into a subdirectory hierarchy corresponding to its package name.The name of the generated JWS file is
Service_PortType
Impl.java
, whereService
andPortType
refer to thename
attribute of the<service>
element and its inner<port>
element, respectively, in the WSDL file for which you are generating a web service. For example, if the service name isMyService
and the port name isMyServicePortType
, then the JWS implementation file is calledMyService_MyServicePortTypeImpl.java
. -
Package_name
refers to the package into which the generated JWS SEI and implementation files should be generated. If you do not specify this attribute, thewsdlc
Ant task generates a package name based on thetargetNamespace
of the WSDL. -
WebService_type
specifies the type of web service. This value can be set to JAXWS or JAXRPC.
The required taskdef
element specifies the full class name of the wsdlc
Ant task.
Only the srcWsdl
and destJwsDir
attributes of the wsdlc
Ant task are required. Typically, however, you generate the stubbed-out JWS file to make your programming easier. Oracle recommends you explicitly specify the package name in case the targetNamespace
of the WSDL file is not suitable to be converted into a readable package name.
The following build.xml
excerpt shows an example of running the wsdlc
Ant task against a WSDL file:
<taskdef name="wsdlc" classname="weblogic.wsee.tools.anttasks.WsdlcTask"/> <target name="generate-from-wsdl"> <wsdlc srcWsdl="wsdl_files/TemperatureService.wsdl" destJwsDir="output/compiledWsdl" destImplDir="impl_output" packageName="examples.webservices.wsdlc" type="JAXWS" /> </target>
In the example:
-
The existing WSDL file is called
TemperatureService.wsdl
and is located in thewsdl_files
subdirectory of the directory that contains thebuild.xml
file. -
The JAR file that will contain the JWS SEI and data binding artifacts is generated to the
output/compiledWsdl
directory; the name of the JAR file isTemperatureService_wsdl.jar
. -
The package name of the generated JWS files is
examples.webservices.wsdld
. -
The stubbed-out JWS file is generated into the
impl_output/examples/webservices/wsdlc
directory relative to the current directory. -
Assuming that the service and port type names in the WSDL file are
TemperatureService
andTemperaturePortType
, then the name of the JWS implementation file isTemperatureService_TemperaturePortTypeImpl.java
. -
A JAX-WS web service is generated.
To actually run this task, type the following at the command line:
prompt> ant generate-from-wsdl
For more information, see wsdlc in WebLogic Web Services Reference for Oracle WebLogic Server.
Updating the Stubbed-out JWS Implementation Class File Generated By wsdlc
The wsdlc
Ant task generates the stubbed-out JWS implementation file into the directory specified by its destImplDir
attribute; the name of the file is Service_PortType
Impl.java
, where Service
is the name of the service and PortType
is the name of the port type in the original WSDL. The class file includes everything you need to compile it into a web service, except for your own business logic.
The JWS class implements the JWS web service endpoint interface that corresponds to the WSDL file; the JWS SEI is also generated by wsdlc
and is located in the JAR file that contains other artifacts, such as the Java representations of XML Schema data types in the WSDL and so on. The public methods of the JWS class correspond to the operations in the WSDL file.
The wsdlc
Ant task automatically includes the @WebService
annotation in the JWS implementation class; the value corresponds to the equivalent value in the WSDL. For example, the serviceName
attribute of @WebService
is the same as the name
attribute of the <service>
element in the WSDL file.
When you update the JWS file, you add Java code to the methods so that the corresponding web service operations operate as required. Typically, the generated JWS file contains comments where you should add code, such as:
//replace with your impl here
In addition, you can add additional JWS annotations to the file, with the following restrictions:
-
You can include the following annotations from the standard (JSR-181)
javax.jws
package in the JWS implementation file:@WebService
,@HandlerChain
,@SOAPMessageHandler
, and@SOAPMessageHandlers
. If you specify any other JWS annotation from thejavax.jws
package, thejwsc
Ant task returns error when you try to compile the JWS file into a web service. For example, if you specify the@Policy
annotation in a your JWS implementation file, thejwsc
Ant task throws a compilation error. -
You can specify only the
serviceName
,endpointInterface
, andtargetNamespace
attributes of the@WebService
annotation. Use theserviceName
attribute to specify a different<service>
WSDL element from the one that thewsdlc
Ant task used, in the rare case that the WSDL file contains more than one<service>
element. Use theendpointInterface
attribute to specify the JWS SEI generated by thewsdlc
Ant task. Use thetargetNamespace
attribute to specify the namespace of a WSDL service, which can be different from the on in JWS SEI. -
You can specify JAX-WS—JSR 224, JAXB (JSR 222)—or Common (JSR 250) annotations, as required. For more information about the annotations that are supported, see JWS Annotation Reference in WebLogic Web Services Reference for Oracle WebLogic Server.
After you have updated the JWS file, Oracle recommends that you move it to an official source location, rather than leaving it in the wsdlc
output directory.
The following example shows the wsdlc
-generated JWS implementation file from the WSDL shown in Sample WSDL File; the text in bold indicates where you would add Java code to implement the single operation (getTemp
) of the web service:
package examples.webservices.wsdlc; import javax.jws.WebService; /** * TemperaturePortTypeImpl class implements web service endpoint interface * TemperaturePortType */ @WebService( serviceName="TemperatureService", endpointInterface="examples.webservices.wsdlc.TemperaturePortType") public class TemperaturePortTypeImpl implements TemperaturePortType { public TemperaturePortTypeImpl() { } public float getTemp(java.lang.String zipcode) {//replace with your impl here
return 0;
} }
Deploying and Undeploying WebLogic Web Services
Because web services are packaged as Enterprise Applications, deploying a web service simply means deploying the corresponding EAR file or exploded directory.
There are a variety of ways to deploy WebLogic applications, from using the WebLogic Server Administration Console to using the weblogic.Deployer
Java utility. There are also various issues you must consider when deploying an application to a production environment as opposed to a development environment. For a complete discussion about deployment, see Deploying Applications to Oracle WebLogic Server.
This guide, because of its development nature, discusses just two ways of deploying web services:
Using the wldeploy Ant Task to Deploy Web Services
The easiest way to deploy a web service as part of the iterative development process is to add a target that executes the wldeploy
WebLogic Ant task to the same build.xml
file that contains the jwsc
Ant task. You can add tasks to both deploy and undeploy the web service so that as you add more Java code and regenerate the service, you can redeploy and test it iteratively.
To use the wldeploy
Ant task, add the following target to your build.xml
file:
<target name="deploy"> <wldeploy action="deploy" name="DeploymentName" source="Source" user="AdminUser" password="AdminPassword" adminurl="AdminServerURL" targets="ServerName"/> </target>
where:
-
DeploymentName refers to the deployment name of the Enterprise Application, or the name that appears in the WebLogic Server Administration Console under the list of deployments.
-
Source refers to the name of the Enterprise Application EAR file or exploded directory that is being deployed. By default, the
jwsc
Ant task generates an exploded Enterprise Application directory. -
AdminUser refers to administrative username.
-
AdminPassword refers to the administrative password.
-
AdminServerURL refers to the URL of the Administration Server, typically
t3://localhost:7001
. -
ServerName refers to the name of the WebLogic Server instance to which you are deploying the web service.
For example, the following wldeploy
task specifies that the Enterprise Application exploded directory, located in the output/ComplexServiceEar
directory relative to the current directory, be deployed to the myServer
WebLogic Server instance. Its deployed name is ComplexServiceEar
.
<target name="deploy"> <wldeploy action="deploy" name="ComplexServiceEar" source="output/ComplexServiceEar" user="weblogic" password="weblogic" verbose="true" adminurl="t3://localhost:7001" targets="myserver"/> </target>
To actually deploy the web service, execute the deploy
target at the command-line:
prompt> ant deploy
You can also add a target to easily undeploy the web service so that you can make changes to its source code, then redeploy it:
<target name="undeploy"> <wldeploy action="undeploy" name="ComplexServiceEar" user="weblogic" password="weblogic" verbose="true" adminurl="t3://localhost:7001" targets="myserver"/> </target>
When undeploying a web service, you do not specify the source
attribute, but rather undeploy it by its name.
Using the Administration Console to Deploy Web Services
To use the WebLogic Server Administration Console to deploy the web service, first invoke it in your browser using the following URL:
http://[host
]:[port
]/console
where:
-
host
refers to the computer on which WebLogic Server is running. -
port
refers to the port number on which WebLogic Server is listening (default value is7001
).
Then use the deployment assistants to help you deploy the Enterprise application. See Enterprise Applications in the Oracle WebLogic Server Administration Console Online Help.
Browsing to the WSDL of the Web Service
You can display the WSDL of the web service in your browser to ensure that it has deployed correctly.
The following URL shows how to display the web service WSDL in your browser:
http://[host
]:[port
]/[contextPath]/[serviceUri]?WSDL
-
host
refers to the computer on which WebLogic Server is running (for example,localhost
). -
port
refers to the port number on which WebLogic Server is listening (default value is7001
). -
contextPath
refers to the context root of the web service. There are many places to set the context root (the<WLHttpTransport>
,<module>
, or<jws>
element ofjwsc
) and certain methods take precedence over others. See Defining the Context Path of a WebLogic Web Service. -
serviceUri
refers to the value of theserviceUri
attribute of the<WLHttpTransport>
child element of thejwsc
Ant task. If you do not specify anyserviceUri
attribute in thejwsc
Ant task, then theserviceUri
of the web service is the default value: theserviceName
element of the@WebService
annotation if specified; otherwise, the name of the JWS file, without its extension, followed byService
.
For example, assume that you specified the following <WLHttpTransport>
child element in the jwsc
task that you use to build your web service:
<target name="build-service"> <jwsc srcdir="src" destdir="${ear-dir}" keepGenerated="true"> <jws file="examples/webservices/complex/ComplexImpl.java" type="JAXWS"> <WLHttpTransport contextPath="complex" serviceUri="ComplexService" portName="ComplexServicePort"/> </jws> </jwsc> </target>
Then the URL to view the WSDL of the web service, assuming the service is running on a host called ariel
at the default port number (7001
), is:
http://ariel:7001/complex/ComplexService?WSDL
Configuring the Server Address Specified in the Dynamic WSDL
The WSDL of a deployed web service (also called dynamic WSDL) includes an <address>
element that assigns an address (URI) to a particular web service port. For example, assume that the following WSDL snippet partially describes a deployed WebLogic web service called ComplexService
:
<definitions name="ComplexServiceDefinitions" targetNamespace="http://example.org"> ... <service name="ComplexService"> <port binding="s0:ComplexServiceSoapBinding" name="ComplexServicePort"> <s1:address location="http://myhost:7101/complex/ComplexService"/> </port> </service> </definitions>
The preceding example shows that the ComplexService
web service includes a port called ComplexServicePort
, and this port has an address of http://myhost:7101/complex/ComplexService
.
WebLogic Server determines the complex/ComplexService
section of this address by examining the contextPath
and serviceURI
attributes of the jwsc
elements, as described in Browsing to the WSDL of the Web Service. However, the method WebLogic Server uses to determine the protocol and host section of the address (http://myhost:7101
, in the example) is more complicated, as described below. For clarity, this section uses the term server address to refer to the protocol and host section of the address.
The server address that WebLogic Server publishes in a dynamic WSDL of a deployed web service depends on whether the web service can be invoked using HTTP/S or JMS, whether you have configured a proxy server, whether the web service is deployed to a cluster, or whether the web service is actually a callback service.
The following sections reflect these different configuration options, and provide links to procedural information about changing the configuration to suit your needs.
It is assumed in the sections that you use the WebLogic Server Administration Console to configure cluster and standalone servers.
Web service is not a callback service and can be invoked using HTTP/S
-
If the web service is deployed to a cluster, the following values are used in the server address of the dynamic WSDL, in order of precedence:
-
Configured network channel, as described in Configuring the Identity of the Front-end SOAP Router Using Network Channels.
-
Frontend Host
,Frontend HTTP Port
, andFrontend HTTPS Port
configured for the cluster, as described in Configure HTTP Settings for a Cluster in Oracle WebLogic Server Administration Console Online Help. -
Frontend Host
,Frontend HTTP Port
, andFrontend HTTPS Port
configured for the local server, as described in Configure HTTP Protocol in Oracle WebLogic Server Administration Console Online Help. -
If none of the above items are set, the
Cluster Address
must be set for the cluster, as described in Configure Clusters in Oracle WebLogic Server Administration Console Online Help. The server channel for the specified protocol from the request URL (for example,http
) will be used to generate the cluster address that is displayed in the WSDL.
-
-
If the web service is deployed to an individual server, the
Frontend Host
,Frontend HTTP Port
, andFrontend HTTPS Port
configured for the local server are used in the server address of the dynamic WSDL, as described in Configure HTTP Protocol in Oracle WebLogic Server Administration Console Online Help.
Web service is a callback service
-
If the callback service is deployed to a cluster, the following values are used in the server address of the dynamic WSDL, in order of precedence:
-
Configured network channel, as described in Configuring the Identity of the Front-end SOAP Router Using Network Channels.
-
Frontend Host
,Frontend HTTP Port
, andFrontend HTTPS Port
configured for the cluster, as described in Configure HTTP Settings for a Cluster in Oracle WebLogic Server Administration Console Online Help. -
Frontend Host
,Frontend HTTP Port
, andFrontend HTTPS Port
configured for the local server, as described in Configure HTTP Protocol in Oracle WebLogic Server Administration Console Online Help. -
Cluster Address
for the cluster, as described in Configure Clusters in Oracle WebLogic Server Administration Console Online Help. TheCluster Address
is required if no other values are set.
-
-
If the callback service is deployed to an individual server, the
Frontend Host
,Frontend HTTP Port
, andFrontend HTTPS Port
configured for the local server are used in the server address of the dynamic WSDL, as described in Configure HTTP Protocol in Oracle WebLogic Server Administration Console Online Help. -
If none of the preceding values are set, but the
Listen Address
of the server to which the callback service is deployed is set, then WebLogic Server uses this value in the server address.See Configure Listen Addresses in Oracle WebLogic Server Administration Console Online Help.
Web service is invoked using a proxy server
Although not required, Oracle recommends that you explicitly set the Frontend Host
, FrontEnd HTTP Port
, and Frontend HTTPS Port
of either the cluster or individual server to which the web service is deployed to point to the proxy server.
See Configure HTTP Settings for a Cluster or Configure HTTP Protocol in Oracle WebLogic Server Administration Console Online Help.
Testing the Web Service
After you have deployed a WebLogic web service, you can test basic and advanced features of your web service, such as security, quality of service (QoS), HTTP headers, and so on. You can also perform stress testing of the security features. For information about testing web services using the Web Services Test Client or Fusion Middleware Control Test Web Service page, see Testing Web Services in Administering Web Services.
Integrating Web Services Into the WebLogic Split Development Directory Environment
This section describes how to integrate web services development into the WebLogic split development directory environment. It is assumed that you understand this WebLogic feature and have set up this type of environment for developing standard Java Platform, Enterprise Edition (Java EE) applications and modules, such as EJBs and Web applications, and you want to update the single build.xml
file to include web services development.
For detailed information about the WebLogic split development directory environment, see Creating a Split Development Directory Environment in Developing Applications for Oracle WebLogic Server and the splitdir/helloWorldEar
example installed with WebLogic Server, located in the ORACLE_HOME
/wlserver/samples/server/examples/src/examples
directory, where ORACLE_HOME
represents the directory in which you installed WebLogic Server. For more information about the WebLogic Server code examples, see Sample Applications and Code Examples in Understanding Oracle WebLogic Server.
Your split development directory environment is now updated to include web service development. When you rebuild and deploy the entire Enterprise Application, the web service will also be deployed as part of the EAR. You invoke the web service in the standard way described in Browsing to the WSDL of the Web Service.