<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FJ2EE%2FJMS_SOAP</id>
		<title>Java/J2EE/JMS SOAP - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FJ2EE%2FJMS_SOAP"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/J2EE/JMS_SOAP&amp;action=history"/>
		<updated>2026-04-22T00:57:06Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/J2EE/JMS_SOAP&amp;diff=7689&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/J2EE/JMS_SOAP&amp;diff=7689&amp;oldid=prev"/>
				<updated>2010-06-01T06:50:01Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 06:50, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/J2EE/JMS_SOAP&amp;diff=7688&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/J2EE/JMS_SOAP&amp;diff=7688&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:45Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== A JMS message listener can use the MessageTransformer utility to convert JMS messages back to SOAP messages ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * @(#)ReceiveSOAPMessageWithJMS.java  1.4 02/05/02&lt;br /&gt;
 *&lt;br /&gt;
 * Copyright (c) 2002 Sun Microsystems, Inc. All Rights Reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Sun grants you (&amp;quot;Licensee&amp;quot;) a non-exclusive, royalty free, license to use,&lt;br /&gt;
 * modify and redistribute this software in source and binary code form,&lt;br /&gt;
 * provided that i) this copyright notice and license appear on all copies of&lt;br /&gt;
 * the software; and ii) Licensee does not utilize the software in a manner&lt;br /&gt;
 * which is disparaging to Sun.&lt;br /&gt;
 *&lt;br /&gt;
 * This software is provided &amp;quot;AS IS,&amp;quot; without a warranty of any kind. ALL&lt;br /&gt;
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY&lt;br /&gt;
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR&lt;br /&gt;
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE&lt;br /&gt;
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING&lt;br /&gt;
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS&lt;br /&gt;
 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,&lt;br /&gt;
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER&lt;br /&gt;
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF&lt;br /&gt;
 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE&lt;br /&gt;
 * POSSIBILITY OF SUCH DAMAGES.&lt;br /&gt;
 *&lt;br /&gt;
 * This software is not designed or intended for use in on-line control of&lt;br /&gt;
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in&lt;br /&gt;
 * the design, construction, operation or maintenance of any nuclear&lt;br /&gt;
 * facility. Licensee represents and warrants that it will not use or&lt;br /&gt;
 * redistribute the Software for such purposes.&lt;br /&gt;
 */&lt;br /&gt;
import javax.xml.soap.MessageFactory;&lt;br /&gt;
import javax.xml.soap.SOAPMessage;&lt;br /&gt;
import javax.xml.soap.AttachmentPart;&lt;br /&gt;
import com.sun.messaging.xml.MessageTransformer;&lt;br /&gt;
import com.sun.messaging.ConnectionFactory;&lt;br /&gt;
import javax.jms.MessageListener;&lt;br /&gt;
import javax.jms.Connection;&lt;br /&gt;
import javax.jms.Session;&lt;br /&gt;
import javax.jms.Message;&lt;br /&gt;
import javax.jms.Session;&lt;br /&gt;
import javax.jms.Topic;&lt;br /&gt;
import javax.jms.JMSException;&lt;br /&gt;
import javax.jms.MessageConsumer;&lt;br /&gt;
import java.util.Iterator;&lt;br /&gt;
/**&lt;br /&gt;
 * This example shows a JMS message listener can use the MessageTransformer&lt;br /&gt;
 * utility to convert JMS messages back to SOAP messages.&lt;br /&gt;
 */&lt;br /&gt;
public class ReceiveSOAPMessageWithJMS implements MessageListener {&lt;br /&gt;
    ConnectionFactory        connectionFactory = null;&lt;br /&gt;
    Connection               connection = null;&lt;br /&gt;
    Session                  session = null;&lt;br /&gt;
    Topic                    topic = null;&lt;br /&gt;
    MessageConsumer          msgConsumer = null;&lt;br /&gt;
    MessageFactory           messageFactory = null;&lt;br /&gt;
    /**&lt;br /&gt;
     * Default constructor.&lt;br /&gt;
     */&lt;br /&gt;
    public ReceiveSOAPMessageWithJMS(String topicName) {&lt;br /&gt;
        init(topicName);&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * JMS Connection/Session/Destination/MessageListener set ups.&lt;br /&gt;
     */&lt;br /&gt;
    public void init(String topicName) {&lt;br /&gt;
        try {&lt;br /&gt;
            /**&lt;br /&gt;
             * construct a default SOAP message factory.&lt;br /&gt;
             */&lt;br /&gt;
            messageFactory = MessageFactory.newInstance();&lt;br /&gt;
            /**&lt;br /&gt;
             * JMS set up.&lt;br /&gt;
             */&lt;br /&gt;
            connectionFactory = new com.sun.messaging.ConnectionFactory();&lt;br /&gt;
            connection = connectionFactory.createConnection();&lt;br /&gt;
            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);&lt;br /&gt;
            topic = session.createTopic(topicName);&lt;br /&gt;
            msgConsumer = session.createConsumer(topic);&lt;br /&gt;
            msgConsumer.setMessageListener( this );&lt;br /&gt;
            connection.start();&lt;br /&gt;
            System.out.println (&amp;quot;ready to receive SOAP messages ...&amp;quot;);&lt;br /&gt;
        } catch (Exception jmse) {&lt;br /&gt;
            jmse.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * JMS Messages are delivered to this method. The body of the message&lt;br /&gt;
     * contains SOAP streams.&lt;br /&gt;
     *&lt;br /&gt;
     * 1.  The message conversion utility converts JMS message to SOAP&lt;br /&gt;
     * message type.&lt;br /&gt;
     * 2.  Get the attachment parts and print content information to the&lt;br /&gt;
     * standard output stream.&lt;br /&gt;
     */&lt;br /&gt;
    public void onMessage (Message message) {&lt;br /&gt;
        try {&lt;br /&gt;
            /**&lt;br /&gt;
             * convert JMS to SOAP message.&lt;br /&gt;
             */&lt;br /&gt;
            SOAPMessage soapMessage =&lt;br /&gt;
            MessageTransformer.SOAPMessageFromJMSMessage( message, messageFactory );&lt;br /&gt;
            /**&lt;br /&gt;
             * Print attachment counts.&lt;br /&gt;
             */&lt;br /&gt;
            System.out.println(&amp;quot;message received!  Attachment counts: &amp;quot; + soapMessage.countAttachments());&lt;br /&gt;
            /**&lt;br /&gt;
             * Get attachment parts of the SOAP message.&lt;br /&gt;
             */&lt;br /&gt;
            Iterator iterator = soapMessage.getAttachments();&lt;br /&gt;
            while ( iterator.hasNext() ) {&lt;br /&gt;
                /**&lt;br /&gt;
                 * Get next attachment.&lt;br /&gt;
                 */&lt;br /&gt;
                AttachmentPart ap = (AttachmentPart) iterator.next();&lt;br /&gt;
                /**&lt;br /&gt;
                 * Get content type.&lt;br /&gt;
                 */&lt;br /&gt;
                String contentType = ap.getContentType();&lt;br /&gt;
                System.out.println(&amp;quot;content type: &amp;quot; + contentType);&lt;br /&gt;
                /**&lt;br /&gt;
                 * Get content Id.&lt;br /&gt;
                 */&lt;br /&gt;
                String contentId = ap.getContentId();&lt;br /&gt;
                System.out.println(&amp;quot;content Id: &amp;quot; + contentId);&lt;br /&gt;
                /**&lt;br /&gt;
                 * Check if this is a Text attachment.&lt;br /&gt;
                 */&lt;br /&gt;
                if ( contentType.indexOf(&amp;quot;text&amp;quot;) &amp;gt;=0 ) {&lt;br /&gt;
                    /**&lt;br /&gt;
                     * Get and print the string content if it is a text&lt;br /&gt;
                     * attachment.&lt;br /&gt;
                     */&lt;br /&gt;
                    String content = (String) ap.getContent();&lt;br /&gt;
                    System.out.println(&amp;quot;*** attachment content: &amp;quot; + content);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        } catch (Exception e) {&lt;br /&gt;
            e.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * The main method to start the example receiver.&lt;br /&gt;
     */&lt;br /&gt;
    public static void main (String[] args) {&lt;br /&gt;
        String topicName = &amp;quot;TestTopic&amp;quot;;&lt;br /&gt;
        if (args.length &amp;gt; 0) {&lt;br /&gt;
            topicName = args[0];&lt;br /&gt;
        }&lt;br /&gt;
        try {&lt;br /&gt;
            ReceiveSOAPMessageWithJMS rsm = new ReceiveSOAPMessageWithJMS(topicName);&lt;br /&gt;
        } catch (Exception e) {&lt;br /&gt;
            e.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
        &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to use the MessageTransformer utility to convert SOAP message to JMS message ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * @(#)SOAPtoJMSServlet.java  1.5 02/07/19&lt;br /&gt;
 *&lt;br /&gt;
 * Copyright (c) 2002 Sun Microsystems, Inc. All Rights Reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Sun grants you (&amp;quot;Licensee&amp;quot;) a non-exclusive, royalty free, license to use,&lt;br /&gt;
 * modify and redistribute this software in source and binary code form,&lt;br /&gt;
 * provided that i) this copyright notice and license appear on all copies of&lt;br /&gt;
 * the software; and ii) Licensee does not utilize the software in a manner&lt;br /&gt;
 * which is disparaging to Sun.&lt;br /&gt;
 *&lt;br /&gt;
 * This software is provided &amp;quot;AS IS,&amp;quot; without a warranty of any kind. ALL&lt;br /&gt;
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY&lt;br /&gt;
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR&lt;br /&gt;
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE&lt;br /&gt;
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING&lt;br /&gt;
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS&lt;br /&gt;
 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,&lt;br /&gt;
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER&lt;br /&gt;
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF&lt;br /&gt;
 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE&lt;br /&gt;
 * POSSIBILITY OF SUCH DAMAGES.&lt;br /&gt;
 *&lt;br /&gt;
 * This software is not designed or intended for use in on-line control of&lt;br /&gt;
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in&lt;br /&gt;
 * the design, construction, operation or maintenance of any nuclear&lt;br /&gt;
 * facility. Licensee represents and warrants that it will not use or&lt;br /&gt;
 * redistribute the Software for such purposes.&lt;br /&gt;
 */&lt;br /&gt;
import javax.xml.messaging.JAXMServlet;&lt;br /&gt;
import javax.xml.messaging.ReqRespListener;&lt;br /&gt;
import javax.xml.soap.SOAPMessage;&lt;br /&gt;
import javax.xml.soap.SOAPBody;&lt;br /&gt;
import javax.xml.soap.SOAPEnvelope;&lt;br /&gt;
import javax.xml.soap.SOAPException;&lt;br /&gt;
import javax.xml.soap.SOAPPart;&lt;br /&gt;
import com.sun.messaging.xml.MessageTransformer;&lt;br /&gt;
import com.sun.messaging.TopicConnectionFactory;&lt;br /&gt;
import javax.jms.MessageListener;&lt;br /&gt;
import javax.jms.TopicConnection;&lt;br /&gt;
import javax.jms.TopicSession;&lt;br /&gt;
import javax.jms.Session;&lt;br /&gt;
import javax.jms.Message;&lt;br /&gt;
import javax.jms.Topic;&lt;br /&gt;
import javax.jms.JMSException;&lt;br /&gt;
import javax.jms.TopicPublisher;&lt;br /&gt;
import javax.servlet.ServletConfig;&lt;br /&gt;
import javax.servlet.ServletException;&lt;br /&gt;
/**&lt;br /&gt;
 * This example shows how to use the MessageTransformer utility to convert SOAP&lt;br /&gt;
 * message to JMS message.  When SOAP messages are received, they are&lt;br /&gt;
 * delivered to the ReqRespListener&amp;quot;s onMessage() method.  The onMessage()&lt;br /&gt;
 * implementation uses the utility to convert SOAP to JMS message, then&lt;br /&gt;
 * publishes the message to the JMS Topic.&lt;br /&gt;
 * &amp;lt;p&amp;gt;&lt;br /&gt;
 * The onMessage() method adds &amp;lt;MessageStatus&amp;gt; element with value &amp;quot;published&amp;quot;&lt;br /&gt;
 * to the SOAPBody and returns the SOAP message to the caller.&lt;br /&gt;
 */&lt;br /&gt;
public class SOAPtoJMSServlet extends JAXMServlet implements ReqRespListener {&lt;br /&gt;
    TopicConnectionFactory tcf = null;&lt;br /&gt;
    TopicConnection tc = null;&lt;br /&gt;
    TopicSession session = null;&lt;br /&gt;
    Topic topic = null;&lt;br /&gt;
    TopicPublisher publisher = null;&lt;br /&gt;
    /**&lt;br /&gt;
     * The init method set up JMS Connection/Session/Publisher.&lt;br /&gt;
     */&lt;br /&gt;
    public void init(ServletConfig config) throws ServletException {&lt;br /&gt;
        super.init(config);&lt;br /&gt;
        try {&lt;br /&gt;
            tcf = new com.sun.messaging.TopicConnectionFactory();&lt;br /&gt;
            tc = tcf.createTopicConnection();&lt;br /&gt;
            session = tc.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);&lt;br /&gt;
            String topicName = config.getInitParameter(&amp;quot;TopicName&amp;quot;);&lt;br /&gt;
            if ( topicName == null ) {&lt;br /&gt;
                topicName = &amp;quot;TestTopic&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
            topic = session.createTopic(topicName);&lt;br /&gt;
            publisher = session.createPublisher(topic);&lt;br /&gt;
        } catch (Exception jmse) {&lt;br /&gt;
            throw new ServletException (jmse);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Clean up JMS connection.&lt;br /&gt;
     */&lt;br /&gt;
    public void destroy() {&lt;br /&gt;
        try {&lt;br /&gt;
            if ( tc != null ) {&lt;br /&gt;
                tc.close();&lt;br /&gt;
            }&lt;br /&gt;
        } catch (Exception e) {&lt;br /&gt;
            e.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * SOAP Messages are delivered to this method and then published to the&lt;br /&gt;
     * JMS topic destination.&lt;br /&gt;
     */&lt;br /&gt;
    public SOAPMessage onMessage (SOAPMessage soapMessage) {&lt;br /&gt;
        try {&lt;br /&gt;
            Message message =&lt;br /&gt;
            MessageTransformer.SOAPMessageIntoJMSMessage(soapMessage, session);&lt;br /&gt;
            publisher.publish( message );&lt;br /&gt;
        } catch (Exception e) {&lt;br /&gt;
            e.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
        SOAPMessage resp = generateResponseMessage(soapMessage);&lt;br /&gt;
        return resp;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Add a MessageStatus element with the value of &amp;quot;published&amp;quot; to&lt;br /&gt;
     * the soapMessage.&lt;br /&gt;
     */&lt;br /&gt;
    public SOAPMessage generateResponseMessage(SOAPMessage soapMessage) {&lt;br /&gt;
        try {&lt;br /&gt;
            SOAPPart soapPart = soapMessage.getSOAPPart();&lt;br /&gt;
            SOAPEnvelope envelope = soapPart.getEnvelope();&lt;br /&gt;
            SOAPBody soapBody = envelope.getBody();&lt;br /&gt;
            soapBody.addChildElement(&amp;quot;MessageStatus&amp;quot;).addTextNode(&amp;quot;published&amp;quot;);&lt;br /&gt;
            soapMessage.saveChanges();&lt;br /&gt;
        } catch (SOAPException soape) {&lt;br /&gt;
            soape.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
        return soapMessage;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
        &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to use the MessageTransformer utility to send SOAP messages with JMS ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * @(#)SendSOAPMessageWithJMS.java  1.6 02/05/02&lt;br /&gt;
 *&lt;br /&gt;
 * Copyright (c) 2002 Sun Microsystems, Inc. All Rights Reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Sun grants you (&amp;quot;Licensee&amp;quot;) a non-exclusive, royalty free, license to use,&lt;br /&gt;
 * modify and redistribute this software in source and binary code form,&lt;br /&gt;
 * provided that i) this copyright notice and license appear on all copies of&lt;br /&gt;
 * the software; and ii) Licensee does not utilize the software in a manner&lt;br /&gt;
 * which is disparaging to Sun.&lt;br /&gt;
 *&lt;br /&gt;
 * This software is provided &amp;quot;AS IS,&amp;quot; without a warranty of any kind. ALL&lt;br /&gt;
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY&lt;br /&gt;
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR&lt;br /&gt;
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE&lt;br /&gt;
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING&lt;br /&gt;
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS&lt;br /&gt;
 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,&lt;br /&gt;
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER&lt;br /&gt;
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF&lt;br /&gt;
 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE&lt;br /&gt;
 * POSSIBILITY OF SUCH DAMAGES.&lt;br /&gt;
 *&lt;br /&gt;
 * This software is not designed or intended for use in on-line control of&lt;br /&gt;
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in&lt;br /&gt;
 * the design, construction, operation or maintenance of any nuclear&lt;br /&gt;
 * facility. Licensee represents and warrants that it will not use or&lt;br /&gt;
 * redistribute the Software for such purposes.&lt;br /&gt;
 */&lt;br /&gt;
import javax.xml.soap.SOAPMessage;&lt;br /&gt;
import javax.xml.soap.SOAPPart;&lt;br /&gt;
import javax.xml.soap.SOAPEnvelope;&lt;br /&gt;
import javax.xml.soap.SOAPBody;&lt;br /&gt;
import javax.xml.soap.SOAPElement;&lt;br /&gt;
import javax.xml.soap.MessageFactory;&lt;br /&gt;
import javax.xml.soap.AttachmentPart;&lt;br /&gt;
import javax.xml.soap.Name;&lt;br /&gt;
import java.net.URL;&lt;br /&gt;
import javax.activation.DataHandler;&lt;br /&gt;
import com.sun.messaging.xml.MessageTransformer;&lt;br /&gt;
import javax.jms.ConnectionFactory;&lt;br /&gt;
import javax.jms.Connection;&lt;br /&gt;
import javax.jms.JMSException;&lt;br /&gt;
import javax.jms.Session;&lt;br /&gt;
import javax.jms.Message;&lt;br /&gt;
import javax.jms.Session;&lt;br /&gt;
import javax.jms.Topic;&lt;br /&gt;
import javax.jms.MessageProducer;&lt;br /&gt;
/**&lt;br /&gt;
 * This example shows how to use the MessageTransformer utility to send SOAP&lt;br /&gt;
 * messages with JMS.&lt;br /&gt;
 * &amp;lt;p&amp;gt;&lt;br /&gt;
 * SOAP messages are constructed with javax.xml.soap API.  The messages&lt;br /&gt;
 * are converted with MessageTransformer utility to convert SOAP to JMS&lt;br /&gt;
 * message types.  The JMS messages are then published to the JMS topics.&lt;br /&gt;
 */&lt;br /&gt;
public class SendSOAPMessageWithJMS {&lt;br /&gt;
    ConnectionFactory        connectionFactory = null;&lt;br /&gt;
    Connection               connection = null;&lt;br /&gt;
    Session                  session = null;&lt;br /&gt;
    Topic                    topic = null;&lt;br /&gt;
    MessageProducer          msgProducer = null;&lt;br /&gt;
    /**&lt;br /&gt;
     * default constructor.&lt;br /&gt;
     */&lt;br /&gt;
    public SendSOAPMessageWithJMS(String topicName) {&lt;br /&gt;
        init(topicName);&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Initialize JMS Connection/Session/Topic and Producer.&lt;br /&gt;
     */&lt;br /&gt;
    public void init(String topicName) {&lt;br /&gt;
        try {&lt;br /&gt;
            connectionFactory = new com.sun.messaging.ConnectionFactory();&lt;br /&gt;
            connection = connectionFactory.createConnection();&lt;br /&gt;
            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);&lt;br /&gt;
            topic = session.createTopic(topicName);&lt;br /&gt;
            msgProducer = session.createProducer(topic);&lt;br /&gt;
        } catch (JMSException jmse) {&lt;br /&gt;
            jmse.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Send SOAP message with JMS API.&lt;br /&gt;
     */&lt;br /&gt;
    public void send () throws Exception {&lt;br /&gt;
        /**&lt;br /&gt;
         * Construct a default SOAP message factory.&lt;br /&gt;
         */&lt;br /&gt;
        MessageFactory mf = MessageFactory.newInstance();&lt;br /&gt;
        /**&lt;br /&gt;
         * Create a SOAP message object.&lt;br /&gt;
         */&lt;br /&gt;
        SOAPMessage soapMessage = mf.createMessage();&lt;br /&gt;
        /**&lt;br /&gt;
         * Get SOAP part.&lt;br /&gt;
         */&lt;br /&gt;
        SOAPPart soapPart = soapMessage.getSOAPPart();&lt;br /&gt;
        /**&lt;br /&gt;
         * Get SOAP envelope.&lt;br /&gt;
         */&lt;br /&gt;
        SOAPEnvelope soapEnvelope = soapPart.getEnvelope();&lt;br /&gt;
        /**&lt;br /&gt;
         * Get SOAP body.&lt;br /&gt;
         */&lt;br /&gt;
        SOAPBody soapBody = soapEnvelope.getBody();&lt;br /&gt;
        /**&lt;br /&gt;
         * Create a name object. with name space http://www.sun.ru/imq.&lt;br /&gt;
         */&lt;br /&gt;
        Name name = soapEnvelope.createName(&amp;quot;HelloWorld&amp;quot;, &amp;quot;hw&amp;quot;, &amp;quot;http://www.sun.ru/imq&amp;quot;);&lt;br /&gt;
        /**&lt;br /&gt;
         * Add child element with the above name.&lt;br /&gt;
         */&lt;br /&gt;
        SOAPElement element = soapBody.addChildElement(name);&lt;br /&gt;
        /**&lt;br /&gt;
         * Add another child element.&lt;br /&gt;
         */&lt;br /&gt;
        element.addTextNode( &amp;quot;Welcome to SunOne Web Services.&amp;quot; );&lt;br /&gt;
        /**&lt;br /&gt;
         * Create an atachment with activation API.&lt;br /&gt;
         */&lt;br /&gt;
        URL url = new URL (&amp;quot;http://java.sun.ru/webservices/&amp;quot;);&lt;br /&gt;
        DataHandler dh = new DataHandler (url);&lt;br /&gt;
        AttachmentPart ap = soapMessage.createAttachmentPart(dh);&lt;br /&gt;
        /**&lt;br /&gt;
         * set content type/ID.&lt;br /&gt;
         */&lt;br /&gt;
        ap.setContentType(&amp;quot;text/html&amp;quot;);&lt;br /&gt;
        ap.setContentId(&amp;quot;cid-001&amp;quot;);&lt;br /&gt;
        /**&lt;br /&gt;
         *  add the attachment to the SOAP message.&lt;br /&gt;
         */&lt;br /&gt;
        soapMessage.addAttachmentPart(ap);&lt;br /&gt;
        soapMessage.saveChanges();&lt;br /&gt;
        /**&lt;br /&gt;
         * Convert SOAP to JMS message.&lt;br /&gt;
         */&lt;br /&gt;
        Message message = MessageTransformer.SOAPMessageIntoJMSMessage( soapMessage, session );&lt;br /&gt;
        /**&lt;br /&gt;
         * publish JMS message.&lt;br /&gt;
         */&lt;br /&gt;
        msgProducer.send( message );&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * close JMS connection.&lt;br /&gt;
     */&lt;br /&gt;
    public void close() throws JMSException {&lt;br /&gt;
        connection.close();&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * The main program to send SOAP messages with JMS.&lt;br /&gt;
     */&lt;br /&gt;
    public static void main (String[] args) {&lt;br /&gt;
        String topicName = &amp;quot;TestTopic&amp;quot;;&lt;br /&gt;
        if (args.length &amp;gt; 0) {&lt;br /&gt;
            topicName = args[0];&lt;br /&gt;
        }&lt;br /&gt;
        try {&lt;br /&gt;
            SendSOAPMessageWithJMS ssm = new SendSOAPMessageWithJMS(topicName);&lt;br /&gt;
            ssm.send();&lt;br /&gt;
            ssm.close();&lt;br /&gt;
        } catch (Exception e) {&lt;br /&gt;
            e.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
        &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== This example demonstrates a hello world example for using JAXM API ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * @(#)SendSOAPMessage.java  1.4 02/05/02&lt;br /&gt;
 *&lt;br /&gt;
 * Copyright (c) 2002 Sun Microsystems, Inc. All Rights Reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Sun grants you (&amp;quot;Licensee&amp;quot;) a non-exclusive, royalty free, license to use,&lt;br /&gt;
 * modify and redistribute this software in source and binary code form,&lt;br /&gt;
 * provided that i) this copyright notice and license appear on all copies of&lt;br /&gt;
 * the software; and ii) Licensee does not utilize the software in a manner&lt;br /&gt;
 * which is disparaging to Sun.&lt;br /&gt;
 *&lt;br /&gt;
 * This software is provided &amp;quot;AS IS,&amp;quot; without a warranty of any kind. ALL&lt;br /&gt;
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY&lt;br /&gt;
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR&lt;br /&gt;
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE&lt;br /&gt;
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING&lt;br /&gt;
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS&lt;br /&gt;
 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,&lt;br /&gt;
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER&lt;br /&gt;
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF&lt;br /&gt;
 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE&lt;br /&gt;
 * POSSIBILITY OF SUCH DAMAGES.&lt;br /&gt;
 *&lt;br /&gt;
 * This software is not designed or intended for use in on-line control of&lt;br /&gt;
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in&lt;br /&gt;
 * the design, construction, operation or maintenance of any nuclear&lt;br /&gt;
 * facility. Licensee represents and warrants that it will not use or&lt;br /&gt;
 * redistribute the Software for such purposes.&lt;br /&gt;
 */&lt;br /&gt;
import javax.xml.messaging.URLEndpoint;&lt;br /&gt;
import javax.xml.soap.MessageFactory;&lt;br /&gt;
import javax.xml.soap.SOAPMessage;&lt;br /&gt;
import javax.xml.soap.SOAPEnvelope;&lt;br /&gt;
import javax.xml.soap.SOAPBody;&lt;br /&gt;
import javax.xml.soap.SOAPPart;&lt;br /&gt;
import javax.xml.soap.SOAPElement;&lt;br /&gt;
import javax.xml.soap.SOAPException;&lt;br /&gt;
import javax.xml.soap.SOAPConnectionFactory;&lt;br /&gt;
import javax.xml.soap.SOAPConnection;&lt;br /&gt;
/**&lt;br /&gt;
 * This example demonstrates a hello world example for using JAXM API.&lt;br /&gt;
 */&lt;br /&gt;
public class SendSOAPMessage {&lt;br /&gt;
    /**&lt;br /&gt;
     * send a simple soap message with JAXM API.&lt;br /&gt;
     */&lt;br /&gt;
    public void sendMessage (String url) {&lt;br /&gt;
        try {&lt;br /&gt;
            /**&lt;br /&gt;
             * Construct a default SOAP message factory.&lt;br /&gt;
             */&lt;br /&gt;
            MessageFactory mf = MessageFactory.newInstance();&lt;br /&gt;
            /**&lt;br /&gt;
             * Create a SOAP message object.&lt;br /&gt;
             */&lt;br /&gt;
            SOAPMessage soapMessage = mf.createMessage();&lt;br /&gt;
            /**&lt;br /&gt;
             * Get SOAP part.&lt;br /&gt;
             */&lt;br /&gt;
            SOAPPart soapPart = soapMessage.getSOAPPart();&lt;br /&gt;
            /**&lt;br /&gt;
             * Get SOAP envelope.&lt;br /&gt;
             */&lt;br /&gt;
            SOAPEnvelope soapEnvelope = soapPart.getEnvelope();&lt;br /&gt;
            /**&lt;br /&gt;
             * Get SOAP body.&lt;br /&gt;
             */&lt;br /&gt;
            SOAPBody soapBody = soapEnvelope.getBody();&lt;br /&gt;
            /**&lt;br /&gt;
             * Add child element with the specified name.&lt;br /&gt;
             */&lt;br /&gt;
            SOAPElement element = soapBody.addChildElement(&amp;quot;HelloWorld&amp;quot;);&lt;br /&gt;
            /**&lt;br /&gt;
             * Add text message&lt;br /&gt;
             */&lt;br /&gt;
            element.addTextNode(&amp;quot;Welcome to SunOne Web Services!&amp;quot;);&lt;br /&gt;
            soapMessage.saveChanges();&lt;br /&gt;
            /**&lt;br /&gt;
             * Construct a default SOAP connection factory.&lt;br /&gt;
             */&lt;br /&gt;
            SOAPConnectionFactory connectionFactory = SOAPConnectionFactory.newInstance();&lt;br /&gt;
            /**&lt;br /&gt;
             * Get SOAP connection.&lt;br /&gt;
             */&lt;br /&gt;
            SOAPConnection soapConnection = connectionFactory.createConnection();&lt;br /&gt;
            /**&lt;br /&gt;
             * Construct endpoint object.&lt;br /&gt;
             */&lt;br /&gt;
            URLEndpoint endpoint = new URLEndpoint (url);&lt;br /&gt;
            /**&lt;br /&gt;
             * Send SOAP message.&lt;br /&gt;
             */&lt;br /&gt;
            SOAPMessage resp = soapConnection.call(soapMessage, endpoint);&lt;br /&gt;
            /**&lt;br /&gt;
             * Print response to the std output.&lt;br /&gt;
             */&lt;br /&gt;
            resp.writeTo( System.out );&lt;br /&gt;
            /**&lt;br /&gt;
             * close the connection&lt;br /&gt;
             */&lt;br /&gt;
            soapConnection.close();&lt;br /&gt;
        } catch (java.io.IOException ioe) {&lt;br /&gt;
            ioe.printStackTrace();&lt;br /&gt;
        } catch (SOAPException soape) {&lt;br /&gt;
            soape.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public static void main (String args[]) {&lt;br /&gt;
        String url = &amp;quot;http://localhost:8080/imqSOAPexamples/SOAPEchoServlet&amp;quot;;&lt;br /&gt;
        if (args.length &amp;gt; 0) {&lt;br /&gt;
            url = args[0];&lt;br /&gt;
        } else {&lt;br /&gt;
            System.out.println(&amp;quot;Usage: &amp;quot; +&lt;br /&gt;
                &amp;quot;\tjava SendSOAPMessage &amp;lt;SOAP servlet url&amp;gt;\n&amp;quot; +&lt;br /&gt;
                &amp;quot;e.g.\n\tjava SendSOAPMessage http://localhost:8080/imqSOAPexamples/SOAPEchoServlet&amp;quot;&lt;br /&gt;
                );&lt;br /&gt;
            System.exit(1);&lt;br /&gt;
        }&lt;br /&gt;
        SendSOAPMessage ssm = new SendSOAPMessage();&lt;br /&gt;
        ssm.sendMessage(url);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
        &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== This example echos the SOAP message received back to the sender ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * @(#)SOAPEchoServlet.java  1.4 02/05/02&lt;br /&gt;
 *&lt;br /&gt;
 * Copyright (c) 2002 Sun Microsystems, Inc. All Rights Reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Sun grants you (&amp;quot;Licensee&amp;quot;) a non-exclusive, royalty free, license to use,&lt;br /&gt;
 * modify and redistribute this software in source and binary code form,&lt;br /&gt;
 * provided that i) this copyright notice and license appear on all copies of&lt;br /&gt;
 * the software; and ii) Licensee does not utilize the software in a manner&lt;br /&gt;
 * which is disparaging to Sun.&lt;br /&gt;
 *&lt;br /&gt;
 * This software is provided &amp;quot;AS IS,&amp;quot; without a warranty of any kind. ALL&lt;br /&gt;
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY&lt;br /&gt;
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR&lt;br /&gt;
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE&lt;br /&gt;
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING&lt;br /&gt;
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS&lt;br /&gt;
 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,&lt;br /&gt;
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER&lt;br /&gt;
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF&lt;br /&gt;
 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE&lt;br /&gt;
 * POSSIBILITY OF SUCH DAMAGES.&lt;br /&gt;
 *&lt;br /&gt;
 * This software is not designed or intended for use in on-line control of&lt;br /&gt;
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in&lt;br /&gt;
 * the design, construction, operation or maintenance of any nuclear&lt;br /&gt;
 * facility. Licensee represents and warrants that it will not use or&lt;br /&gt;
 * redistribute the Software for such purposes.&lt;br /&gt;
 */&lt;br /&gt;
import javax.xml.messaging.JAXMServlet;&lt;br /&gt;
import javax.xml.messaging.ReqRespListener;&lt;br /&gt;
import javax.xml.soap.SOAPMessage;&lt;br /&gt;
/**&lt;br /&gt;
 * This example echos the SOAP message received back to the sender.&lt;br /&gt;
 */&lt;br /&gt;
public class SOAPEchoServlet extends JAXMServlet implements ReqRespListener {&lt;br /&gt;
    /**&lt;br /&gt;
     * SOAP Message received is echoed back to the sender.&lt;br /&gt;
     */&lt;br /&gt;
    public SOAPMessage onMessage (SOAPMessage soapMessage) {&lt;br /&gt;
        return soapMessage;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
        &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>