Java Reference
In-Depth Information
createSOAPRequest(stockSymbol),
SERVICE_HOST + SERVICE_ENDPOINT);
soapConnection.close();
return soapResponse;
} catch (UnsupportedOperationException | SOAPException e) {
e.printStackTrace();
} finally {
if (soapConnection != null)
try { soapConnection.close(); } catch (SOAPException i) {}
}
return null;
}
private static SOAPMessage createSOAPRequest(String stockSymbol) {
try {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPBody soapBody = soapMessage.getSOAPBody();
QName bodyName = new QName(SERVICE_HOST, SERVICE_METHOD);
SOAPBodyElement bodyElement = soapBody.addBodyElement(bodyName);
SOAPElement soapBodyArgument1 = bodyElement.addChildElement("symbol");
soapBodyArgument1.addTextNode(stockSymbol);
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", SERVICE_HOST + SERVICE_METHOD);
soapMessage.saveChanges();
return soapMessage;
} catch (SOAPException e) {
e.printStackTrace();
}
return null;
}
}
4.
Finally, you can create a test class containing a main method, called StockQuoteProgram :
package withoutwsdlobjectoriented;
import java.util.Set;
import javax.xml.soap.SOAPMessage;
public class StockQuoteProgram {
public static void main(String[] args) {
SOAPMessage soapReply = StockServiceClient.getStockQuote("IBM");
Set<Stock> stocks =
StockFactory.newStocksFromSOAPReplyMessage(soapReply);
Search WWH ::




Custom Search