JAX-WS 2.1.2 Web Service Client

Author: Jaroslav Pospisil
Version: 1.8
Estimated time: 4 hours
Last update: 5.12.2009
Introduction:

This test specification should test Web service client creation in J2SE and J2EE project. The specification covers developing of simple web service client in NetBeans 6.5 on Tomcat(specifically Installator contained Tomcat 6.0.18 and external Tomcat 5.5.30) and SJAS 9(Glassfish v2 and v3).
Comment:

This test specification is based on End - to - end scenarios, written by Lukas Jungmann.




Table of Contents






Before you start:


If you use Web & JavaEE or Full version of Netbeans 6.5 installer, you should have Glassfish v2ur2 and v3 already installed (it's default option). Otherwise you have to install Glassfish v2 manually. Tomcat 6.0.18 is optional choice in installator, so you have either to check it on first screen by Customize button, or install manually. In case of external Tomcat 5.5.30 you have to install it manually either way. You can download Glassfish v2 here and Tomcats here Finally add all servers in Runtime tab. Do the web application test cases with all three servers.

Test suite 1: Web Service Client in J2SE project

Purpose: Functionality of J2SE WS Client.
Setup: Open File|New Project|Java Web|Web Application and write WSWebApp into Project Name field. Click Finish
Create new Web Service of name MyWS. Open File|Web Services|Web Service and write MyWS into Web Service Name field and org.test into Package field.
In editor window will open Web Service Designer screen.There's button Add Operation..., click on it,left everything default and click on OK button.
Right-click on WSWebApp in Projects tab and select Undeploy and Deployfrom context menu. Web service is now deployed and available.
Create new Java Application - go to File|New Project|Java|Java Application.
Specify Hello as Project Name.
Click Finish.

#Test caseDescription
1Create web service client
1. Go to File|New File|Web services|Web Service Client|Next.
2. Specify WSDL - there are three ways how to do it and we must check all.
Click on Browse button and select MyWS.
Invoke WS Client wizard again and now select WSDL URL choice. Enter http://www.esynaps.com/WebServices/SearchWS.asmx?WSDL into textfield.
In third case download this wsdl file and use it for choice Local File.
3. Optional: if you're behind proxy check its settings via Proxy settings... button.
4. Check that Client style is set to JAX-WS.
5. Leave Generate Dispatch code unchecked.
6. Click Finish.
RESULT: In Projects tab|Hello is Web Service References node added.Open it and there should be MyWSService node.
2Refresh Client
1. Go to Projects tab|Hello|Web Service References|MyWSService.
2. Right-click on web service and then select Refresh Client
3. Left all unchanged in next window and click Yes
RESULT: WSDL of web service will be updated .
3Refresh Client and replace WSDL
1. Go to Projects tab|Hello|Web Service References|MyWSService.
2. Right-click on web service and then select Refresh Client
3. Check in next window Also replace Local WSDL Filecheckbox and click Yes
RESULT: WSDL of web service will be updated and WSDL file regenerated .
4Edit Web Service Attributes
1. Go to Projects tab|Hello|Web Service References|MyWSService.
2. Right-click on web service and then select "Edit Web Service Attributes"
RESULT: Dialog window will open with Quality of Service table selected. According to other modules installed, there could be also AM Security and WSDL Customization tabs in window. It's described elsewhere.
5Configure Handlers
1. Go to Projects tab|Hello|Web Service References|MyWSService.
2. Right-click on web service and then select "Configure Handlers..."
RESULT: Configure Handlers dialog window of web service will open.
6Call web service operation in Main class
1. Go to editor Main.java and click before // TODO code application logic here.
2. Right-click to invoke context menu and select Web Service Client Resources and Call Web Service Operation. 3. In next window select operation (click through nodes) and click OK.
RESULT: Added code:
try { // Call Web Service Operation
test.MyWSService service = new test.MyWSService();
test.MyWS port = service.getMyWSPort();
// TODO process result here
java.lang.String result = port.operation();
System.out.println("Result = "+result);
} catch (Exception ex) {
// TODO handle custom exceptions here
}
7Call web service operation in java class
1. Create new Java class testClass.java, package testPack, go to editor and add this code:
public void testmethod() {
}
2. Click behind public void testmethod() {.
2. Right-click to invoke context menu and select Web Service Client Resources and Call Web Service Operation. 3. In next window select operation (click through nodes) and click OK.
RESULT: Added code:
try { // Call Web Service Operation
test.MyWSService service = new test.MyWSService();
test.MyWS port = service.getMyWSPort();
// TODO process result here
java.lang.String result = port.operation();
System.out.println("Result = "+result);
} catch (Exception ex) {
// TODO handle custom exceptions here
}
7Test Compile on Save
1. Add space somewhere in Main.java and click on Save.
2. Then Run project.
RESULT: Web project is not only saved,but also compiled,as you can see in Output window.
8Test Disable of Compile on Save
1. Go to Properties and uncheck Compile on Save in Compile tab.
2. Add space somewhere in Main.java and click on Save.
3. Then Run project.
RESULT: Web project is only saved,compilation didn't occured,as you can see in Output window.
9Test Dispatch code
1. Delete Web Service Client in Hello and create it again with Generate Dispatch Code checked.
2. Create another java class of name javaDispatch.java and repeat all steps from previous case.
RESULT: Added code:
import javax.xml.namespace.QName;
import javax.xml.transform.Source;
import javax.xml.ws.Dispatch;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.Service;
import java.io.StringReader;
...
org.test.MyWSService service = new org.test.MyWSService();

QName portQName = new QName("http://test.org/" , "MyWSPort");
String req = "";

try { // Call Web Service Operation

Dispatch sourceDispatch = null;
sourceDispatch = service.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD);
Source result = sourceDispatch.invoke(new StreamSource(new StringReader(req)));
} catch (Exception ex) {
// TODO handle custom exceptions here
}
10Delete web service client
1. Projects tab|Hello|Web Service References|MyWSService node.
2. Right-click on web service and then select "Delete" and "Yes" in next window.
RESULT: Web service (and Web Service references node,if the service was last one) should disappear from Projects tab .
Teardown:




Test suite 2: Web Service Client in J2EE module

Purpose: Functionality of J2EE WS Client.
Setup: Open File|New Project|Java Web|Web Application and write WSWebApp into Project Name field. Click Finish
Create new Web Service of name MyWS. Open File|Web Services|Web Service and write MyWS into Web Service Name field and test into Package field.
In editor window will open Web Service Customizer screen.There's button Add Operation..., click on it,left everything default and click on OK button.
Right-click on WSWebApp in Projects tab and select Undeploy and Deployfrom context menu. Web service is now deployed and available. Create new Web Application - go to File|New Project|Java Web|Web Application.
Specify WSClientWebApp as Project Name.
Click Finish. Create new EJB Application - go to File|New Project|Java EE|EJB Module.
Specify WSClientEJB as Project Name.
Click Finish. Create new Application Client- go to File|New Project|Java EE|Application Client.
Specify WSClientAppC as Project Name.
Click Finish.
Web service client could be created in all these three J2EE modules, so test next test cases with all of them.

#Test caseDescription
1Create web service client
1. Go to File|New File|Web services|Web Service Client|Next.
2. Specify WSDL - there are three ways how to do it and we must check all.
Click on Browse button and select MyWS.
Invoke WS Client wizard again and now select WSDL URL choice. Enter http://www.esynaps.com/WebServices/SearchWS.asmx?WSDL into textfield.
In third case download this wsdl file and use it for choice Local File.
3. Optional: if you're behind proxy check its settings via Proxy settings... button.
4. Leave Generate Dispatch code unchecked.
5. Click Finish.
RESULT: In Projects tab|Hello is Web Service References node added.Open it and there should be MyWS[Service] node. Name of node will vary because of different process of resolving namespaces in different project types. In next test cases we use web application for simplicity.
2Refresh WSDL
1. Go to Projects tab|WSClientWebApp|Web Service References|MyWSService.
2. Right-click on web service and then select Refresh Client
3. Left all unchanged in next window and click Yes
RESULT: WSDL of web service will be updated .
3Refresh Client and replace WSDL
1. Go to Projects tab|WSClientWebApp|Web Service References|MyWSService.
2. Right-click on web service and then select Refresh Client
3. Check in next window Also replace Local WSDL Filecheckbox and click Yes
RESULT: WSDL of web service will be updated and WSDL file regenerated .
4Edit Web Service Attributes
1. Go to Projects tab|WSClientWebApp|Web Service References|MyWSService.
2. Right-click on web service and then select "Edit Web Service Attributes"
RESULT: Dialog window will open with Quality of Service table selected. According to other modules installed, there could be also AM Security and WSDL Customization tabs in window. It's described elsewhere.
5Configure Handlers
1. Go to Projects tab|WSClientWebApp|Web Service References|MyWSService.
2. Right-click on web service and then select "Configure Handlers..."
RESULT: Configure Handlers dialog window of web service will open.
6Call web service operation in Appclient's java class
1. Create new Java class testClass.java, package testPack in WSClientAppC, go to editor and add this code:
public void testmethod() {
}
2. Click behind public void testmethod() {.
2. Right-click to invoke context menu and select Web Service Client Resources and Call Web Service Operation. 3. In next window select operation (click through nodes) and click OK.
RESULT: Added code:
try { // Call Web Service Operation
test.MyWSService service = new test.MyWSService();
test.MyWS port = service.getMyWSPort();
// TODO process result here
java.lang.String result = port.operation();
System.out.println("Result = "+result);
} catch (Exception ex) {
// TODO handle custom exceptions here
}
7Call web service operation in servlet
1. Create new servlettestServlet.java, package org.serv in WSWebApp, go to editor and delete this code:
/* TODO output your page here
*/
2. Click behind out.println("

Project Features

About this Project

QA was started in November 2009, is owned by Jiří Kovalský, and has 97 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20160708.bf2ac18). © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close