16.10.2015 Views

Getting Started with WebSphere Application Server

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 7 – Web services 139<br />

e.printStackTrace();<br />

}<br />

}<br />

Listing 7.9 – Get Web service from Web application context<br />

To resolve the type errors add this line:<br />

import javax.naming.*;<br />

You can also use annotation to get the Web service resource into the servlet. Add the lines<br />

below in the Servlet class definition:<br />

@Resource(name="services/Hello")<br />

Service service;<br />

Then change the doPost method as shown in Listing 7.10:<br />

protected void doPost(HttpServletRequest request, HttpServletResponse<br />

response) throws ServletException, IOException {<br />

PrintWriter out = response.getWriter();<br />

String target = request.getParameter("target");<br />

HelloBillService billService = (HelloBillService)service;<br />

HelloPeople bill = billService.getHelloBillPort();<br />

out.println(bill.sayHello(target));<br />

}<br />

Listing 7.10 – Changes in Servlet after using @Resource annotation<br />

To resolve the type errors add these lines:<br />

import javax.annotation.Resource;<br />

import javax.xml.ws.Service;<br />

7.4 Creating Data Web services <strong>with</strong> IBM Data Studio<br />

Data Web Services refer to the ability to wrap Web services around the logic provided by<br />

the database. For example, you might already have a SQL script or stored procedure that<br />

provides business logic for returning the current price of a particular item in inventory from<br />

the database. Using Data Web Services, you are simply making it much easier for a Web<br />

application (or other client) to invoke that capability, perhaps even as simple as putting the<br />

HTTP request in a Web browser.<br />

This approach to creating a Web service based on existing database operations/business<br />

logic is called “bottoms up” as opposed to a to ”top down” approach in which the Web<br />

services description is defined first and then logic is provided to map to that particular<br />

description.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!