KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: MuleInvoker.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 java.lang.reflect.Method JavaDoc;
14
15 import javax.xml.namespace.QName JavaDoc;
16
17 import org.codehaus.xfire.MessageContext;
18 import org.codehaus.xfire.fault.XFireFault;
19 import org.codehaus.xfire.service.invoker.Invoker;
20 import org.mule.config.MuleProperties;
21 import org.mule.impl.MuleMessage;
22 import org.mule.providers.AbstractMessageReceiver;
23 import org.mule.providers.NullPayload;
24 import org.mule.umo.UMOException;
25 import org.mule.umo.UMOMessage;
26 import org.mule.umo.endpoint.UMOImmutableEndpoint;
27
28 /**
29  * Invokes a Mule Service via an XFire binding.
30  */

31 public class MuleInvoker implements Invoker
32 {
33     private final AbstractMessageReceiver receiver;
34     private final boolean synchronous;
35
36     public MuleInvoker(AbstractMessageReceiver receiver, boolean synchronous)
37     {
38         this.receiver = receiver;
39         this.synchronous = synchronous;
40     }
41
42     public Object JavaDoc invoke(Method JavaDoc method, Object JavaDoc[] objects, MessageContext messageContext) throws XFireFault
43     {
44         UMOMessage message = null;
45         try
46         {
47             XFireMessageAdapter messageAdapter = (XFireMessageAdapter)receiver.getConnector()
48                 .getMessageAdapter(objects);
49             messageAdapter.setMessageContext(messageContext);
50             messageAdapter.setProperty(MuleProperties.MULE_METHOD_PROPERTY, method);
51
52             message = receiver.routeMessage(new MuleMessage(messageAdapter), synchronous);
53         }
54         catch (UMOException e)
55         {
56             throw new XFireFault(e);
57         }
58
59         if (message != null)
60         {
61             if (message.getExceptionPayload() != null)
62             {
63                 QName JavaDoc code = new QName JavaDoc(String.valueOf(message.getExceptionPayload().getCode()));
64                 throw new XFireFault(message.getExceptionPayload().getMessage(),
65                     message.getExceptionPayload().getException(), code);
66             }
67             else if (message.getPayload() instanceof NullPayload)
68             {
69                 return null;
70             }
71             else
72             {
73                 return message.getPayload();
74             }
75         }
76         else
77         {
78             return null;
79         }
80     }
81
82     public UMOImmutableEndpoint getEndpoint()
83     {
84         return receiver.getEndpoint();
85     }
86 }
87
Popular Tags