Section 16.2. How do you create a service provider in Java?


16.2. How do you create a service provider in Java?

In Chapter 15, we described how to service enable a Remote Function Call (RFC), creating a service from the inside out using ABAP. The process for service enabling a method in a Java class or EJB is quite similar, but it is worth taking a detailed look from the Java side. Similar to the example in Chapter 15, we will be providing employee address data through the web service we create in this section.

Since we are enabling existing functionality, we will assume that the EJB to be exposed already exists and that it has been imported into SAP NetWeaver Developer Studio or created in that development environment. We will also assume that an existing Enterprise Archive (EAR) project is associated with this EJB. In this example, we will work with a stateful session bean.

We start the Web Service Creation Wizard by right-clicking on the bean we want to service enable and selecting New Web Service, as shown in Figure 16-2.

Figure 16-2. Service enabling an EJB


The Web Service Creation Wizard starts, as shown in Figure 16-3.

Figure 16-3. The Web Service Creation Wizard


If you read Chapter 15, you may notice that the Java version of this wizard looks a bit different from the ABAP version. The Source Folder and Endpoint fields default to values appropriate for this service. We supply a Web Service Namein this case, EmployeeHomeAddressWS. This is where we configure the web service as well.

Web services configuration allows you to define (through a pull-down menu) the technical characteristics of this service very easily. For example, you can specify whether it is stateful or stateless and what type of transport it uses (on this screen, SOAP over HTTP; another option would be SOAP over HTTPS to provide transport-level encryption). It also defines what authentication measures will be used for the service; choices include none, username and password (referred to as basic authentication), and authentication using digital certificates. You can change all of these settings later if desired, but this pull-down menu provides you with an easy way to configure many technical details right in the wizard.

We click Next to display the screen shown in Figure 16-4. On this screen, we select the methods we want to service enable. You could choose multiple methods or all of them. In this case, we selected one method that takes two strings and a java.util.date as input.

Figure 16-4. Selecting the method or methods to service enable


We click Next to display the screen shown in Figure 16-5. On this screen, Endpoint defaults to the session bean we pointed at when we started the wizard. The virtual interface defaults to the same name as the web service, with VI appended; similarly, the Web Service Definition has the same name with Wsd appended. The EAR project defaults to the EAR project associated with this EJB.

Figure 16-5. Specifying the virtual interface, web services definition, and EAR project


The virtual interface allows you to hide or rename parameters, simplifying or customizing an interface. (We will demonstrate this later in this example.)

All changes that we make will be propagated to the EAR project specified here.

We click Finish to display the screen shown in Figure 16-6. This screen summarizes the characteristics of the web service we created, including its configuration details (session handling, authentication level, authorization, and transport guarantee).

Figure 16-6. The newly created web service


At this point, we tweak the virtual interface a bit. This is an optional step; it allows you to hide or rename parameters. In the J2EE Explorer (shown in Figure 16-7 in the left pane), we select the virtual interface for this web service.

Figure 16-7. Modifying the virtual interface


In Figure 16-7, you can see that we changed the method name from getEmployeePersonalAddress to getEmployeeHomeAddress. We also assigned addressType a fixed value (HM for home), so this will not appear as an input in the web service.

The next step is to deploy the EAR file. We then click on the Web Services perspective to display the Web Services Navigator, shown in Figure 16-8.

Figure 16-8. The Web Services Navigator


The SAP Web Service Homepage is displayed in the upper-right pane. We click Test to display the screen shown in Figure 16-9.

Figure 16-9. The SAP Web Service Homepage, which lists operations for the web service


This screen shows the operations for the web service; in this example, there is only one operation, and it is based on the method we selected. You can see that the method name change we made in the virtual interface (getEmployeePersonalAddress to getEmployeeHomeAddress) is reflected on this screen.

We click Test again to display the screen shown in Figure 16-10.

Figure 16-10. Testing the web service


Note that since we set addressType to HM, it doesn't appear as a parameter.

Note also that no Java coding was required to web service enable this EJB; everything, including the descriptor files, was generated for us. Now, we enter an employeeID (in this example, 1001) and click Send to display the screen shown in Figure 16-11.

Figure 16-11. The results of the test


On this screen, you can see the request and the response for the web service. Near the bottom of the screen, you can see the very top of the SOAP request and response messages. You can wrap and unwrap the SOAP message to view the details of what is sent over the wire. Looking at these details can be helpful when troubleshooting a web service, especially for SOAP fault messages.

Figure 16-12 shows the beginning of a list of the Web Services Description Language (WSDL) files available for this service.

Figure 16-12. The styles of WSDL files from which to choose


Document style is typically the best choice, but a variety of WSDL styles are available.

You can see that it is easy to turn Java functionality into a web service. You don't have to write more Java and you don't even have to write any XML. While you can tweak everything by hand or through the SAP NetWeaver Developer Studio, the wizard gives you the power to create a web service, hide and rename parameters and methods, and configure the service quite easily.




Enterprise SOA. Designing IT for Business Innovation
Enterprise SOA: Designing IT for Business Innovation
ISBN: 0596102380
EAN: 2147483647
Year: 2004
Pages: 265

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net