Example usage for javax.xml.bind JAXBException getMessage

List of usage examples for javax.xml.bind JAXBException getMessage

Introduction

In this page you can find the example usage for javax.xml.bind JAXBException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.xerox.amazonws.ec2.Jec2.java

/**
 * Associates an address with an instance.
 *
 * @param instanceId the instance/*  w  w w.j  a  v a  2s . c om*/
 * @param publicIp the ip address to associate
 * @throws EC2Exception wraps checked exceptions
 */
public void associateAddress(String instanceId, String publicIp) throws EC2Exception {
    Map<String, String> params = new HashMap<String, String>();
    params.put("InstanceId", instanceId);
    params.put("PublicIp", publicIp);
    GetMethod method = new GetMethod();
    try {
        AssociateAddressResponse response = makeRequest(method, "AssociateAddress", params,
                AssociateAddressResponse.class);
        if (!response.isReturn()) {
            throw new EC2Exception("Could not associate address with instance (no reason given).");
        }
    } catch (JAXBException ex) {
        throw new EC2Exception("Problem parsing returned message.", ex);
    } catch (MalformedURLException ex) {
        throw new EC2Exception(ex.getMessage(), ex);
    } catch (IOException ex) {
        throw new EC2Exception(ex.getMessage(), ex);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.xerox.amazonws.ec2.Jec2.java

/**
 * Reboot a selection of running instances.
 * //  w  ww.  j  a  v a2  s .  c  o  m
 * @param instanceIds A list of instances ({@link com.xerox.amazonws.ec2.ReservationDescription.Instance#instanceId}.
 * @throws EC2Exception wraps checked exceptions
 */
public void rebootInstances(List<String> instanceIds) throws EC2Exception {
    Map<String, String> params = new HashMap<String, String>();
    for (int i = 0; i < instanceIds.size(); i++) {
        params.put("InstanceId." + (i + 1), instanceIds.get(i));
    }
    GetMethod method = new GetMethod();
    try {
        RebootInstancesResponse response = makeRequest(method, "RebootInstances", params,
                RebootInstancesResponse.class);
        if (!response.isReturn()) {
            throw new EC2Exception("Could not reboot instances. No reason given.");
        }
    } catch (JAXBException ex) {
        throw new EC2Exception("Problem parsing returned message.", ex);
    } catch (MalformedURLException ex) {
        throw new EC2Exception(ex.getMessage(), ex);
    } catch (IOException ex) {
        throw new EC2Exception(ex.getMessage(), ex);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.xerox.amazonws.ec2.Jec2.java

/**
 * Returns true if the productCode is associated with the instance.
 *
 * @param instanceId An instance's id ({@link com.xerox.amazonws.ec2.ReservationDescription.Instance#instanceId}.
 * @param productCode the code for the project you registered with AWS
 * @return null if no relationship exists, otherwise information about the owner
 * @throws EC2Exception wraps checked exceptions
 *//*  www . java 2 s .  c  om*/
public ProductInstanceInfo confirmProductInstance(String instanceId, String productCode) throws EC2Exception {
    Map<String, String> params = new HashMap<String, String>();
    params.put("InstanceId", instanceId);
    params.put("ProductCode", productCode);
    GetMethod method = new GetMethod();
    try {
        ConfirmProductInstanceResponse response = makeRequest(method, "ConfirmProductInstance", params,
                ConfirmProductInstanceResponse.class);
        if (response.isReturn()) {
            return new ProductInstanceInfo(instanceId, productCode, response.getOwnerId());
        } else
            return null;
    } catch (JAXBException ex) {
        throw new EC2Exception("Problem parsing returned message.", ex);
    } catch (MalformedURLException ex) {
        throw new EC2Exception(ex.getMessage(), ex);
    } catch (IOException ex) {
        throw new EC2Exception(ex.getMessage(), ex);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.xerox.amazonws.ec2.Jec2.java

/**
 * Revokes incoming permissions from a security group.
 * /*from  ww w  . ja va2  s . c om*/
 * @param groupName name of group to modify
 * @param secGroupName name of security group to revoke access from
 * @param secGroupOwnerId owner of security group to revoke access from
 * @throws EC2Exception wraps checked exceptions
 */
public void revokeSecurityGroupIngress(String groupName, String secGroupName, String secGroupOwnerId)
        throws EC2Exception {
    Map<String, String> params = new HashMap<String, String>();
    params.put("GroupName", groupName);
    params.put("SourceSecurityGroupOwnerId", secGroupOwnerId);
    params.put("SourceSecurityGroupName", secGroupName);
    GetMethod method = new GetMethod();
    try {
        RevokeSecurityGroupIngressResponse response = makeRequest(method, "RevokeSecurityGroupIngress", params,
                RevokeSecurityGroupIngressResponse.class);
        if (!response.isReturn()) {
            throw new EC2Exception("Could not revoke security ingress : " + groupName + ". No reason given.");
        }
    } catch (JAXBException ex) {
        throw new EC2Exception("Problem parsing returned message.", ex);
    } catch (MalformedURLException ex) {
        throw new EC2Exception(ex.getMessage(), ex);
    } catch (IOException ex) {
        throw new EC2Exception(ex.getMessage(), ex);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.xerox.amazonws.ec2.Jec2.java

/**
 * Adds incoming permissions to a security group.
 * /*from  w ww. j a  v a 2 s  . c o m*/
 * @param groupName name of group to modify
 * @param secGroupName name of security group to authorize access to
 * @param secGroupOwnerId owner of security group to authorize access to
 * @throws EC2Exception wraps checked exceptions
 */
public void authorizeSecurityGroupIngress(String groupName, String secGroupName, String secGroupOwnerId)
        throws EC2Exception {
    Map<String, String> params = new HashMap<String, String>();
    params.put("GroupName", groupName);
    params.put("SourceSecurityGroupOwnerId", secGroupOwnerId);
    params.put("SourceSecurityGroupName", secGroupName);
    GetMethod method = new GetMethod();
    try {
        AuthorizeSecurityGroupIngressResponse response = makeRequest(method, "AuthorizeSecurityGroupIngress",
                params, AuthorizeSecurityGroupIngressResponse.class);
        if (!response.isReturn()) {
            throw new EC2Exception(
                    "Could not authorize security ingress : " + groupName + ". No reason given.");
        }
    } catch (JAXBException ex) {
        throw new EC2Exception("Problem parsing returned message.", ex);
    } catch (MalformedURLException ex) {
        throw new EC2Exception(ex.getMessage(), ex);
    } catch (IOException ex) {
        throw new EC2Exception(ex.getMessage(), ex);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.xerox.amazonws.ec2.Jec2.java

/**
 * Revokes incoming permissions from a security group.
 * //  w ww .  jav  a  2s.c  o  m
 * @param groupName name of group to modify
 * @param ipProtocol protocol to revoke (tcp, udp, icmp)
 * @param fromPort bottom of port range to revoke
 * @param toPort top of port range to revoke
 * @param cidrIp CIDR IP range to revoke (i.e. 0.0.0.0/0)
 * @throws EC2Exception wraps checked exceptions
 */
public void revokeSecurityGroupIngress(String groupName, String ipProtocol, int fromPort, int toPort,
        String cidrIp) throws EC2Exception {
    Map<String, String> params = new HashMap<String, String>();
    params.put("GroupName", groupName);
    params.put("IpProtocol", ipProtocol);
    params.put("FromPort", "" + fromPort);
    params.put("ToPort", "" + toPort);
    params.put("CidrIp", cidrIp);
    GetMethod method = new GetMethod();
    try {
        RevokeSecurityGroupIngressResponse response = makeRequest(method, "RevokeSecurityGroupIngress", params,
                RevokeSecurityGroupIngressResponse.class);
        if (!response.isReturn()) {
            throw new EC2Exception("Could not revoke security ingress : " + groupName + ". No reason given.");
        }
    } catch (JAXBException ex) {
        throw new EC2Exception("Problem parsing returned message.", ex);
    } catch (MalformedURLException ex) {
        throw new EC2Exception(ex.getMessage(), ex);
    } catch (IOException ex) {
        throw new EC2Exception(ex.getMessage(), ex);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.xerox.amazonws.ec2.Jec2.java

/**
 * Adds incoming permissions to a security group.
 * //from ww w .  java 2s .c  o  m
 * @param groupName name of group to modify
 * @param ipProtocol protocol to authorize (tcp, udp, icmp)
 * @param fromPort bottom of port range to authorize
 * @param toPort top of port range to authorize
 * @param cidrIp CIDR IP range to authorize (i.e. 0.0.0.0/0)
 * @throws EC2Exception wraps checked exceptions
 */
public void authorizeSecurityGroupIngress(String groupName, String ipProtocol, int fromPort, int toPort,
        String cidrIp) throws EC2Exception {
    Map<String, String> params = new HashMap<String, String>();
    params.put("GroupName", groupName);
    params.put("IpProtocol", ipProtocol);
    params.put("FromPort", "" + fromPort);
    params.put("ToPort", "" + toPort);
    params.put("CidrIp", cidrIp);
    GetMethod method = new GetMethod();
    try {
        AuthorizeSecurityGroupIngressResponse response = makeRequest(method, "AuthorizeSecurityGroupIngress",
                params, AuthorizeSecurityGroupIngressResponse.class);
        if (!response.isReturn()) {
            throw new EC2Exception(
                    "Could not authorize security ingress : " + groupName + ". No reason given.");
        }
    } catch (JAXBException ex) {
        throw new EC2Exception("Problem parsing returned message.", ex);
    } catch (MalformedURLException ex) {
        throw new EC2Exception(ex.getMessage(), ex);
    } catch (IOException ex) {
        throw new EC2Exception(ex.getMessage(), ex);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.xerox.amazonws.ec2.Jec2.java

/**
 * Resets an attribute on an AMI.//from   ww  w . j  av a 2s . c o  m
 *
 * @param imageId The AMI to reset the attribute on.
 * @param imageAttribute The attribute type to reset.
 * @throws EC2Exception wraps checked exceptions
 */
public void resetImageAttribute(String imageId, ImageAttribute.ImageAttributeType imageAttribute)
        throws EC2Exception {
    Map<String, String> params = new HashMap<String, String>();
    params.put("ImageId", imageId);
    if (imageAttribute.equals(ImageAttribute.ImageAttributeType.launchPermission)) {
        params.put("Attribute", "launchPermission");
    } else if (imageAttribute.equals(ImageAttribute.ImageAttributeType.productCodes)) {
        throw new IllegalArgumentException("Cannot reset productCodes attribute");
    }
    GetMethod method = new GetMethod();
    try {
        ResetImageAttributeResponse response = makeRequest(method, "ResetImageAttribute", params,
                ResetImageAttributeResponse.class);
        if (!response.isReturn()) {
            throw new EC2Exception("Could not reset image attribute. No reason given.");
        }
    } catch (JAXBException ex) {
        throw new EC2Exception("Problem parsing returned message.", ex);
    } catch (MalformedURLException ex) {
        throw new EC2Exception(ex.getMessage(), ex);
    } catch (IOException ex) {
        throw new EC2Exception(ex.getMessage(), ex);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.xerox.amazonws.ec2.Jec2.java

/**
 * Lists public/private keypairs.//from www . ja  va2s  .c  om
 * 
 * @param keyIds A list of keypairs.
 * @return A list of keypair descriptions ({@link KeyPairInfo}).
 * @throws EC2Exception wraps checked exceptions
 */
public List<KeyPairInfo> describeKeyPairs(List<String> keyIds) throws EC2Exception {
    Map<String, String> params = new HashMap<String, String>();
    for (int i = 0; i < keyIds.size(); i++) {
        params.put("KeyName." + (i + 1), keyIds.get(i));
    }
    GetMethod method = new GetMethod();
    try {
        DescribeKeyPairsResponse response = makeRequest(method, "DescribeKeyPairs", params,
                DescribeKeyPairsResponse.class);
        List<KeyPairInfo> result = new ArrayList<KeyPairInfo>();
        DescribeKeyPairsResponseInfoType set = response.getKeySet();
        Iterator set_iter = set.getItems().iterator();
        while (set_iter.hasNext()) {
            DescribeKeyPairsResponseItemType item = (DescribeKeyPairsResponseItemType) set_iter.next();
            result.add(new KeyPairInfo(item.getKeyName(), item.getKeyFingerprint(), null));
        }
        return result;
    } catch (JAXBException ex) {
        throw new EC2Exception("Problem parsing returned message.", ex);
    } catch (MalformedURLException ex) {
        throw new EC2Exception(ex.getMessage(), ex);
    } catch (IOException ex) {
        throw new EC2Exception(ex.getMessage(), ex);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.xerox.amazonws.ec2.Jec2.java

/**
 * Returns a list of availability zones and their status.
 *
 * @param zones a list of zones to limit the results, or null
 * @return a list of zones and their availability
 * @throws EC2Exception wraps checked exceptions
 *//*from  w  w  w .java 2s .  c om*/
public List<AvailabilityZone> describeAvailabilityZones(List<String> zones) throws EC2Exception {
    Map<String, String> params = new HashMap<String, String>();
    if (zones != null && zones.size() > 0) {
        for (int i = 0; i < zones.size(); i++) {
            params.put("ZoneName." + (i + 1), zones.get(i));
        }
    }
    GetMethod method = new GetMethod();
    try {
        DescribeAvailabilityZonesResponse response = makeRequest(method, "DescribeAvailabilityZones", params,
                DescribeAvailabilityZonesResponse.class);
        List<AvailabilityZone> ret = new ArrayList<AvailabilityZone>();
        AvailabilityZoneSetType set = response.getAvailabilityZoneInfo();
        Iterator set_iter = set.getItems().iterator();
        while (set_iter.hasNext()) {
            AvailabilityZoneItemType item = (AvailabilityZoneItemType) set_iter.next();
            ret.add(new AvailabilityZone(item.getZoneName(), item.getZoneState()));
        }
        return ret;
    } catch (JAXBException ex) {
        throw new EC2Exception("Problem parsing returned message.", ex);
    } catch (MalformedURLException ex) {
        throw new EC2Exception(ex.getMessage(), ex);
    } catch (IOException ex) {
        throw new EC2Exception(ex.getMessage(), ex);
    } finally {
        method.releaseConnection();
    }
}