Skip to content
Browse files

refactored some soap fault stuff for walrus

  • Loading branch information...
1 parent 7a804ec commit 2cafd0ed7da2fd8278d247e37abc3ef2f089b523 Neil committed Aug 17, 2009
View
173 clc/modules/core/src/main/java/com/eucalyptus/util/WalrusUtil.java
@@ -0,0 +1,173 @@
+/*
+ * Software License Agreement (BSD License)
+ *
+ * Copyright (c) 2008, Regents of the University of California
+ * All rights reserved.
+ *
+ * Redistribution and use of this software in source and binary forms, with or
+ * without modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Author: Sunil Soman sunils@cs.ucsb.edu
+ */
+
+package com.eucalyptus.util;
+
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+
+import edu.ucsb.eucalyptus.cloud.AccessDeniedException;
+import edu.ucsb.eucalyptus.cloud.BucketAlreadyExistsException;
+import edu.ucsb.eucalyptus.cloud.BucketAlreadyOwnedByYouException;
+import edu.ucsb.eucalyptus.cloud.BucketNotEmptyException;
+import edu.ucsb.eucalyptus.cloud.DecryptionFailedException;
+import edu.ucsb.eucalyptus.cloud.EntityTooLargeException;
+import edu.ucsb.eucalyptus.cloud.ImageAlreadyExistsException;
+import edu.ucsb.eucalyptus.cloud.InvalidRangeException;
+import edu.ucsb.eucalyptus.cloud.NoSuchBucketException;
+import edu.ucsb.eucalyptus.cloud.NoSuchEntityException;
+import edu.ucsb.eucalyptus.cloud.NotAuthorizedException;
+import edu.ucsb.eucalyptus.cloud.NotImplementedException;
+import edu.ucsb.eucalyptus.cloud.NotModifiedException;
+import edu.ucsb.eucalyptus.cloud.PreconditionFailedException;
+import edu.ucsb.eucalyptus.cloud.TooManyBucketsException;
+import edu.ucsb.eucalyptus.msgs.EucalyptusMessage;
+import edu.ucsb.eucalyptus.msgs.WalrusBucketErrorMessageType;
+import edu.ucsb.eucalyptus.msgs.EucalyptusErrorMessageType;
+
+
+public class WalrusUtil {
+ private static Logger LOG = Logger.getLogger( WalrusUtil.class );
+ private static String ipAddress;
+
+ static {
+ ipAddress = "127.0.0.1";
+ List<NetworkInterface> ifaces = null;
+ try {
+ ifaces = Collections.list( NetworkInterface.getNetworkInterfaces() );
+ } catch ( SocketException e1 ) {}
+
+ for ( NetworkInterface iface : ifaces ) {
+ try {
+ if ( !iface.isLoopback() && !iface.isVirtual() && iface.isUp() ) {
+ for ( InetAddress iaddr : Collections.list( iface.getInetAddresses() ) ) {
+ if ( !iaddr.isSiteLocalAddress() && !( iaddr instanceof Inet6Address) ) {
+ ipAddress = iaddr.getHostAddress();
+ break;
+ }
+ }
+ }
+ } catch ( SocketException e1 ) {}
+ }
+ }
+
+ public static EucalyptusMessage convertErrorMessage(EucalyptusErrorMessageType errorMessage) {
+ EucalyptusMessage errMsg;
+ Throwable ex = errorMessage.getException();
+ if ( ex instanceof NoSuchBucketException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( NoSuchBucketException ) ex ).getBucketName(), "NoSuchBucket", "The specified bucket was not found", HttpResponseStatus.NOT_FOUND, errorMessage.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( errorMessage.getCorrelationId() );
+ }
+ else if ( ex instanceof AccessDeniedException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( AccessDeniedException ) ex ).getBucketName(), "AccessDenied", "Access Denied", HttpResponseStatus.FORBIDDEN, errorMessage.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( errorMessage.getCorrelationId() );
+ }
+ else if ( ex instanceof NotAuthorizedException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( NotAuthorizedException ) ex ).getValue(), "Unauthorized", "You are not authorized to perform this operation", HttpResponseStatus.UNUATHORIZED, errorMessage.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( errorMessage.getCorrelationId() );
+ }
+ else if ( ex instanceof BucketAlreadyOwnedByYouException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( BucketAlreadyOwnedByYouException ) ex ).getBucketName(), "BucketAlreadyOwnedByYou", "Your previous request to create the named bucket succeeded and you already own it.", HttpResponseStatus.CONFLICT, errorMessage.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( errorMessage.getCorrelationId() );
+ }
+ else if ( ex instanceof BucketAlreadyExistsException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( BucketAlreadyExistsException ) ex ).getBucketName(), "BucketAlreadyExists", "The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.", HttpResponseStatus.CONFLICT, errorMessage.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( errorMessage.getCorrelationId() );
+ }
+ else if ( ex instanceof BucketNotEmptyException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( BucketNotEmptyException ) ex ).getBucketName(), "BucketNotEmpty", "The bucket you tried to delete is not empty.", HttpResponseStatus.CONFLICT, errorMessage.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( errorMessage.getCorrelationId() );
+ }
+ else if ( ex instanceof PreconditionFailedException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( PreconditionFailedException ) ex ).getPrecondition(), "PreconditionFailed", "At least one of the pre-conditions you specified did not hold.", HttpResponseStatus.PRECONDITION_FAILED, errorMessage.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( errorMessage.getCorrelationId() );
+ }
+ else if ( ex instanceof NotModifiedException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( NotModifiedException ) ex ).getPrecondition(), "NotModified", "Object Not Modified", HttpResponseStatus.NOT_MODIFIED, errorMessage.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( errorMessage.getCorrelationId() );
+ }
+ else if ( ex instanceof TooManyBucketsException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( TooManyBucketsException ) ex ).getBucketName(), "TooManyBuckets", "You have attempted to create more buckets than allowed.", HttpResponseStatus.BAD_REQUEST, errorMessage.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( errorMessage.getCorrelationId() );
+ }
+ else if ( ex instanceof EntityTooLargeException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( EntityTooLargeException ) ex ).getEntityName(), "EntityTooLarge", "Your proposed upload exceeds the maximum allowed object size.", HttpResponseStatus.BAD_REQUEST, errorMessage.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( errorMessage.getCorrelationId() );
+ }
+ else if ( ex instanceof NoSuchEntityException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( NoSuchEntityException ) ex ).getBucketName(), "NoSuchEntity", "The specified entity was not found", HttpResponseStatus.NOT_FOUND, errorMessage.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( errorMessage.getCorrelationId() );
+ }
+ else if ( ex instanceof DecryptionFailedException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( DecryptionFailedException ) ex ).getValue(), "Decryption Failed", "Fail", HttpResponseStatus.EXPECTATION_FAILED, errorMessage.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( errorMessage.getCorrelationId() );
+ }
+ else if ( ex instanceof ImageAlreadyExistsException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( ImageAlreadyExistsException ) ex ).getValue(), "Image Already Exists", "Fail", HttpResponseStatus.CONFLICT, errorMessage.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( errorMessage.getCorrelationId() );
+ }
+ else if ( ex instanceof NotImplementedException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( NotImplementedException ) ex ).getValue(), "Not Implemented", "NA", HttpResponseStatus.NOT_IMPLEMENTED, errorMessage.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( errorMessage.getCorrelationId() );
+ } else if ( ex instanceof InvalidRangeException )
+ {
+ errMsg = new WalrusBucketErrorMessageType( ( ( InvalidRangeException ) ex ).getMessage(), "Invalid Range", "The requested range cannot be satisfied.", HttpResponseStatus.REQUESTED_RANGE_NOT_SATISFIABLE, errorMessage.getCorrelationId(), ipAddress);
+ errMsg.setCorrelationId( errorMessage.getCorrelationId() );
+ } else {
+ errMsg = errorMessage;
+ }
+ return errMsg;
+ }
+}
View
8 clc/modules/msgs/src/main/java/edu/ucsb/eucalyptus/msgs/Walrus.groovy
@@ -179,6 +179,14 @@ public class WalrusErrorMessageType extends EucalyptusMessage {
}
public HttpResponseStatus getStatus() {
+ return status;
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public String getMessage() {
return message;
}
}
View
105 clc/modules/wsstack/src/main/java/com/eucalyptus/ws/handlers/WalrusOutboundHandler.java
@@ -7,6 +7,7 @@
import java.util.Collections;
import java.util.List;
+import com.eucalyptus.util.WalrusUtil;
import com.eucalyptus.ws.MappingHttpResponse;
import org.apache.log4j.Logger;
@@ -39,29 +40,6 @@
@ChannelPipelineCoverage("one")
public class WalrusOutboundHandler extends MessageStackHandler {
private static Logger LOG = Logger.getLogger( WalrusOutboundHandler.class );
- private static String ipAddress;
-
- static {
- ipAddress = "127.0.0.1";
- List<NetworkInterface> ifaces = null;
- try {
- ifaces = Collections.list( NetworkInterface.getNetworkInterfaces() );
- } catch ( SocketException e1 ) {}
-
- for ( NetworkInterface iface : ifaces ) {
- try {
- if ( !iface.isLoopback() && !iface.isVirtual() && iface.isUp() ) {
- for ( InetAddress iaddr : Collections.list( iface.getInetAddresses() ) ) {
- if ( !iaddr.isSiteLocalAddress() && !( iaddr instanceof Inet6Address) ) {
- ipAddress = iaddr.getHostAddress();
- break;
- }
- }
- }
- } catch ( SocketException e1 ) {}
- }
- }
-
@Override
public void incomingMessage( ChannelHandlerContext ctx, MessageEvent event ) throws Exception {
@@ -98,92 +76,13 @@ public void outgoingMessage( ChannelHandlerContext ctx, MessageEvent event ) thr
}
} else if(msg instanceof EucalyptusErrorMessageType) {
-
EucalyptusErrorMessageType errorMessage = (EucalyptusErrorMessageType) msg;
- EucalyptusMessage errMsg;
- Throwable ex = errorMessage.getException();
- if ( ex instanceof NoSuchBucketException )
- {
- errMsg = new WalrusBucketErrorMessageType( ( ( NoSuchBucketException ) ex ).getBucketName(), "NoSuchBucket", "The specified bucket was not found", HttpResponseStatus.NOT_FOUND, msg.getCorrelationId(), ipAddress);
- errMsg.setCorrelationId( msg.getCorrelationId() );
- }
- else if ( ex instanceof AccessDeniedException )
- {
- errMsg = new WalrusBucketErrorMessageType( ( ( AccessDeniedException ) ex ).getBucketName(), "AccessDenied", "No U", HttpResponseStatus.FORBIDDEN, msg.getCorrelationId(), ipAddress);
- errMsg.setCorrelationId( msg.getCorrelationId() );
- }
- else if ( ex instanceof NotAuthorizedException )
- {
- errMsg = new WalrusBucketErrorMessageType( ( ( NotAuthorizedException ) ex ).getValue(), "Unauthorized", "No U", HttpResponseStatus.UNUATHORIZED, msg.getCorrelationId(), ipAddress);
- errMsg.setCorrelationId( msg.getCorrelationId() );
- }
- else if ( ex instanceof BucketAlreadyOwnedByYouException )
- {
- errMsg = new WalrusBucketErrorMessageType( ( ( BucketAlreadyOwnedByYouException ) ex ).getBucketName(), "BucketAlreadyOwnedByYou", "Your previous request to create the named bucket succeeded and you already own it.", HttpResponseStatus.CONFLICT, msg.getCorrelationId(), ipAddress);
- errMsg.setCorrelationId( msg.getCorrelationId() );
- }
- else if ( ex instanceof BucketAlreadyExistsException )
- {
- errMsg = new WalrusBucketErrorMessageType( ( ( BucketAlreadyExistsException ) ex ).getBucketName(), "BucketAlreadyExists", "The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.", HttpResponseStatus.CONFLICT, msg.getCorrelationId(), ipAddress);
- errMsg.setCorrelationId( msg.getCorrelationId() );
- }
- else if ( ex instanceof BucketNotEmptyException )
- {
- errMsg = new WalrusBucketErrorMessageType( ( ( BucketNotEmptyException ) ex ).getBucketName(), "BucketNotEmpty", "The bucket you tried to delete is not empty.", HttpResponseStatus.CONFLICT, msg.getCorrelationId(), ipAddress);
- errMsg.setCorrelationId( msg.getCorrelationId() );
- }
- else if ( ex instanceof PreconditionFailedException )
- {
- errMsg = new WalrusBucketErrorMessageType( ( ( PreconditionFailedException ) ex ).getPrecondition(), "PreconditionFailed", "At least one of the pre-conditions you specified did not hold.", HttpResponseStatus.PRECONDITION_FAILED, msg.getCorrelationId(), ipAddress);
- errMsg.setCorrelationId( msg.getCorrelationId() );
- }
- else if ( ex instanceof NotModifiedException )
- {
- errMsg = new WalrusBucketErrorMessageType( ( ( NotModifiedException ) ex ).getPrecondition(), "NotModified", "Object Not Modified", HttpResponseStatus.NOT_MODIFIED, msg.getCorrelationId(), ipAddress);
- errMsg.setCorrelationId( msg.getCorrelationId() );
- }
- else if ( ex instanceof TooManyBucketsException )
- {
- errMsg = new WalrusBucketErrorMessageType( ( ( TooManyBucketsException ) ex ).getBucketName(), "TooManyBuckets", "You have attempted to create more buckets than allowed.", HttpResponseStatus.BAD_REQUEST, msg.getCorrelationId(), ipAddress);
- errMsg.setCorrelationId( msg.getCorrelationId() );
- }
- else if ( ex instanceof EntityTooLargeException )
- {
- errMsg = new WalrusBucketErrorMessageType( ( ( EntityTooLargeException ) ex ).getEntityName(), "EntityTooLarge", "Your proposed upload exceeds the maximum allowed object size.", HttpResponseStatus.BAD_REQUEST, msg.getCorrelationId(), ipAddress);
- errMsg.setCorrelationId( msg.getCorrelationId() );
- }
- else if ( ex instanceof NoSuchEntityException )
- {
- errMsg = new WalrusBucketErrorMessageType( ( ( NoSuchEntityException ) ex ).getBucketName(), "NoSuchEntity", "The specified entity was not found", HttpResponseStatus.NOT_FOUND, msg.getCorrelationId(), ipAddress);
- errMsg.setCorrelationId( msg.getCorrelationId() );
- }
- else if ( ex instanceof DecryptionFailedException )
- {
- errMsg = new WalrusBucketErrorMessageType( ( ( DecryptionFailedException ) ex ).getValue(), "Decryption Failed", "Fail", HttpResponseStatus.EXPECTATION_FAILED, msg.getCorrelationId(), ipAddress);
- errMsg.setCorrelationId( msg.getCorrelationId() );
- }
- else if ( ex instanceof ImageAlreadyExistsException )
- {
- errMsg = new WalrusBucketErrorMessageType( ( ( ImageAlreadyExistsException ) ex ).getValue(), "Image Already Exists", "Fail", HttpResponseStatus.CONFLICT, msg.getCorrelationId(), ipAddress);
- errMsg.setCorrelationId( msg.getCorrelationId() );
- }
- else if ( ex instanceof NotImplementedException )
- {
- errMsg = new WalrusBucketErrorMessageType( ( ( NotImplementedException ) ex ).getValue(), "Not Implemented", "NA", HttpResponseStatus.NOT_IMPLEMENTED, msg.getCorrelationId(), ipAddress);
- errMsg.setCorrelationId( msg.getCorrelationId() );
- } else if ( ex instanceof InvalidRangeException )
- {
- errMsg = new WalrusBucketErrorMessageType( ( ( InvalidRangeException ) ex ).getMessage(), "Invalid Range", "The requested range cannot be satisfied.", HttpResponseStatus.REQUESTED_RANGE_NOT_SATISFIABLE, msg.getCorrelationId(), ipAddress);
- errMsg.setCorrelationId( msg.getCorrelationId() );
- } else {
- errMsg = errorMessage;
- }
+ EucalyptusMessage errMsg = WalrusUtil.convertErrorMessage(errorMessage);
if(errMsg instanceof WalrusBucketErrorMessageType) {
WalrusBucketErrorMessageType walrusErrorMsg = (WalrusBucketErrorMessageType) errMsg;
httpResponse.setStatus(walrusErrorMsg.getStatus());
}
httpResponse.setMessage(errMsg);
-
} else if(msg instanceof WalrusDeleteResponseType) {
httpResponse.setStatus(HttpResponseStatus.NO_CONTENT);
httpResponse.setMessage(null);
View
13 clc/modules/wsstack/src/main/java/com/eucalyptus/ws/handlers/WalrusSoapHandler.java
@@ -27,13 +27,16 @@
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.handler.codec.http.HttpHeaders;
+import com.eucalyptus.util.WalrusUtil;
import com.eucalyptus.ws.EucalyptusRemoteFault;
import com.eucalyptus.ws.MappingHttpMessage;
import com.eucalyptus.ws.MappingHttpRequest;
import com.eucalyptus.ws.binding.Binding;
import com.google.common.collect.Lists;
import edu.ucsb.eucalyptus.msgs.EucalyptusErrorMessageType;
+import edu.ucsb.eucalyptus.msgs.EucalyptusMessage;
+import edu.ucsb.eucalyptus.msgs.WalrusBucketErrorMessageType;
@ChannelPipelineCoverage("one")
public class WalrusSoapHandler extends MessageStackHandler {
@@ -87,8 +90,14 @@ public void outgoingMessage( ChannelHandlerContext ctx, MessageEvent event ) thr
if ( event.getMessage( ) instanceof MappingHttpMessage ) {
final MappingHttpMessage httpMessage = ( MappingHttpMessage ) event.getMessage( );
if( httpMessage.getMessage( ) instanceof EucalyptusErrorMessageType ) {
- EucalyptusErrorMessageType errMsg = (EucalyptusErrorMessageType) httpMessage.getMessage( );
- httpMessage.setSoapEnvelope( Binding.createFault( errMsg.getSource( ), errMsg.getMessage( ), errMsg.getStatusMessage( ) ) );
+ EucalyptusErrorMessageType errorMessage = (EucalyptusErrorMessageType) httpMessage.getMessage( );
+ EucalyptusMessage errMsg = WalrusUtil.convertErrorMessage(errorMessage);
+ if(errMsg instanceof WalrusBucketErrorMessageType) {
+ WalrusBucketErrorMessageType walrusErrMsg = (WalrusBucketErrorMessageType) errMsg;
+ httpMessage.setSoapEnvelope( Binding.createFault( walrusErrMsg.getCode(), walrusErrMsg.getMessage(), walrusErrMsg.getStatus().getReasonPhrase()));
+ } else {
+ httpMessage.setSoapEnvelope( Binding.createFault( errorMessage.getSource( ), errorMessage.getMessage( ), errorMessage.getStatusMessage( ) ) );
+ }
} else {
// :: assert sourceElem != null :://
httpMessage.setSoapEnvelope( this.soapFactory.getDefaultEnvelope( ) );

0 comments on commit 2cafd0e

Please sign in to comment.
Something went wrong with that request. Please try again.