Implement the GreetingService interface and GreetingServiceImpl class.
Create the GreetingPublisher to publish the web service.
Run the publisher and verify that the service is running (they should see the "Greeting Service is published!" message).
Implement the GreetingClient to consume the web service.
Run the client and verify that it receives the correct greeting.
Modify the getGreeting method to include the current time in the greeting.
(Optional) Create a simple GUI for the client using Java Swing or JavaFX.
This lab introduces several key concepts:
Web Service annotations (@WebService, @WebMethod, @WebParam)
Publishing a web service
Creating a client to consume a web service
Basic remote method invocation
It's simple enough for beginners to understand and implement quickly, but also provides room for creativity and extension. The personalized greeting aspect makes it more engaging than a standard "Hello World" example.
To make the lab more interactive, you could have students pair up and try to consume each other's web services by exchanging localhost URLs. This would reinforce the concept of distributed computing and network communication.
CopyRetry
Claude does not have the ability to run the code it generates yet.
Does this use a Java Application Server
The example I provided doesn't explicitly use a Java Application Server, but it's important to clarify this point.
Lightweight Deployment: The example uses the javax.xml.ws.Endpoint class to publish the web service. This approach creates a lightweight HTTP server and deploys the web service using it. It's suitable for testing and development but not for production environments.
Java Application Server Alternative: In a more realistic scenario, especially for production, you would deploy your web service to a Java Application Server. Common choices include:
Apache Tomcat
GlassFish
WildFly (formerly JBoss)
IBM WebSphere
Oracle WebLogic
Modifying the Lab for Application Server Deployment: To adapt this lab to use a Java Application Server like Tomcat, you would: a. Package the service in a WAR (Web Application Archive) file. b. Create a web.xml deployment descriptor or use annotations. c. Deploy the WAR file to the application server.
Here's how you could modify the lab to use Tomcat:
Package these files along with your compiled classes into a WAR file.
Deploy the WAR file to Tomcat's webapps directory.
Modify the client to use the new URL:
java
Copy
URL url = new URL("http://localhost:8080/your_war_name/greetingservice?wsdl");
Lab Extension for Application Server:
Install Apache Tomcat on their development machines.
Package the web service as a WAR file.
Deploy the WAR file to Tomcat.
Start Tomcat and verify the web service is running.
Modify the client to connect to the Tomcat-hosted service.
This extension would introduce students to:
Java Application Servers
WAR file structure
Deployment descriptors
The deployment process
While this adds complexity, it provides a more realistic scenario of how web services are typically deployed in production environments. You could offer this as an advanced option or a follow-up lab to the simpler Endpoint-based version.
Want to print your doc? This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (