Sending and receiving XML in a Java application Sean C. Sullivan sean seansullivan com September 2003.

Slides:



Advertisements
Similar presentations
Java Message Service (JMS) CS 595 Web Services Aysu Betin-Can.
Advertisements

 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
An architecture for webb applications, J2EE
Introduction to Java 2 Enterprise Edition About myself –Neutrinos, Cancer Research, IT Applications Today’s topic: J2EE –Context –Advantages –Components.
Objectives Ch. D - 1 At the end of this chapter students will: Know the general architecture and purpose of servlets Understand how to create a basic servlet.
Middleware Fatemeh Hendijanifard 1 آزمايشگاه سيستم هاي هوشمند (
Servlets and a little bit of Web Services Russell Beale.
Slide 1 EE557: Server-Side Development Lecturer: David Molloy Room: XG19 Mondays 10am-1pm Notes:
J2EE JavaMail API Presented by Bartosz Sakowicz. Instalation Java Mail API: Java Activation Framework.
SOAP Chandra Dutt Yarlagadda Introduction  Why ?  What ?  How ?  Security Issues in SOAP  Advantages  Uses  Conclusion.
Java Message Service API CSE 487/587 Feb 17, 2005 References: JRun Programmer’s Guide.
JMS Java Message Service Instructor Professor: Charles Tappert By Student: Amr Fouda.
EEC-681/781 Distributed Computing Systems Lecture 6 Wenbing Zhao Department of Electrical and Computer Engineering Cleveland State University
Session-01. What is a Servlet? Servlet can be described in many ways, depending on the context: 1.Servlet is a technology i.e. used to create web application.
JAVA MAIL API. High level representation of the basic components of any mail system. The components are represented by abstract classes in the javax.mail.
Messaging Technologies Group: Yuzhou Xia Yi Tan Jianxiao Zhai.
TP2653 Adv Web Programming SOAP and WSDL. SOAP Simple Object Access Protocol – Lightweight XML-based messaging protocol – A protocol for accessing a Web.
Research on Non-repudiation service By Yi Zhang. Motivation of Non-repudiation In paper-based business Electronic business transactions Less physical.
Web technologies and programming cse hypermedia and multimedia technology Fanis Tsandilas April 3, 2007.
SMTP, POP3, IMAP.
HTTP client wide area network (Internet) HTTP proxy HTTP server HTTP gateway firewall HTTP tunnel Copyright Springer Verlag Berlin Heidelberg 2004.
Ing. Ignacio Roqueta ARTech GeneXus and J2EE.
Enterprise Computing COSC 617 Jeff Schmitt September 7,2006.
Java Message Service - What and Why? Bill Kelly, Silvano Maffeis SoftWired AG, Zürich
Module 6 Message-Driven Beans. History Introduced in EJB 2.0 –Supports processing of asynchronous messages from a JMS provider Definition expanded in.
CS 493/693: Distributed Systems Programming V. “Juggy” Jagannathan CSEE, West Virginia University March 21, 2005.
Prepared By : Monika Darji Web Services using REST & JAX-WS.
Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.
1 SOA and Enterprise Computing Enterprise Java Beans.
Java Transaction API Sean C. Sullivan
第十四章 J2EE 入门 Introduction What is J2EE ?
Enterprise Java v120131Intro to JavaEE1 Java EE 5 TM Introduction.
Message Driven Beans & Web Services INFORMATICS ENGINEERING – UNIVERSITY OF BRAWIJAYA Eriq Muhammad Adams J
James Holladay, Mario Sweeney, Vu Tran. Web Services Presentation Web Services Theory James Holladay Tools – Visual Studio Vu Tran Tools – Net Beans Mario.
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
OCT 1 Master of Information System Management Organizational Communications and Distributed Object Technologies Lecture 5: JMS.
Architecture of Message Oriented Middleware [1]
Java Messaging Service. An Abstraction for using Messaging Oriented Middleware Purpose is to provide a sophisticated, yet straightforward way to exchange.
1 Java Message Service Манин П Enterprise messaging Key concept: 1. Messages are delivered asynchronously 2. Sender is not required to wait for.
INT-5: Integrate over the Web with OpenEdge® Web Services
Databases JDBC (Java Database Connectivity) –Thin clients – servlet,JavaServer Pages (JSP) –Thick clients – RMI to remote databases –most recommended way.
Http protocol Response-request Clients not limited to web browsers. Anything that can access code implementing the protocol works: –Standalone programs.
1 Seminar on Service Oriented Architecture Principles of REST.
1 Web Services Web and Database Management System.
CliServ. J2EE/141 Client/Server Distributed Systems v Objectives –introduce the J2EE specification, and the J2EE SDK –other approaches: Struts,
JMS (Java Messaging Service)
Copyright © 2002 ProsoftTraining. All rights reserved. Java Servlets.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
A quick overview of Network communications A quick overview of Network communications Anthony Lomax Anthony Lomax Scientific Software Mouans-Sartoux, France.
Java Message Service (JMS) Web Apps and Services.
1 Distributed System using J2EE. 2 What is J2EE?  J2EE (Java2 Enterprise Edition) offers a suite of software specification to design, develop, assemble.
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
XML-RPC: How Fast ? Brent Callaghan Sun Microsystems, Inc.
Introduction to Web Services Presented by Sarath Chandra Dorbala.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Java Message Service Introduction to JMS API. JMS provides a common way for Java programs to create, send, receive and read an enterprise messaging system’s.
December 9, 2004 EC511 Java Pet Store Demo Chandra Donipati.
Server-side http General form of http response/request GET request method POST request method Responses Servlet support.
SOAP, Web Service, WSDL Week 14 Web site:
SOAP : Simple Object Access Protocol A ‘clean’ tool for remote procedure calls.
Slide No. 1 of 111 JMS ( J AVA M ESSAGE S ERVICE ) -Dhananjay Singh.
Clinical Data Exchange using HL7 and Mirth Connect Lecture 8 - HTTP Connectors - Web Service Connectors - JMS Connectors Siv Raman, MD, MS.
Introduction to Servlets
Java Messaging Service (JMS)
Java Messaging Service (JMS)
Distributed System Using Java 2 Enterprise Edition (J2EE)
Java Messaging Service (JMS)
Harjutus 3: Aünkroonne hajussüsteemi päring
Servlet APIs Every servlet must implement javax.servlet.Servlet interface Most servlets implement the interface by extending one of these classes javax.servlet.GenericServlet.
Lab 6 – EJB User Managment
Presentation transcript:

Sending and receiving XML in a Java application Sean C. Sullivan sean seansullivan com September 2003

Agenda XML XML via HTTP XML via JMS XML via JavaMail XML via FTP

Agenda XML XML via HTTP XML via JMS XML via JavaMail XML via FTP

XML Sun Microsystems SUNW XML is a syntax for describing and structuring data

Application integration “[If you look at] where XML is really, truly being used right now, it's [for] lightweight, quick and dirty enterprise application integration. […] you could achieve remarkably acceptable results in enterprise application integration simply by binding a set of XML messages to ship back and forth.” Tim Bray, 9/23/2003, news.com interview

Data exchange Application BApplication A

XML request OVERNIGHT

XML response 68.00

Agenda XML XML via HTTP XML via JMS XML via JavaMail XML via FTP

HTTP protocol HTTP server HTTP client request

HTTP protocol HTTP server HTTP client request response

HTTP protocol methods GET POST HEAD …

HTTP headers Content-Type Accept

MIME types for XML text/xml application/xml text/xml-external-parsed-entity application/xml-external-parsed-entity application/xml-dtd application/soap+xml

Jakarta Commons HTTPClient

Example: HTTP POST import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.methods*; PostMethod post = new PostMethod( “ post.setRequestBody(strXML); post.setRequestHeader( “Content-type”, “application/xml”);

Example: HTTP POST post.setRequestHeader( “Accept”, “application/xml”); HttpClient client = new HttpClient(); int result = client.executeMethod(post); // … String strXMLResponse = post.getResponseBodyAsString(); post.releaseConnection();

Receiving XML using a Servlet public class XMLServlet extends javax.servlet.http.HttpServlet { protected void doPost( HttpServletRequest req, HttpServletResponse resp) { // … method implementation … }

doPost method // … String type = req.getContentType(); int contentLength = req.getContentLength(); char[] xmlData = new char[contentLength]; BufferedReader reader = httpRequest.getReader(); // …

doPost (continued) do { n = reader.read(xmlData, bytesRead, xmlData.length - bytesRead); if (n > 0) { bytesRead += n; } } while ( (n != -1) && (bytesRead < contentLength) )

Agenda XML XML via HTTP XML via JMS XML via JavaMail XML via FTP

Java Message Service messaging API for J2EE platform Point-to-point –JMS Queue Publish-Subscribe –JMS Topic “at most once” delivery mode transactional

JMS message queue Message Producer Message Queue 123 Message Consumer

Sending XML using JMS import javax.jms.*; import javax.naming.*; Queue queue; ConnectionFactory cf; queue = /* lookup via JNDI */; cf = /* lookup via JNDI */; Connection conn = cf.createConnection(); Session session = conn.createSession(…);

Sending XML using JMS MessageProducer producer; producer = session.createProducer(queue); TextMessage msg; msg = session.createTextMessage(); msg.setText(strXML); producer.send(msg); session.commit();

Receiving XML via JMS Choose one: javax.jms.MessageConsumer Message Driven Bean (MDB)

Example: Message Driven Bean public void onMessage(Message msg) { // … if (msg instanceof TextMessage) { TextMessage tm = (Message) msg; String strXML = tm.getText(); } // … }

Agenda XML XML via HTTP XML via JMS XML via JavaMail XML via FTP

JavaMail

Example: XML via JavaMail import javax.mail.*; import javax.mail.internet.*; Session sess = /* JNDI lookup */; MimeMessage msg = new MimeMessage(sess); msg.setFrom(from); // …

Example: XML via JavaMail // … msg.setRecipients( Message.RecipientType.TO, recipients); msg.setSubject(“Hello XML”); // …

Example: XML via JavaMail // … MimeBodyPart mbp = new MimeBodyPart(); mbp.setContent(strXML, “application/xml”); Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp); msg.setContent(mp); Transport.send(msg); // …

Agenda XML XML via HTTP XML via JMS XML via JavaMail XML via FTP

FTP with Jakarta Commons Net

Example: XML via FTP import org.apache.commons.net.ftp.*; FTPClient ftp = new FTPClient(); ftp.connect(“ftp.example.com”); ftp.login(username, password);

Example: XML via FTP ftp.setFileType(FTP.BINARY_FILE_TYPE); ftp.enterLocalPassiveMode(); ftp.storeFile(“foo.xml”, xmlInputStream); ftp.logout(); ftp.disconnect();

Additional topics… Sockets SOAP XML-RPC Binary encodings for XML

Additional resources

Summary Use XML for data exchange between heterogeneous applications. Sending and receiving XML is easy.