It2406 LM

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 21

RAJALAKSHMI ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY IT2406 SERVICE ORIENTED ARCHITECTURE LAB

LAB MANUAL

CREATION OF ADDITION WEB SERVICE: Aim: To create a web service for adding few numbers using NetBeans. Algorithm: 1. 2. 3. 4. 5. 6. 7. Using the Netbeans API create a project of the type web application. Create a web service in the project. Click on the Design tab and design the prototype of the web service. Click on source tab and modify the application logic of the web service. Save the project. Right click on the project and click on deploy and undeploy. Then test the web service.

STEPS TO CREATE ADDITION WEB SERVICE: I.STEPS FOR CREATING SERVER SIDE PROJECT: 1.OPEN File->New->NewProject->Web->Web App..click next

2.Give Project name->addserverthen click finish

3.The addserver project will be created in right side.Right click it and choose the following. Give the web service name as addweb.

4.After this in left side ,the design window choose the add operation

5. Give the following in the opened window for creating operation Name->add

6.Then in the source add the following code and save it. package org; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; @WebService() public class addweb { /** * Web service operation */ @WebMethod(operationName = "add") public int add(@WebParam(name = "a") int a, @WebParam(name = "b") int b) { int k=a+b; return k;

} } 7.Then right click on add addserver and perform undeploy and deployafter that right click on addweb and do test web service to see the SOAP request and response message.

Give some integers and click add.

CREATION OF WEB SERVICE CLIENT Aim: To create a web service for adding few numbers using NetBeans and write client side code to invoke the web service. Algorithm: 1. Using the Netbeans API create a project of the type web application. 2. Create a web service in the project. 3. Click on the Design tab and design the prototype of the web service. 4. Click on source tab and modify the application logic of the web service. 5. Save the project. 6. Right click on the project and click on deploy and undeploy. 7. Then test the web service. 8. Create another web application project and create a jsp file. 9. Right click on project and click on create web service client. 10. Browse and choose the web service created i.e wsdl url 11. Drag and drop the web service reference to the source code window. 12. Then pass the appropriate parameters to the web service client and invoke the web service. STEPS TO CREATE CLIENT SIDE PROJECT: 1.create the new project as above and give the name as addclient.

2. addclient project will be created. right click it and choose the following.

3.Then browse and choose the addweb wsdl file

4.Then choose the following and add the source code in index.jsp and save it.

Index.jsp source code <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <h1>Hello World!</h1> <form name="" action="actionn.jsp" method="post"> Enter 1st No:<input name="fst" type="text" /><br/> Enter 2nd No:<input name="snd" type="text" /><br/> <input name="ok" type="submit" value="Add" /> </form> </body> </html> 5.Then create an action.jsp as follows. Right click web page in addclient and choose new->jsp Name:action

Click finish

6.click on the actionn.jsp page..then right click in it and choose web service client reference ->call web service

7.The invoke the add service.

8. add the following code in the action.jsp <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <h1>Hello World!</h1> <% String a1=request.getParameter("fst"); String b1=request.getParameter("snd"); int aa=Integer.parseInt(a1); int bb=Integer.parseInt(b1); %> <%-- start web service invocation --%><hr/> <% try { org.AddwebService service = new org.AddwebService(); org.Addweb port = service.getAddwebPort(); // TODO initialize WS operation arguments here int a = aa; int b = bb; // TODO process result here int result = port.add(a, b); out.println("Result = "+result); } catch (Exception ex) { // TODO handle custom exceptions here } %>

<%-- end web service invocation --%><hr/> </body> </html> 8.finally undeploy and deploy the addclient and run it.

CREATION OF A BPEL MODULE AND A COMPOSITE APPLICATION Aim: Create a SOA project with BPEL Module to compose a web service. STEPS TO CREATE A BPEL MODULE Creating a new BPEL Module Project The following sections use the Synchronous sample project, and provide step-by-step directions for creating a simple BPEL module project, using the Synchronous sample project. To Create a BPEL Module Project 1. In the NetBeans IDE, choose File > New Project. The New Projects wizard appears. 2. Under Categories, select Service Oriented Architecture. 3. Under Projects, select BPEL Moduleand click Next.

4. In the Name and Location page, enter the project name (for this example HelloWorld) and specify the project location or accept the defaults.

5. Click Finish. The Projects window now contains a project node for the BPEL Module project.

Creating a BPEL Process Using the BPEL Designer Now that you have created your XML Schema and WSDL Document, you can create your BPEL process. To Create the BPEL Process 1. In the Projects window, expand your BPEL module project node, right-click the Process Files node, and choose New -> BPEL Process. The New BPEL Process dialog box appears.

2. Enter a name for the process file name (HelloWorldProcess for this example), and click Finish. The new BPEL file opens in the Design view of the BPEL Designer. If the Palette and Properties windows are not displayed in your current view, click Windows -> Reset Windows on the NetBeans menu.

3. Add a partner link to the BPEL Process. a. In the Projects window, expand your project's Process Files node and select the .wsdl file (Synchronous.wsdl for this example). b. Drag the WSDL file from the Projects window to the left side of the Design view canvas. The IDE provides visual prompts to show you where you can drop the selection. The BPEL Editor adds a partner link to the canvas.

4. Add a Receive activity to the BPEL Process. a. From the Web Service section of the Palette window, select the Receive activity. b. Drag the Receive activity to the HelloWorldProcess process box in the Design view canvas, between the Process Start and the Process End activities. The Receive1 activity is added to the process box. c. Click the Receive1 activity's Edit icon. The Receive1 Property Editor appears. d. On the Main tab, change the value in the Name field to start. e. From the Partner Link drop-down list, choose PartnerLink1. The IDE populates the Operation field with NewWSDLOperation. f. Click the Create button next to the Input Variable Field. The New Input Variable dialog box appears. g. Click OK to accept the default values. h. Click OK to close the Receive1 Property Editor. The Design view displays the new connection between PartnerLink1 and the Start activity in the process box.

5. Add a Reply activity to the BPEL Process. a. Select the Reply activity in the Web Service section of the Palette. Drag and drop the Reply to the prompt between the Start activity and the Process End activity in the process box on the design view canvas. A Reply1 activity is added to the design view canvas. b. Click the Reply1 activity's Edit icon. The Reply1 Property Editor appears. c. On the Main tab, change the value in the Name field to End. d. From the Partner Link drop-down list, choose PartnerLink1. The IDE populates the Operation field with NewWSDLOperation. e. To create anew output variable, make sure that Normal Response is selected, and click the Create button next to the Input Variable Field. The New Input Variable dialog box appears. Click OK to accept the default values. f. Click OK to close the Reply1 Property Editor. The Design view displays the new connection between the End activity in the process box and PartnerLink1.

6. Add a Assign activity to the BPEL Process. a. Select the Assign activity in the Basic Activities section of the Palette. Drag and drop the Assign to the prompt between the Start activity and the End activity in the process box on the design view canvas. The Assign1 activity is added to the design view canvas. b. Select the Assign1 activity and click the Mapper button on the editors toolbar. The BPEL Mapper appears. c. Map the paramA node under Variables -> NewWSDLOperationIn -> inputType in the Output pane of the BPEL Mapper, to the paramA node under Variables -> NewWSDLOperationOut -> resultType in the Input pane of the Mapper. To do this, select theparamA node under Variables -> NewWSDLOperationIn -> inputType in the Output pane, and drag your cursor to the paramA node under Variables -> NewWSDLOperationOut -> resultType in the Input pane. This assignment copies the input statement into the output.

7. To save your changes click the Save All icon in the IDE menu bar. Creating a Composite Application Project A BPEL Module project is not directly deployable. You must first add a BPEL Module project, as a JBI module, to a Composite Application project. You can then deploy the Composite Application project. Deploying the project makes the service assembly available to the application server and enables its service units to run. To Create a New Composite Application Project 1. Choose File > New Project (Ctrl-Shift-N). 2. In the Categories list choose Service Oriented Architecture, in the Projects list choose Composite Application, and click Next. 3. In the Name and Location page, change the project name to HelloWorldApplication, and specify the location of project files. 4. To set the new Composite Application the main project as main, leave the Set as Main Project checkbox selected, and click Finish. 5. To add the BPEL Module as a JBI module to the Composite Application project, right-click the new Composite Application and choose Add JBI Module. The Select Project dialog box opens. 6. Select the HelloWorld project you created earlier and click Add Project JAR Files. The Select Project dialog box closes and the HelloWorld.jar file is added to the JBI Modules node of the HelloWorldApplication Composite Application Building and Deploying the Composite Application Project Building a project compiles the BPEL source file and packages the BPEL file and web service artifacts, including WSDL and XSD files, into a JAR archive. Deploying the project compiles the files in the Composite Application project, packages the compiled BPEL and related web service artifacts (including WSDL and XSD files) into an archive, and deploys them to the Application Server. To Build and Deploy the Composite Application Project 1. Right-click the Composite Application project's node, and choose Build. When the build is complete the Output window reports Build Successful. If the Output window is not visible, choose Window -> Output -> Output. 2. Right-click the Composite Application project's node, and choose Deploy. 3. Deployment has succeeded when you see a Build successful message in the GlassFish tab of the Output window.

4. Open the Services window and expand Servers -> GlassFish V2 -> JBI -> Service Assemblies to see your new deployed Service Assembly. If you do not see the deployed project, right-click the Service Assemblies node and choose Refresh.

Testing the Composite Application You can test your Composite Application project by adding test cases, binding to the operation, supplying input, and then using the tester. Test the HelloWorldApplication Composite Application Project 1. In the Projects window, expand the HelloWorldApplication project node, rightclick the Test node, and choose New Test Case. The New Test Case wizard opens. 2. Accept the default test case name, TestCase1, and click Next. 3. From the Select the WSDL Document page, expand the HelloWorld - Proecss Files node, select Synchronous.wsdl, and click Next. 4. From the Select the Operation to Test page, select the Operation1 and click Finish. A new TestCase1 node is added under the project's Test node in the Projects window, containing two subnodes, Input and Output. The Source Editor appears containing the Input file, Input.xml Note If the Source Editor does not contain a tab for Input.xml, double-click the Input node in the Projects window to open the file. 5. From the Input.xml tab of the Source Editor, do the following: a. Locate the line: <syn:paramA>?string?<syn:paramA> b. Replace ?string? with Hello World, so that the line appears as follows: <syn:paramA>Hello World<syn:paramA>

c. From the NetBeans IDE menu bar, click Save All.

6. In the Projects window, double-click the Output node under Test -> TestCase1. Output.xml is opened in the Source Editor. Initially, Output.xml is empty until the first test run populates the file. 7. In the Projects window, right-click the TestCase1 node and choose Run from the pop-up menu. When the Overwrite Empty Output dialog box appears, click Yes to accept new output. The first test run populates the Output.xml file displayed in the Source Editor.

The test compares the output to the contents of the output file. Because the first run of the test has nothing to compare itself to, the first test fails. Subsequent test runs will compare their output with the contents of Output.xml and should succeed. 8. Run the test again. The test case is compared to the current output file and succeeds.

You might also like