DOC PREVIEW
CMU ISM 95733 - JAXM Java API for XML Messaging (Processing SOAP)

This preview shows page 1-2-3-4-5-34-35-36-37-68-69-70-71-72 out of 72 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

95-733 Internet TechnologiesJava API for XML MessagingJAXM On the ClientSlide 4BookTitlesProxy.javaSlide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12On the ServerSlide 14A New Kind of ServletSlide 16Slide 17Slide 18Slide 19Running the ClientMy Classpath for JAXMSlide 22Asynchronous MessagingJAXM With a Message ProviderSlide 25Slide 26XML Messaging JAXMSlide 28Slide 29Slide 30Configure the ProviderSlide 32Set the classpathProvide two client.xml filesSlide 35Server Side DirectoriesClient Side DirectoriesClient Side Web.xmlSlide 39Slide 40Slide 41Server Side web.xmlSlide 43Server Side CalculationHandler.javaSlide 45Slide 46Slide 47Slide 48Slide 49Slide 50Slide 51Slide 52HTTP Servlet DoCalculationServletSlide 54Slide 55Slide 56Slide 57Slide 58Slide 59Slide 60JAXM Servlet ResultHandlerSlide 62Slide 63Slide 64Slide 65Slide 66Slide 67ResultHolder.javaSlide 69GetResultsAsHTMLSlide 71Slide 7295-733 Internet Technologies •JAXM Java API for XML Messaging (Processing SOAP)•Synchronous Messaging•Asynchronous MessageJava API for XML Messaging Two main packages SOAP with attachments API for Java (SAAJ) javax.xml.soap Java API for XML Messaging (JAXM) javax.xml.messagingJAXM On the Client// Code adapted from "Java Web Service" // by Deitel StandAloneClient.javaimport java.io.*;public class StandAloneClient { public static void main(String args[]) throws IOException { // Get a proxy that handles communications BookTitlesProxy service = new BookTitlesProxy(); System.out.println("Proxy created");// Ask the proxy for book titles String response[] = service.getBookTitles(); System.out.println("Book Titles"); for(int i = 0; i < response.length; i++) { System.out.println(response[i]); } }}BookTitlesProxy.java// Adapted from Java Web Services by Deitel & Deitel BookTitlesProxy.java// BookTitlesProxy runs on the client and handles communications// for wrapping a SOAP documentimport javax.xml.soap.*;// for sending the SOAP documentimport javax.xml.messaging.*;// Standard Java importsimport java.io.*;import java.net.URL;import java.util.Iterator;public class BookTitlesProxy { // We will need a connection, a message and an endpoint private SOAPConnectionFactory soapConnectionFactory; private URLEndpoint urlEndpoint; private MessageFactory messageFactory;public BookTitlesProxy() throws java.io.IOException { try { // get factories and endpoints soapConnectionFactory = SOAPConnectionFactory.newInstance(); System.out.println("Got SOAPconnection factory"); // get a message factory messageFactory = MessageFactory.newInstance(); System.out.println("Got Message factory"); // establish a url endpoint urlEndpoint = new URLEndpoint( "http://localhost:8080/AnotherSOAPDemo/BookTitles"); System.out.println("endpoint built"); } catch (SOAPException e) { throw new IOException(e.getMessage()); } }public String[] getBookTitles() { // invoke web service try { SOAPMessage response = sendSoapRequest(); return handleSoapResponse(response); } catch (SOAPException e) { System.out.println("Mike's Exception " + e); return null; } }private SOAPMessage sendSoapRequest() throws SOAPException { // get a SOAPConnection from the factory SOAPConnection soapConnection = soapConnectionFactory.createConnection(); // get a SOAPMessage from the factory SOAPMessage soapRequest = messageFactory.createMessage(); // make a synchronous call on the service // in other words, call and wait for the response SOAPMessage soapResponse = soapConnection.call(soapRequest, urlEndpoint); System.out.println("Got soap response from server"); soapConnection.close(); return soapResponse; }/* The SOAP response has the following structure <soap-env:Envelope xmlns:soap-env= "http://schemas.xmlsoap.org/soap/envelope/"> <soap-env:Header/> <soap-env:Body> <titles bookCount="2"> <title>To Kill A MokingBird</title> <title>Billy Budd</title> </titles> </soap-env:Body> </soap-env:Envelope> */private String[] handleSoapResponse(SOAPMessage sr) throws SOAPException { // We need to take the result from the SOAP message SOAPPart responsePart = sr.getSOAPPart(); SOAPEnvelope responseEnvelope = responsePart.getEnvelope(); SOAPBody responseBody = responseEnvelope.getBody(); Iterator responseBodyChildElements = responseBody.getChildElements(); SOAPBodyElement titlesElement = (SOAPBodyElement) responseBodyChildElements.next();int bookCount = Integer.parseInt( titlesElement.getAttributeValue( responseEnvelope.createName( "bookCount"))); String bookTitles[] = new String[bookCount]; Iterator titleIterator = titlesElement.getChildElements( responseEnvelope.createName("title")); int i = 0; while(titleIterator.hasNext()) { SOAPElement titleElement = (SOAPElement) titleIterator.next(); bookTitles[i++] = titleElement.getValue(); } return bookTitles; }}On the Server //BookTitlesImpl.java// code adapted from "Java Web Services" by Deitel import java.io.*; import java.util.*;// when using rdbms


View Full Document

CMU ISM 95733 - JAXM Java API for XML Messaging (Processing SOAP)

Download JAXM Java API for XML Messaging (Processing SOAP)
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view JAXM Java API for XML Messaging (Processing SOAP) and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view JAXM Java API for XML Messaging (Processing SOAP) 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?