Java Reference
In-Depth Information
public SOAPMessage invoke(SOAPMessage request) {
LOGGER.debug("Executing.");
String ns = "http://ns.soacookbook.com/credit";
QName svcQName = new QName(ns, "CreditService");
QName portQName = new QName(ns, "CreditAuthorizer");
String wsdlUrl = "http://localhost:8080/soaCookbookWS/
CreditService?wsdl";
final Service service = Service.create(svcQName);
service.addPort(portQName,
SOAPBinding.SOAP11HTTP_BINDING, wsdlUrl);
LOGGER.debug("Invoking Service: " + service.getServiceName() +
". Port: " + portQName + ". WSDL Location: " + wsdlUrl);
final Dispatch<SOAPMessage> dispatch =
service.createDispatch(portQName,
SOAPMessage.class, Service.Mode.MESSAGE);
//Call the Service with our message
return dispatch.invoke(request);
}
@SuppressWarnings(value = "unchecked")
public static Authorization unmarshal(SOAPMessage soapMsg){
LOGGER.debug("Executing.");
String pkg = "com.soacookbook.ns.credit";
Authorization auth = null;
try {
JAXBContext ctx = JAXBContext.newInstance(pkg);
Unmarshaller unmarshaller = ctx.createUnmarshaller();
//Show returned SOAP Message
soapMsg.writeTo(System.out);
//Get the payload of the response
Document doc =
soapMsg.getSOAPBody().extractContentAsDocument();
//turn DOM docunment paydload into JAXBElement
JAXBElement<Authorization> el =
(JAXBElement<Authorization>)
unmarshaller.unmarshal(doc);
//extract the payload as object
Search WWH ::




Custom Search