Slide 1 EE557: Server-Side Development eXtensible Stylesheet Language (XSL) XSL is the language that describes how XML documents are displayed XSL developed.

  • Published on

  • View

  • Download


EE557: Server-Side DevelopmenteXtensible Stylesheet Language (XSL) XSL is the language that describes how XML documents are displayed XSL developed by the W3C Working Group Consists of three parts - XSLT (XSL Transformations)- XSL Formatting Objects (XSL-FO)- XPath XSLT is the language that specifies the conversion of a document from one format to another, where the XSL stylesheet defines the means -> typically used for for textual transformations, such as HTML or WML from XML XSL-FO formatting objects used when converting XML into binary formats such as PDF files, or Word Documents. This part is not covered by JAXP or here XPath allows you to specify the part of the structure you are talking about It allows you to distinguish between and -> We can describe different transformations for different elements EE557: Server-Side Development DavidMolloy John Peter Smith Jane Grogan xslexample1.xmlEE557: Server-Side Developmentxslexample1.xsl stylesheet is the top level element -> root of the XSL stylesheet tree associates the template with the root of the doc works like a for loop selects the value of the tag within the root elementEmployee Firstname: Lastname: EE557: Server-Side DevelopmentClient-Side/Server-Side TransformationsEE557: Server-Side DevelopmentClient-Side/Server-Side Internet Explorer 5.0+ goes a long way towards implementing client side transformations of XML Non standards compliant in many ways with some omissions/changes Perform a client transformation example Many advantages in performing a manual transformation on the server - works across multiple browsers (HTML) - lightweight clients - transformations are performed in advance quicker java classpath .;xalan.jar org.apache.xalan.xslt.Process IN xslexample1.xml XSL xslexample1.xsl -OUT xslexample1.html Work through second example in the notes xslcustomers.xml/.xslEE557: Server-Side DevelopmentXSLT and JAXP Often need to perform transformation real-time with dynamic data Eg. XML to browser-specific HTML XML to Wireless Markup Language (WML) for mobile phones Personalized webpages/documentation JAXP contains four packages responsible for handling XSLT - javax.xml.transform- javax.xml.transform.dom- javax.xml.transform.sax- javax.xml.transform.streamEE557: Server-Side DevelopmentXSLT and JAXP Steps: 1) Import javax.xml.transform package classes and other classes such as DOM packages if you use DOM 2) Instantiate a TransformerFactory objectTransformerFactory tFactory = TransformerFactory.newInstance() 3) Create a Transformer, in which we can define a set of transformation instructions. In our example, we supply an XSL StreamSource 4) Perform the transformation on the input (which can be created from a SAX reader, a DOM or an input stream) in our example, we provide a DOMSource. The transform method takes a second argument, which in our example is a File (via a FileWriter) 5) Handle the possible exceptions Work through the example in the notesMessaging with Java Most common form of message is eMail This is person-to-person or server-to-person messaging, not application to application messaging Email is made up of a Header and Content Each header attribute has its own line, with attributes split by a : Eg.Precedence: bulkFrom: David Molloy Show full email message from the notesEE557: Server-Side DevelopmentMessaging with Java Email messages are stored or sent using one of a number of different protocols- Simple Mail Transfer Protocol (SMTP)- Post Office Protocol (POP3)- Internet Message Access Protocol (IMAP4) IMAP4 typically considered more advanced than POP3, since it supports folders and status flags (among other features)EE557: Server-Side DevelopmentJavaMail API J2EE developer does not need to understand underlying protocols JavaMail API includes providers for the most commonly used protocols JavaMail sits on top of the electronic mail vendors systems Provides a standard, independent framework for Java client applications to use electronic mail Can use JavaMail to: - Compose messages (including multi-part messages with attachments) - Send messages to particular servers - Retrieve and store messages in folders When using JavaMail, the application needs network access to a mail service that can send messages to the destination (dialup or network service)EE557: Server-Side DevelopmentJavaMail API JavaMail is contructed with an Open Architecture, so can support future protocols and standards Two different types of protocols providers can implement: - Transport: is the service which sends messages to the destination Most commonly used transport is SMTP - Store: the service that provides access to messages that have been delivered to a mailboc. Most commonly used is POP3 but IMAP4 is considered better and becoming more common JavaMail relies heavily on the Java Activation Framework (JAF). JAF designed to work in a standard way with different types of data When an application needs to work with a particular data type, these JAF objects can be activated and used to process data (mail.jar, activation.jar, J2EE standard inclusion)EE557: Server-Side DevelopmentJavaMail API javax.mail.Session class is starting point for JavaMail. Allows the specification of properties, such as the transport mechanism and the mail server Using the Session we can create a new MimeMessageObject We then set the properties for the email message, such as the sender, recipient, subject and contents of the message Finally, we use Transport.send(message) to open up a new connection to the mail service and send the message Show the example code -> issues with running application (local access only etc.) - demoMail.javaEE557: Server-Side DevelopmentJava Message Service (JMS) JavaMail is an API for Messaging using email Java Message Service (JMS) is an API for Messaging between applications Developed by Sun Microsystems as part of the Java 2 Enterprise Ed. Provides a common way for Java programmers to create, send, receive and read an enterprise messaging systems messages A message is a unit of data that is sent from a process running on one computer to other processes running on the same computer or a different computer Messages can be simple text, or more complicated structures such as Java Hashtables or other serializable Java objects Object is serializable if it can be transmitted across a network as a series of bytes and re-created into a copy of the original objectEE557: Server-Side Development MOM is a specialized type of middleware that coordinates the sending and receiving of messages Provides dependable mechanisms that enable applications to create, send, and receive messages asynchronously in an enterprise environ. Numerous examples of MOM:- IBM MQ Series- Fiorano Message Server- Progress SonicMQ- SilverStream JbrokerMQ-> JMS provides a standard interface to these MOM products Frees developers from having to write low level infrastructure code, also known as plumbing, allowing them to build solutions quicker JMS is used and integrates with other components of J2EE (eg. JDBC used for persisting messages, JMS used in MDBs)EE557: Server-Side DevelopmentJava Message Service (JMS) Two primary communication modes:EE557: Server-Side DevelopmentJava Message Service (JMS)Synchronous Communication: conducted between two parties, both parties must be active and must acknowledge receipt of a message (known as a blocking call) before proceeding- easily affected by hardware, software and network failures, resulting in delayed messages and traffic backups- if hardware capacities are exceeded information is typically lost- Example: chat applicationAsynchronous Communication: all parties are peers and can send messages at will. Does not require real-time acknowledgement of messages. Requester can continue with other processing once it sends the message (known as a non-blocking call)- Example: Email. Even though your e-mail client may not be running on your PC, people can still send multiple messages to you. - Example: internet-based purchase ring tone system -> return feedback to browser, mobile phone turned off/no signal? Using messaging for exchanging data provides for:EE557: Server-Side DevelopmentJava Message Service (JMS) Easy integration of incompatible systems Asynchronous communications One-to-many communications Guaranteed messaging Transactional messaging (all or none, commit/abort) JMS supports two message models known as Point-to-Point (PTP) and Publish/Subscribe (Pub/Sub) Both models can deliver messages synchronously or asynchronously Sends messages to a receiver on a one-to-one basis, such as in instant messaging, or sending an order to another system Message delivered to a queue -> processed on FIFO basis Only one receiver can process each message (regardless of number of receivers) Receiver can look through messages in a Queue (eg. To count them) but must process them FIFOEE557: Server-Side DevelopmentPoint-to-Point Model (PTP)Publish/Subscribe Model Applications can publish messages on a one-to-many or many-to-many basis. Eg. Sending news stories to interested parties, stock prices to traders Messages are published to a Topic -> one or more publishers can publish messages to a Topic -> clients must subscribe to receive messages -> typically must be subscribed in advance If no clients subscribed, messages are typically destroyedEE557: Server-Side DevelopmentJMS API Programming Model Firstly, we set up a QueueConnectionFactory or a TopicConnectionFactory for use in our JMS applications We achieve this by using the Sun Application Server Admin Console (or whatever console is appropriate for the application server we are using). The steps to add the ConnectionFactory are detailed in the notes At beginning of JMS application, we perform a JNDI API lookup of the connection factory. Eg.Context ctx = new InitialContext();QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) ctx.lookup(myQueueConnectionFactory);EE557: Server-Side Development We also need to define a destination, which will be either a Queue or a Topic. It defines the target of messages it produces and the source of messages it consumes Again we create this resource using the Admin Console In our Java application we perform a JNDI lookup for our destination:Queue myQueue = (Queue) ctx.lookup(MyQueue);Topic myTopic = (Topic) ctx.lookup(MyTopic); Obtain a QueueConnection/TopicConnection to the provider by using the QueueConnectionFactory or TopicConnectionFactory Obtain a QueueSession/TopicSession with the provider by using the QueueConnection/TopicConnectionEE557: Server-Side DevelopmentJMS API Programming ModelJMS API Programming ModelEE557: Server-Side Development Create a QueueSender or QueueReceiver (TopicPublisher or TopicSubscriber) via the QueueSession (TopicSession) for the required Queue (Topic) Send and/or receive messages (Publish and/or subscribe messages) Close the QueueConnection (automatically closes QueueSender/Receiver, and the QueueSession). For Pub/Sub, close the TopicConnection, TopicPublisher/Subscriber and TopicSessionJMS API Programming ModelEE557: Server-Side DevelopmentJMS Messages Typically formatted data (such as a request, event or status) passed between applications. Message can contain simple or complex data types, including Serializable Java objects JMS message is made up of 1 required component and 2 optional: - A header (required) used for identifying and routing messages, setting expiration,priority etc. many settable by clients - Properties (optional) extra header information- A body (optional) one of 5 different formats ByteMessage,ObjectMessage,TextMessage,StreamMessage and MapMessage (hashtable type) message = queueSession.createTextMessage(); for (int i = 0; i < NUM_MSGS; i++) { message.setText("This is message " + (i + 1)); System.out.println("Sending message: " + message.getText()); } EE557: Server-Side DevelopmentPoint-to-Point Example SimpleQueueReceiver.javaEE557: Server-Side DevelopmentPublish/Subscribe Example


View more >