Initial commit: JAX-WS Hello World Service
- Complete JAX-WS Hello World implementation - Docker and Docker Compose support for easy deployment - Python test scripts for service validation - Comprehensive README with setup instructions for Windows and Linux - Maven configuration with JAX-WS dependencies 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
155
scripts/README.md
Normal file
155
scripts/README.md
Normal file
@ -0,0 +1,155 @@
|
||||
# Test Scripts for JAX-WS Hello World Service
|
||||
|
||||
This folder contains test scripts to interact with the JAX-WS Hello World Service.
|
||||
|
||||
## Python Test Script
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Python 3.6 or higher
|
||||
- pip (Python package installer)
|
||||
|
||||
### Installation
|
||||
|
||||
1. **Install Python dependencies:**
|
||||
|
||||
**Windows:**
|
||||
```cmd
|
||||
cd scripts
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
**Linux/Mac:**
|
||||
```bash
|
||||
cd scripts
|
||||
pip3 install -r requirements.txt
|
||||
```
|
||||
|
||||
### Running the Test Script
|
||||
|
||||
Make sure the JAX-WS service is running (using Docker or traditional setup).
|
||||
|
||||
**Windows:**
|
||||
```cmd
|
||||
python test_hello_world.py
|
||||
```
|
||||
|
||||
**Linux/Mac:**
|
||||
```bash
|
||||
python3 test_hello_world.py
|
||||
# OR
|
||||
chmod +x test_hello_world.py
|
||||
./test_hello_world.py
|
||||
```
|
||||
|
||||
### What the Script Does
|
||||
|
||||
The `test_hello_world.py` script:
|
||||
|
||||
1. **Checks WSDL availability** - Verifies the service is running
|
||||
2. **Tests with multiple names** - Calls the service with predefined test cases
|
||||
3. **Interactive mode** - Allows you to enter custom names and see responses in real-time
|
||||
|
||||
### Example Output
|
||||
|
||||
```
|
||||
============================================================
|
||||
JAX-WS Hello World Service Test Client
|
||||
============================================================
|
||||
|
||||
1. Checking WSDL availability...
|
||||
WSDL is accessible
|
||||
|
||||
2. Testing Hello World Service...
|
||||
|
||||
Calling service with name: 'World'
|
||||
Response: Hello World, World!
|
||||
|
||||
Calling service with name: 'Python Client'
|
||||
Response: Hello World, Python Client!
|
||||
|
||||
Calling service with name: 'JAX-WS User'
|
||||
Response: Hello World, JAX-WS User!
|
||||
|
||||
Calling service with name: 'Docker'
|
||||
Response: Hello World, Docker!
|
||||
|
||||
3. Interactive Mode
|
||||
--------------------------------------------------------
|
||||
Enter a name (or 'quit' to exit): John
|
||||
Response: Hello World, John!
|
||||
|
||||
Enter a name (or 'quit' to exit): quit
|
||||
|
||||
============================================================
|
||||
Test completed!
|
||||
============================================================
|
||||
```
|
||||
|
||||
## Using the HelloWorldClient Class
|
||||
|
||||
You can also use the `HelloWorldClient` class in your own Python scripts:
|
||||
|
||||
```python
|
||||
from test_hello_world import HelloWorldClient
|
||||
|
||||
# Create client
|
||||
client = HelloWorldClient()
|
||||
|
||||
# Check if service is available
|
||||
is_available, message = client.check_wsdl()
|
||||
print(message)
|
||||
|
||||
# Call the service
|
||||
response = client.call_hello_world("Your Name")
|
||||
print(response) # Output: Hello World, Your Name!
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Service Not Available
|
||||
|
||||
If you get a connection error:
|
||||
|
||||
1. Make sure the Docker container is running:
|
||||
```bash
|
||||
docker ps | grep jaxws
|
||||
```
|
||||
|
||||
2. Check if the service is accessible:
|
||||
```bash
|
||||
curl http://localhost:8080/jaxws-hello-world/hello?wsdl
|
||||
```
|
||||
|
||||
3. Restart the service:
|
||||
```bash
|
||||
docker-compose restart
|
||||
```
|
||||
|
||||
### Python Not Found
|
||||
|
||||
If you get "python: command not found":
|
||||
|
||||
- **Windows**: Use `python` or `py` command
|
||||
- **Linux/Mac**: Use `python3` command
|
||||
|
||||
### Dependencies Not Installing
|
||||
|
||||
If pip install fails:
|
||||
|
||||
1. Make sure pip is up to date:
|
||||
```bash
|
||||
python -m pip install --upgrade pip
|
||||
```
|
||||
|
||||
2. Try installing with sudo (Linux/Mac only):
|
||||
```bash
|
||||
sudo pip3 install -r requirements.txt
|
||||
```
|
||||
|
||||
3. Use a virtual environment:
|
||||
```bash
|
||||
python3 -m venv venv
|
||||
source venv/bin/activate # On Windows: venv\Scripts\activate
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
4
scripts/requirements.txt
Normal file
4
scripts/requirements.txt
Normal file
@ -0,0 +1,4 @@
|
||||
# Python dependencies for JAX-WS Hello World test scripts
|
||||
|
||||
# HTTP library for making SOAP requests
|
||||
requests>=2.31.0
|
||||
49
scripts/simple_test.py
Normal file
49
scripts/simple_test.py
Normal file
@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Simple non-interactive test script for JAX-WS Hello World Service
|
||||
"""
|
||||
|
||||
import sys
|
||||
from test_hello_world import HelloWorldClient
|
||||
|
||||
|
||||
def test_service(name=None):
|
||||
"""
|
||||
Simple test function
|
||||
|
||||
Args:
|
||||
name: Optional name to test with. If None, uses "World"
|
||||
"""
|
||||
if name is None:
|
||||
name = "World" if len(sys.argv) < 2 else sys.argv[1]
|
||||
|
||||
client = HelloWorldClient()
|
||||
|
||||
# Check WSDL
|
||||
print(f"Checking service availability...")
|
||||
wsdl_ok, wsdl_msg = client.check_wsdl()
|
||||
|
||||
if not wsdl_ok:
|
||||
print(f"[FAIL] {wsdl_msg}")
|
||||
sys.exit(1)
|
||||
|
||||
print(f"[OK] {wsdl_msg}")
|
||||
|
||||
# Call service
|
||||
print(f"\nCalling service with: '{name}'")
|
||||
result = client.call_hello_world(name)
|
||||
print(f"Response: {result}")
|
||||
|
||||
# Verify response format
|
||||
expected_start = f"Hello World, {name}"
|
||||
if result.startswith(expected_start):
|
||||
print("\n[PASS] Test PASSED!")
|
||||
return 0
|
||||
else:
|
||||
print(f"\n[FAIL] Test FAILED! Expected response to start with: '{expected_start}'")
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
exit_code = test_service()
|
||||
sys.exit(exit_code)
|
||||
208
scripts/test_hello_world.py
Normal file
208
scripts/test_hello_world.py
Normal file
@ -0,0 +1,208 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Python script to test JAX-WS Hello World Service
|
||||
"""
|
||||
|
||||
import requests
|
||||
import xml.etree.ElementTree as ET
|
||||
from xml.dom import minidom
|
||||
|
||||
|
||||
class HelloWorldClient:
|
||||
"""Client for Hello World SOAP Service"""
|
||||
|
||||
def __init__(self, service_url="http://localhost:8080/jaxws-hello-world/hello"):
|
||||
"""
|
||||
Initialize the Hello World client
|
||||
|
||||
Args:
|
||||
service_url: The SOAP service endpoint URL
|
||||
"""
|
||||
self.service_url = service_url
|
||||
self.wsdl_url = f"{service_url}?wsdl"
|
||||
self.headers = {
|
||||
'Content-Type': 'text/xml; charset=utf-8',
|
||||
'SOAPAction': ''
|
||||
}
|
||||
|
||||
def create_soap_envelope(self, name):
|
||||
"""
|
||||
Create SOAP envelope for getHelloWorld request
|
||||
|
||||
Args:
|
||||
name: The name parameter for the hello world service
|
||||
|
||||
Returns:
|
||||
XML string of SOAP envelope
|
||||
"""
|
||||
soap_envelope = f"""<?xml version="1.0" encoding="UTF-8"?>
|
||||
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
|
||||
xmlns:ser="http://service.example.com/">
|
||||
<soapenv:Header/>
|
||||
<soapenv:Body>
|
||||
<ser:getHelloWorld>
|
||||
<arg0>{name}</arg0>
|
||||
</ser:getHelloWorld>
|
||||
</soapenv:Body>
|
||||
</soapenv:Envelope>"""
|
||||
return soap_envelope
|
||||
|
||||
def call_hello_world(self, name):
|
||||
"""
|
||||
Call the Hello World SOAP service
|
||||
|
||||
Args:
|
||||
name: The name to send to the service
|
||||
|
||||
Returns:
|
||||
Response message from the service
|
||||
"""
|
||||
try:
|
||||
# Create SOAP envelope
|
||||
soap_request = self.create_soap_envelope(name)
|
||||
|
||||
# Make the SOAP request
|
||||
response = requests.post(
|
||||
self.service_url,
|
||||
data=soap_request,
|
||||
headers=self.headers,
|
||||
timeout=10
|
||||
)
|
||||
|
||||
# Check if request was successful
|
||||
response.raise_for_status()
|
||||
|
||||
# Parse the response
|
||||
return self.parse_response(response.text)
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
return f"Error calling service: {str(e)}"
|
||||
|
||||
def parse_response(self, response_xml):
|
||||
"""
|
||||
Parse the SOAP response
|
||||
|
||||
Args:
|
||||
response_xml: The XML response from the service
|
||||
|
||||
Returns:
|
||||
The return value from the service
|
||||
"""
|
||||
try:
|
||||
# Parse XML
|
||||
root = ET.fromstring(response_xml)
|
||||
|
||||
# Find the return element
|
||||
# Handle namespaces
|
||||
namespaces = {
|
||||
'S': 'http://schemas.xmlsoap.org/soap/envelope/',
|
||||
'ns2': 'http://service.example.com/'
|
||||
}
|
||||
|
||||
# Find the return value
|
||||
return_elem = root.find('.//ns2:getHelloWorldResponse/return', namespaces)
|
||||
|
||||
if return_elem is not None:
|
||||
return return_elem.text
|
||||
else:
|
||||
return "Could not find return value in response"
|
||||
|
||||
except ET.ParseError as e:
|
||||
return f"Error parsing response: {str(e)}"
|
||||
|
||||
def check_wsdl(self):
|
||||
"""
|
||||
Check if WSDL is accessible
|
||||
|
||||
Returns:
|
||||
True if WSDL is accessible, False otherwise
|
||||
"""
|
||||
try:
|
||||
response = requests.get(self.wsdl_url, timeout=5)
|
||||
response.raise_for_status()
|
||||
return True, "WSDL is accessible"
|
||||
except requests.exceptions.RequestException as e:
|
||||
return False, f"Cannot access WSDL: {str(e)}"
|
||||
|
||||
def pretty_print_xml(self, xml_string):
|
||||
"""
|
||||
Pretty print XML string
|
||||
|
||||
Args:
|
||||
xml_string: XML string to format
|
||||
|
||||
Returns:
|
||||
Formatted XML string
|
||||
"""
|
||||
try:
|
||||
parsed = minidom.parseString(xml_string)
|
||||
return parsed.toprettyxml(indent=" ")
|
||||
except Exception:
|
||||
return xml_string
|
||||
|
||||
|
||||
def main():
|
||||
"""Main function to test the Hello World service"""
|
||||
|
||||
print("=" * 60)
|
||||
print("JAX-WS Hello World Service Test Client")
|
||||
print("=" * 60)
|
||||
print()
|
||||
|
||||
# Create client
|
||||
client = HelloWorldClient()
|
||||
|
||||
# Check WSDL
|
||||
print("1. Checking WSDL availability...")
|
||||
wsdl_ok, wsdl_msg = client.check_wsdl()
|
||||
print(f" {wsdl_msg}")
|
||||
if not wsdl_ok:
|
||||
print(" Service is not available. Make sure the service is running.")
|
||||
return
|
||||
print()
|
||||
|
||||
# Test with different names
|
||||
test_names = [
|
||||
"World",
|
||||
"Python Client",
|
||||
"JAX-WS User",
|
||||
"Docker"
|
||||
]
|
||||
|
||||
print("2. Testing Hello World Service...")
|
||||
print()
|
||||
|
||||
for name in test_names:
|
||||
print(f" Calling service with name: '{name}'")
|
||||
result = client.call_hello_world(name)
|
||||
print(f" Response: {result}")
|
||||
print()
|
||||
|
||||
# Interactive mode
|
||||
print("3. Interactive Mode")
|
||||
print(" " + "-" * 56)
|
||||
try:
|
||||
while True:
|
||||
user_input = input(" Enter a name (or 'quit' to exit): ").strip()
|
||||
|
||||
if user_input.lower() in ['quit', 'exit', 'q']:
|
||||
break
|
||||
|
||||
if user_input:
|
||||
result = client.call_hello_world(user_input)
|
||||
print(f" Response: {result}")
|
||||
print()
|
||||
else:
|
||||
print(" Please enter a valid name.")
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\n Interrupted by user")
|
||||
|
||||
print()
|
||||
print("=" * 60)
|
||||
print("Test completed!")
|
||||
print("=" * 60)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user