Package com.cloud.bridge.service.exception

Examples of com.cloud.bridge.service.exception.EC2ServiceException


        EC2DescribeInstances EC2request = new EC2DescribeInstances();
        String[] instanceId = request.getParameterValues( "InstanceId" );
        if ( instanceId != null && instanceId.length > 0)
            EC2request.addInstanceId( instanceId[0] );
        else
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - InstanceId");

        String[] attribute = request.getParameterValues( "Attribute" );
        if (attribute != null && attribute.length > 0) {
               if ( !attribute[0].equalsIgnoreCase("instanceType") ) {
                throw new EC2ServiceException( ClientError.InvalidParameterValue,
                        "Only value supported for paramter Attribute is 'instanceType'");
            }
        } else {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - Attribute");
        }

        // -> execute the request
        DescribeInstanceAttributeResponse EC2response = EC2SoapServiceImpl.toDescribeInstanceAttributeResponse( ServiceProvider.getInstance().getEC2Engine().describeInstances(EC2request));
        serializeResponse(response, EC2response);
View Full Code Here


        String[] instanceId = request.getParameterValues( "InstanceId" );
        if ( instanceId != null && instanceId.length > 0 )
             ec2Request.setInstanceId(instanceId[0]);
        else {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - InstanceId");
        }

        String[] instanceType = request.getParameterValues( "InstanceType.Value" );
        String[] userData  = request.getParameterValues( "UserData.Value" );

        if ( instanceType != null && userData != null ) {
            throw new EC2ServiceException( ClientError.InvalidParameterCombination, "Only one attribute can be" +
                    " specified at a time");
        }
        if ( instanceType != null && instanceType.length > 0 ) {
            ec2Request.setInstanceType(instanceType[0]);
        } else if ( userData != null && userData.length > 0 ) {
            ec2Request.setUserData(userData[0]);
        } else {
            throw new EC2ServiceException( ClientError.MissingParamter,
                    "Missing parameter - InstanceType/UserData should be provided");
        }

        // -> execute the request
        ModifyInstanceAttributeResponse EC2response = EC2SoapServiceImpl.toModifyInstanceAttributeResponse(
View Full Code Here

    private void importKeyPair(HttpServletRequest request, HttpServletResponse response)
            throws ADBException, XMLStreamException, IOException {

        String keyName = request.getParameter("KeyName");
        if ( keyName == null ) {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - KeyName");
        }

        String publicKeyMaterial = request.getParameter("PublicKeyMaterial");
        if ( publicKeyMaterial == null ) {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - PublicKeyMaterial");
        }

        if (!publicKeyMaterial.contains(" "))
            publicKeyMaterial = new String(Base64.decodeBase64(publicKeyMaterial.getBytes()));
View Full Code Here

    private void createKeyPair(HttpServletRequest request, HttpServletResponse response)
            throws ADBException, XMLStreamException, IOException {
        String keyName = request.getParameter("KeyName");
        if (keyName==null) {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - KeyName");
        }

        EC2CreateKeyPair ec2Request = new EC2CreateKeyPair();
        if (ec2Request != null) {
            ec2Request.setKeyName(keyName);
View Full Code Here

    private void deleteKeyPair(HttpServletRequest request, HttpServletResponse response)
            throws ADBException, XMLStreamException, IOException {
        String keyName = request.getParameter("KeyName");
        if (keyName==null) {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - KeyName");
        }

        EC2DeleteKeyPair ec2Request = new EC2DeleteKeyPair();
        ec2Request.setKeyName(keyName);
View Full Code Here

    private void getPasswordData(HttpServletRequest request, HttpServletResponse response)
            throws ADBException, XMLStreamException, IOException {
        String instanceId = request.getParameter("InstanceId");
        if (instanceId==null) {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - InstanceId");
        }

        GetPasswordDataResponse EC2Response = EC2SoapServiceImpl.toGetPasswordData(
                ServiceProvider.getInstance().getEC2Engine().getPasswordData(instanceId));
        serializeResponse(response, EC2Response);
View Full Code Here

                resourceIdList.add(resourceIds[0]);
            else break;
            nCount++;
        } while (true);
        if ( resourceIdList.isEmpty() ) {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - ResourceId");
        }
        ec2Request = EC2SoapServiceImpl.toResourceTypeAndIds(ec2Request, resourceIdList);

        nCount = 1;
        do {
            String[] tagKey = request.getParameterValues( "Tag." + nCount + ".Key" );
            if ( tagKey != null && tagKey.length > 0 ) {
               String[] tagValue = request.getParameterValues( "Tag." + nCount + ".Value" );
            if ( tagValue != null && tagValue.length > 0 ) {
                resourceTagList.put(tagKey[0], tagValue[0]);
            } else
                resourceTagList.put(tagKey[0], null);
            } else break;
            nCount++;
        } while (true);
        if ( resourceTagList.isEmpty() ) {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - ResourceTag");
        }
        ec2Request = EC2SoapServiceImpl.toResourceTag(ec2Request, resourceTagList);

        return ec2Request;
    }
View Full Code Here

        //  -> note that the Servlet engine will un-URL encode all parameters we extract via "getParameterValues()" calls
        String[] awsAccess = request.getParameterValues( "AWSAccessKeyId" );
        if ( null != awsAccess && 0 < awsAccess.length )
            cloudAccessKey = awsAccess[0];
        else {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - AWSAccessKeyId");
        }

        String[] clientSig = request.getParameterValues( "Signature" );
        if ( null != clientSig && 0 < clientSig.length )
            signature = clientSig[0];
        else {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - Signature");
        }

        String[] method = request.getParameterValues( "SignatureMethod" );
        if ( null != method && 0 < method.length )
        {
            sigMethod = method[0];
            if (!sigMethod.equals( "HmacSHA256" ) && !sigMethod.equals( "HmacSHA1" )) {
              throw new EC2ServiceException( ClientError.InvalidParameterValue,
                         "Unsupported SignatureMethod value: " + sigMethod + " expecting: HmacSHA256 or HmacSHA1");
            }
        } else {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - SignatureMethod");
        }

        String[] version = request.getParameterValues( "Version" );
        if ( null != version && 0 < version.length )
        {
            if (!version[0].equals( wsdlVersion )) {
                throw new EC2ServiceException( ClientError.InvalidParameterValue,
                        "Unsupported Version value: " + version[0] + " expecting: " + wsdlVersion);
            }
        } else {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - Version");
        }

        String[] sigVersion = request.getParameterValues( "SignatureVersion" );
        if ( null != sigVersion && 0 < sigVersion.length )
        {
            if (!sigVersion[0].equals( "2" )) {
                throw new EC2ServiceException( ClientError.InvalidParameterValue,
                     "Unsupported SignatureVersion value: " + sigVersion[0] + " expecting: 2");
            }
        }
        else {
            throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - SignatureVersion");
        }

        // -> can have only one but not both { Expires | Timestamp } headers
        String[] expires = request.getParameterValues( "Expires" );
        if ( null != expires && 0 < expires.length )
        {
            // -> contains the date and time at which the signature included in the request EXPIRES
            if (hasSignatureExpired( expires[0] )) { //InvalidSecurity.RequestHasExpired
                 throw new EC2ServiceException( ClientError.InvalidSecurity_RequestHasExpired,
                        "Expires parameter indicates signature has expired: " + expires[0]);
            }
        }
        else
        {    // -> contains the date and time at which the request is SIGNED
            String[] time = request.getParameterValues( "Timestamp" );
            if ( null == time || 0 == time.length ) {
                throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter -" +
                          " Timestamp/Expires");
            }
        }

        // [B] Use the access key to get the users secret key from the cloud DB
        cloudSecretKey = userDao.getSecretKeyByAccessKey( cloudAccessKey );
        if ( cloudSecretKey == null ) {
            logger.debug( "Access key '" + cloudAccessKey + "' not found in the the EC2 service ");
            throw new EC2ServiceException( ClientError.AuthFailure, "Access key '" + cloudAccessKey + "' not found in the the EC2 service ");
        }

        // [C] Verify the signature
        //  -> getting the query-string in this way maintains its URL encoding
        EC2RestAuth restAuth = new EC2RestAuth();
        restAuth.setHostHeader( request.getHeader( "Host" ));
        String requestUri = request.getRequestURI();

        // If forwarded from another basepath:
        String forwardedPath = (String) request.getAttribute("javax.servlet.forward.request_uri");
        if(forwardedPath!=null){
            requestUri=forwardedPath;
        }
        restAuth.setHTTPRequestURI( requestUri);

        String queryString = request.getQueryString();
        // getQueryString returns null (does it ever NOT return null for these),
        // we need to construct queryString to avoid changing the auth code...
        if (queryString == null) {
            // construct our idea of a queryString with parameters!
            Enumeration<?> params = request.getParameterNames();
            if (params != null) {
                while(params.hasMoreElements()) {
                    String paramName = (String) params.nextElement();
                    // exclude the signature string obviously. ;)
                    if (paramName.equalsIgnoreCase("Signature")) continue;
                    // URLEncoder performs application/x-www-form-urlencoded-type encoding and not Percent encoding
                    // according to RFC 3986 as required by Amazon, we need to Percent-encode (URL Encode)
                    String encodedValue = URLEncoder.encode(request.getParameter(paramName), "UTF-8")
                            .replace("+", "%20").replace("*", "%2A");
                    if (queryString == null)
                        queryString = paramName + "=" + encodedValue;
                    else
                        queryString = queryString + "&" + paramName + "=" + encodedValue;
                }
            }
        }
        restAuth.setQueryString(queryString);

        if ( restAuth.verifySignature( request.getMethod(), cloudSecretKey, signature, sigMethod )) {
            UserContext.current().initContext( cloudAccessKey, cloudSecretKey, cloudAccessKey, "REST request", null );
            return true;
        }
        else throw new EC2ServiceException( ClientError.SignatureDoesNotMatch,
                "The request signature calculated does not match the signature provided by the user.");
    }
View Full Code Here

   * @param param
   */
  public void setArchitecture( String param ) {
    if (null != param) {
            if (!param.contains(":") || param.split(":").length < 4) {
                throw new EC2ServiceExceptionClientError.InvalidParameterValue, "Supported format for " +
                        "parameter 'architecture' is format:zonename:ostypename:hypervisor" );
            }
            String parts[] = param.split( ":" );
            format = parts[0];
            zoneName = parts[1];
View Full Code Here

 
    String filterName = param.getName();
        String value = (String) filterTypes.get( filterName );

        if ( value == null || value.equalsIgnoreCase("null") ) {
                throw new EC2ServiceException( ClientError.InvalidFilter, "Filter '" + filterName + "' is invalid");
        }

    // ToDo we could add checks to make sure the type of a filters value is correct (e.g., an integer)
    filterSet.add( param );
  }
View Full Code Here

TOP

Related Classes of com.cloud.bridge.service.exception.EC2ServiceException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.