Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Stop Speculating, Start Building: A Step-by-step Guide to Building Web Services with WebLogic Workshop 8.1 and MySQL : Page 3

Use this simple, step-by-step solution to download and configure both WebLogic platform 8.1 and MySQL, and develop a Web service that ties the two together.


advertisement
Step 4. Configure WebLogic Application Server for MySQL Access
When a Web service is running within the WebLogic application server and it needs to use classes that are contained in third-party JAR files (like what we want to do with the MySQL classes hosted in the MySQL JAR file), the application server needs to be configured at start-up to have access to these JAR files.

The following steps enable you to do this:

  1. Using Windows Explorer, navigate to the following directory (BEA_HOME is the installation directory, probably c:\bea\weblogic81b):

    {BEA_HOME}\samples\domains\platform

  2. Right click the file startWebLogic.cmd and select 'Edit.'
  3. Notepad will open the file. Find the line that reads:


    PRE_CLASSPATH=.;%POINTBASE_CLASSPATH%;%WLW_PRE_CLASSPATH%;
    %WLI_PRE_CLASSPATH%;%WLP_PRE_CLASSPATH%

    and amend it to read:

    PRE_CLASSPATH=.;C:\mysqljar\mysql-connector-java-3.0.7-stable\
    mysql-connector-java-3.0.7-stable-bin.jar;%POINTBASE_CLASSPATH%;
    %WLW_PRE_CLASSPATH%;%WLI_PRE_CLASSPATH%;%WLP_PRE_CLASSPATH%

Save the file. Launch WebLogic Workshop and start the WebLogic server as before.

You have added the reference to the MySQL JAR file that you downloaded earlier. If you installed it to a different directory, make sure that the new entry in this file corresponds to the location of the mysql-connector JAR file on your hard drive.

Now, start the WebLogic console by opening your browser and navigating to http://localhost:7001/console. If the server is running, you will get the WebLogic login prompt. Log in with the username 'weblogic' and the password 'weblogic.' These are the default settings you accepted when you installed the application. If you chose your own username and password instead of the defaults, enter them here.

You can test whether the server recognizes your driver by doing the following:

  1. Look for the JDBC setting on the right-hand side and select the 'Connection Pools' link underneath it.
  2. On the next screen, select 'Configure a new JDBC connection pool.'
  3. For database type. select 'Other.' If MySQL is available and you want to use the built-in driver, skip the rest of this section, but note the driver classname. You'll need it later.
  4. Enter the following settings on the next screen:
    • Name: MySQL
    • Driver Classname: com.mysql.jdbc.Driver
    • URL: jdbc:mysql://localhost/content
    • Database User Name: root
    • Password: root
    • Confirm Password: root
  5. Click 'Test Connection.' You should see a message saying 'Connection Successful' at the top of the screen. If you don't, please recheck all the previous steps to make sure you have set up the MySQL server correctly.

Step 5. Create the Web Service
The Web service will expose two methods. The first method allows users to enter data into the database. The second method retrieves the last five articles from the database, based on their date.

To create the Web service, start up WebLogic Workshop and the application server as outlined in Step 1. Once it has loaded, do the following:

  1. Close the current application by issuing File–>Close Application.
  2. Create a new application with File–>New–>Application.
  3. On the application dialog, select a 'Default Application' and give it the name 'Webcontents.'
  4. Click 'Create,' and click 'Yes' if it asks whether you want to create the directory.
  5. Create a new Web services project by selecting File–>New–>Project.
  6. In the ensuing dialog, select 'Web Services' on the list and 'Web Service Project' as the Project type. Name the project 'WebContentWS.'
  7. Create the Web Service by selecting File–>New–>Web Service. Give it the name "WS.jws."
  8. If you look at the WebContentsWS node in your application, you will now see 'Helloworld.jws' and 'Ws.jws.'
  9. Open Ws.jws and the WebLogic Workshop designer will open onto your Web service.

The WLW designer is a unique piece of software that allows you to visually design your Web service. This solution only scratches the surface of its features, but feel free to play with it and work through the Help file tutorials to see more.

Step 6. Implement the Web Service
Within the WLW designer, you can add your methods and design them. To do this, you must first understand the screen layout. Figure 2 shows the designer.

The Web Service Designer
Figure 2: The Web Service Designer

The Web service is denoted by a box, which is divided into two areas. The light gray area on the left denotes the outward-facing interface of the Web service. The darker gray area on the right denotes the inward-facing interface of the Web service. If the Web service is calling other Web services further "in" the architecture, you will see links to them here.

The methods that you will create in your Web service are fairly straightforward. They are:

  • getContents(): queries the contents of the database and returns the last five articles by date
  • setContents(): uploads new contents to the database

To create these, follow these steps:

  1. Right click the light gray area on the left, and select 'New Method.' Call it getContents.
  2. Repeat the previous step for 'setContents.'
  3. Right click the getContents link in the gray area, and select 'Edit XML Maps.' On the bottom window of the ensuing dialog, change the Java to read:

    public String getContents()

  4. Right click the setContents link in the gray area, and select 'Edit XML Maps.' On the bottom window of the ensuing dialog, change the Java to read:

    public bool setContents(String contentDate,
    String contentTitle, String contentText)

  5. Note how the XML changes to show the ingoing and outgoing schemas based on the Java language method maps.

    You now have a basic, boilerplate Web service, so the next step is to add the code that implements the methods.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date