KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > soap > xfire > MuleHeadersOutHandler


1 /*
2  * $Id: MuleHeadersOutHandler.java 3937 2006-11-20 16:04:25Z lajos $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.providers.soap.xfire;
12
13 import org.codehaus.xfire.MessageContext;
14 import org.codehaus.xfire.handler.AbstractHandler;
15 import org.jdom.Element;
16 import org.jdom.Namespace;
17 import org.mule.config.MuleProperties;
18 import org.mule.providers.soap.MuleSoapHeaders;
19 import org.mule.umo.UMOEvent;
20
21 /**
22  * Writes the Mule Soap Header to the outgoing request.
23  */

24 public class MuleHeadersOutHandler extends AbstractHandler
25 {
26     /**
27      * Invoke a handler. If a fault occurs it will be handled via the
28      * <code>handleFault</code> method.
29      *
30      * @param context The message context.
31      */

32     public void invoke(MessageContext context) throws Exception JavaDoc
33     {
34         UMOEvent event = (UMOEvent)context.getProperty(MuleProperties.MULE_EVENT_PROPERTY);
35
36         if (event == null && context.getClient() != null)
37         {
38             event = (UMOEvent)context.getClient().getProperty(MuleProperties.MULE_EVENT_PROPERTY);
39         }
40
41         if (event != null)
42         {
43             MuleSoapHeaders muleHeaders = new MuleSoapHeaders(event);
44             Element header = context.getOutMessage().getHeader();
45
46             if (header == null)
47             {
48                 header = new Element("Header", context.getOutMessage().getSoapVersion().getPrefix(),
49                     context.getOutMessage().getSoapVersion().getNamespace());
50             }
51
52             // we can also add some extra properties like
53
// Enconding Property, Session Property
54

55             Element muleHeader = null;
56             Namespace ns = Namespace.getNamespace(MuleSoapHeaders.MULE_NAMESPACE,
57                 MuleSoapHeaders.MULE_10_ACTOR);
58             if (muleHeaders.getCorrelationId() != null || muleHeaders.getReplyTo() != null)
59             {
60                 muleHeader = new Element(MuleSoapHeaders.MULE_HEADER, ns);
61             }
62             else
63             {
64                 return;
65             }
66
67             Element e = null;
68             if (muleHeaders.getCorrelationId() != null)
69             {
70
71                 e = new Element(MuleProperties.MULE_CORRELATION_ID_PROPERTY, ns);
72                 e.setText(muleHeaders.getCorrelationId());
73                 muleHeader.addContent(e);
74
75                 e = new Element(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY, ns);
76                 e.setText(muleHeaders.getCorrelationGroup());
77                 muleHeader.addContent(e);
78
79                 e = new Element(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY, ns);
80                 e.setText(muleHeaders.getCorrelationSequence());
81                 muleHeader.addContent(e);
82
83             }
84             if (muleHeaders.getReplyTo() != null)
85             {
86
87                 e = new Element(MuleProperties.MULE_REPLY_TO_PROPERTY, ns);
88                 e.setText(muleHeaders.getReplyTo());
89                 muleHeader.addContent(e);
90             }
91             header.addContent(muleHeader);
92
93             context.getOutMessage().setHeader(header);
94         }
95     }
96 }
97
Popular Tags