2
* Software License Agreement (BSD License)
4
* Copyright (c) 2008, Regents of the University of California
7
* Redistribution and use of this software in source and binary forms, with or
8
* without modification, are permitted provided that the following conditions
11
* * Redistributions of source code must retain the above
12
* copyright notice, this list of conditions and the
13
* following disclaimer.
15
* * Redistributions in binary form must reproduce the above
16
* copyright notice, this list of conditions and the
17
* following disclaimer in the documentation and/or other
18
* materials provided with the distribution.
20
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
* POSSIBILITY OF SUCH DAMAGE.
32
* Author: Chris Grzegorczyk grze@cs.ucsb.edu
35
package edu.ucsb.eucalyptus.transport;
37
import edu.ucsb.eucalyptus.cloud.EucalyptusCloudException;
38
import edu.ucsb.eucalyptus.msgs.*;
39
import edu.ucsb.eucalyptus.transport.binding.BindingManager;
40
import edu.ucsb.eucalyptus.transport.client.BasicClient;
41
import edu.ucsb.eucalyptus.transport.config.*;
42
import edu.ucsb.eucalyptus.util.BindingUtil;
43
import org.apache.axis2.AxisFault;
44
import org.apache.axis2.context.ConfigurationContext;
45
import org.apache.log4j.Logger;
46
import org.jibx.runtime.JiBXException;
47
import org.mule.DefaultMuleMessage;
48
import org.mule.api.*;
49
import org.mule.api.endpoint.OutboundEndpoint;
50
import org.mule.api.transformer.TransformerException;
51
import org.mule.message.ExceptionMessage;
52
import org.mule.transport.AbstractMessageDispatcher;
55
public class Axis2MessageDispatcher extends AbstractMessageDispatcher {
57
private static Logger LOG = Logger.getLogger( Axis2MessageDispatcher.class );
58
private Axis2OutProperties properties;
59
private BasicClient client;
61
@SuppressWarnings("unchecked")
62
public Axis2MessageDispatcher( OutboundEndpoint endpoint ) throws AxisFault, JiBXException
65
if ( !endpoint.getProperties().containsKey( Key.WSSEC_POLICY.getKey() ) )
66
endpoint.getProperties().put( Key.WSSEC_POLICY.getKey(), ( ( Axis2Connector ) endpoint.getConnector() ).getDefaultWssecPolicy() );
67
ConfigurationContext ctx = (( Axis2Connector) endpoint.getConnector() ).getAxisConfig();
68
Mep wssecFlow = Mep.valueOf( (String) endpoint.getProperty( Key.WSSEC_FLOW.getKey() ) );
69
if( Mep.IN_ONLY.equals( wssecFlow ) ) endpoint.getProperties().put( Key.WSSEC_FLOW.getKey(), Mep.OUT_ONLY.name() );
70
this.properties = new Axis2OutProperties( endpoint.getProperties(), ctx );
71
System.out.println( "" );
74
public void sendAsync( Object msg ) throws EucalyptusCloudException
78
this.client.dispatch( (EucalyptusMessage) msg );
83
throw new EucalyptusCloudException( "Error dispatching the message", e );
87
public void doDispatch( MuleEvent event ) throws EucalyptusCloudException
89
Object msg = getMessage( event );
90
this.sendAsync( msg );
93
public MuleMessage doSend( MuleEvent event ) throws EucalyptusCloudException
98
msg = event.transformMessage();
99
if ( msg instanceof ExceptionMessage )
100
msg = checkException( msg );
102
catch ( TransformerException e )
105
throw new EucalyptusCloudException( "Error handling message preparation for dispatch", e );
107
Object msgResponse = sendSync( msg );
108
return new DefaultMuleMessage( msgResponse );
111
public Object sendSync( Object msg ) throws EucalyptusCloudException
113
Object msgResponse = null;
116
msgResponse = this.client.send( ( EucalyptusMessage ) msg );
118
catch ( Exception e )
121
throw new EucalyptusCloudException( "Error dispatching the message", e );
126
private Object checkException( Object msg )
128
ExceptionMessage em = ( ExceptionMessage ) msg;
131
String eucaMsgString = em.getPayloadAsString( "UTF-8" );
133
EucalyptusMessage sourceMessage = ( EucalyptusMessage ) BindingManager.getBinding( BindingUtil.sanitizeNamespace( "http://msgs.eucalyptus.ucsb.edu/" ) ).fromOM( eucaMsgString );
135
Throwable exception = em.getException().getCause();
136
EucalyptusCloudException myEx = null;
137
if ( exception instanceof EucalyptusCloudException )
138
myEx = ( EucalyptusCloudException ) exception;
140
myEx = new EucalyptusCloudException( exception.getMessage(), exception);
141
msg = new EucalyptusErrorMessageType( em.getEndpoint().getAddress(), sourceMessage, myEx.getMessage() );
143
catch ( Exception e )
150
private Object getMessage( final MuleEvent event ) throws EucalyptusCloudException
155
msg = event.transformMessage();
156
if ( msg instanceof ExceptionMessage )
157
msg = checkException( msg );
159
catch ( TransformerException e )
162
throw new EucalyptusCloudException( "Error handling message preparation for dispatch", e );
167
public BasicClient getClient()
172
public void setClient( final BasicClient client )
174
this.client = client;
177
public Axis2OutProperties getProperties()
182
public void doConnect() throws Exception
187
public void doDisconnect() throws Exception
192
protected void doDispose() {}