~ubuntu-branches/ubuntu/raring/eucalyptus/raring

« back to all changes in this revision

Viewing changes to clc/modules/msgs/src/main/java/com/eucalyptus/http/MappingHttpMessage.java

  • Committer: Package Import Robot
  • Author(s): Brian Thomason
  • Date: 2011-11-29 13:17:52 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 185.
  • Revision ID: package-import@ubuntu.com-20111129131752-rq31al3ntutv2vvl
Tags: upstream-3.0.999beta1
Import upstream version 3.0.999beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
 * SOFTWARE, AND IF ANY SUCH MATERIAL IS DISCOVERED THE PARTY DISCOVERING
54
54
 * IT MAY INFORM DR. RICH WOLSKI AT THE UNIVERSITY OF CALIFORNIA, SANTA
55
55
 * BARBARA WHO WILL THEN ASCERTAIN THE MOST APPROPRIATE REMEDY, WHICH IN
56
 
 * THE REGENTS’ DISCRETION MAY INCLUDE, WITHOUT LIMITATION, REPLACEMENT
 
56
 * THE REGENTS' DISCRETION MAY INCLUDE, WITHOUT LIMITATION, REPLACEMENT
57
57
 * OF THE CODE SO IDENTIFIED, LICENSING OF THE CODE SO IDENTIFIED, OR
58
58
 * WITHDRAWAL OF THE CODE CAPABILITY TO THE EXTENT NEEDED TO COMPLY WITH
59
59
 * ANY SUCH LICENSES OR RIGHTS.
65
65
 
66
66
import org.apache.axiom.om.OMElement;
67
67
import org.apache.axiom.soap.SOAPEnvelope;
 
68
import org.apache.log4j.Logger;
 
69
import org.jboss.netty.channel.ChannelEvent;
 
70
import org.jboss.netty.channel.MessageEvent;
68
71
import org.jboss.netty.handler.codec.http.DefaultHttpMessage;
69
72
import org.jboss.netty.handler.codec.http.HttpMessage;
70
73
import org.jboss.netty.handler.codec.http.HttpVersion;
71
74
import com.eucalyptus.auth.principal.User;
 
75
import edu.ucsb.eucalyptus.msgs.BaseMessage;
72
76
 
73
77
public abstract class MappingHttpMessage extends DefaultHttpMessage implements HttpMessage {
 
78
  private static Logger LOG = Logger.getLogger( MappingHttpMessage.class );
74
79
  private String       correlationId;
75
80
  private String       messageString;
76
81
  private SOAPEnvelope soapEnvelope;
77
82
  private OMElement    omMessage;
78
 
  private Object       message;
 
83
  protected Object       message;
79
84
  private User         user;
80
85
  private Boolean      keepAlive = Boolean.TRUE;
81
86
  private final Long         timestamp = System.currentTimeMillis( );
105
110
  }
106
111
 
107
112
  public void setMessage( Object message ) {
 
113
    if( message instanceof BaseMessage ) {
 
114
      ((BaseMessage)message).setCorrelationId( this.getCorrelationId( ) );
 
115
    }
108
116
    this.message = message;
109
117
  }
110
118
 
144
152
    this.correlationId = correlationId;
145
153
  }
146
154
  
 
155
  public String logMessage( ) {
 
156
    StringBuffer buf = new StringBuffer();
 
157
    buf.append( "============================================\n" );
 
158
    buf.append( "HTTP" ).append( this.getProtocolVersion( ) ).append( '\n' );
 
159
    for( String s : this.getHeaderNames( ) ) {
 
160
      buf.append( s ).append( ": " ).append( this.getHeader( s ) ).append( '\n' );
 
161
    }
 
162
    buf.append( "============================================\n" );
 
163
    buf.append( this.getContent( ).toString( "UTF-8" ) ).append( '\n' );;
 
164
    buf.append( "============================================\n" );
 
165
    return buf.toString( );
 
166
  }
 
167
 
 
168
  /**
 
169
   * Get the message from within a ChannelEvent. Returns null if no message found.
 
170
   * 
 
171
   * @param <T>
 
172
   * @param e
 
173
   * @return message or null if no msg.
 
174
   */
 
175
  public static <T extends MappingHttpMessage> T extractMessage( ChannelEvent e ) {
 
176
    if ( e instanceof MessageEvent ) {
 
177
      final MessageEvent msge = ( MessageEvent ) e;
 
178
      if ( msge.getMessage( ) instanceof MappingHttpRequest ) {
 
179
        return ( T ) msge.getMessage( );
 
180
      } else if ( msge.getMessage( ) instanceof MappingHttpResponse ) {
 
181
          return ( T ) msge.getMessage( );
 
182
      } else {
 
183
        return null;
 
184
      }
 
185
    } else {
 
186
      return null;
 
187
    }
 
188
  }
147
189
}