import javax.xml.soap.*;
public class SOAPClient {
public static void main(String[] args) {
try {
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPBody soapBody = soapEnvelope.getBody();
SOAPElement operation = soapBody.addChildElement("operation");
SOAPElement parameter = operation.addChildElement("parameter");
parameter.addTextNode("value");
SOAPMessage response = soapConnection.call(soapMessage, "http://example.com/service");
SOAPBody responseBody = response.getSOAPBody();
String result = responseBody.getTextContent();
System.out.println("Response: " + result);
soapConnection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
@Path("/hello")
public class HelloWorldResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
public String sayHello() {
return "Hello, World!";
}
}