List of usage examples for javax.xml.bind JAXBException getMessage
public String getMessage()
From source file:com.xerox.amazonws.ec2.Jec2.java
/** * Returns a list of addresses associated with this account. * * @param addresses a list of zones to limit the results, or null * @return a list of addresses and their associated instance * @throws EC2Exception wraps checked exceptions *//* w w w .ja va 2 s. co m*/ public List<AddressInfo> describeAddresses(List<String> addresses) throws EC2Exception { Map<String, String> params = new HashMap<String, String>(); if (addresses != null && addresses.size() > 0) { for (int i = 0; i < addresses.size(); i++) { params.put("PublicIp." + (i + 1), addresses.get(i)); } } GetMethod method = new GetMethod(); try { DescribeAddressesResponse response = makeRequest(method, "DescribeAddresses", params, DescribeAddressesResponse.class); List<AddressInfo> ret = new ArrayList<AddressInfo>(); DescribeAddressesResponseInfoType set = response.getAddressesSet(); Iterator set_iter = set.getItems().iterator(); while (set_iter.hasNext()) { DescribeAddressesResponseItemType item = (DescribeAddressesResponseItemType) set_iter.next(); ret.add(new AddressInfo(item.getPublicIp(), item.getInstanceId())); } 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(); } }
From source file:com.xerox.amazonws.ec2.Jec2.java
protected List<ImageDescription> describeImages(Map<String, String> params) throws EC2Exception { GetMethod method = new GetMethod(); try {/*from w w w . j a va 2 s. c o m*/ DescribeImagesResponse response = makeRequest(method, "DescribeImages", params, DescribeImagesResponse.class); List<ImageDescription> result = new ArrayList<ImageDescription>(); DescribeImagesResponseInfoType set = response.getImagesSet(); Iterator set_iter = set.getItems().iterator(); while (set_iter.hasNext()) { DescribeImagesResponseItemType item = (DescribeImagesResponseItemType) set_iter.next(); ArrayList<String> codes = new ArrayList<String>(); ProductCodesSetType code_set = item.getProductCodes(); if (code_set != null) { for (ProductCodesSetItemType code : code_set.getItems()) { codes.add(code.getProductCode()); } } result.add(new ImageDescription(item.getImageId(), item.getImageLocation(), item.getImageOwnerId(), item.getImageState(), item.isIsPublic(), codes)); } 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
/** * Terminates a selection of running instances. * /* w ww. j a va 2s.co m*/ * @param instanceIds A list of instances ({@link com.xerox.amazonws.ec2.ReservationDescription.Instance#instanceId}. * @return A list of {@link TerminatingInstanceDescription} instances. * @throws EC2Exception wraps checked exceptions */ public List<TerminatingInstanceDescription> terminateInstances(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 { TerminateInstancesResponse response = makeRequest(method, "TerminateInstances", params, TerminateInstancesResponse.class); response.getInstancesSet(); List<TerminatingInstanceDescription> res = new ArrayList<TerminatingInstanceDescription>(); TerminateInstancesResponseInfoType set = response.getInstancesSet(); Iterator instances_iter = set.getItems().iterator(); while (instances_iter.hasNext()) { TerminateInstancesResponseItemType rsp_item = (TerminateInstancesResponseItemType) instances_iter .next(); res.add(new TerminatingInstanceDescription(rsp_item.getInstanceId(), rsp_item.getPreviousState().getName(), rsp_item.getPreviousState().getCode(), rsp_item.getShutdownState().getName(), rsp_item.getShutdownState().getCode())); } return res; } 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
/** * Gets a list of running instances./*from w w w.j a v a 2s .c om*/ * <p> * If the list of instance IDs is empty then a list of all instances owned * by the caller will be returned. Otherwise the list will contain * information for the requested instances only. * * @param instanceIds A list of instances ({@link com.xerox.amazonws.ec2.ReservationDescription.Instance#instanceId}. * @return A list of {@link com.xerox.amazonws.ec2.ReservationDescription} instances. * @throws EC2Exception wraps checked exceptions */ public List<ReservationDescription> describeInstances(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 { DescribeInstancesResponse response = makeRequest(method, "DescribeInstances", params, DescribeInstancesResponse.class); List<ReservationDescription> result = new ArrayList<ReservationDescription>(); ReservationSetType res_set = response.getReservationSet(); Iterator reservations_iter = res_set.getItems().iterator(); while (reservations_iter.hasNext()) { RunInstancesResponse item = (RunInstancesResponse) reservations_iter.next(); ReservationDescription res = new ReservationDescription(item.getOwnerId(), item.getReservationId()); GroupSetType grp_set = item.getGroupSet(); Iterator groups_iter = grp_set.getItems().iterator(); while (groups_iter.hasNext()) { GroupItemType rsp_item = (GroupItemType) groups_iter.next(); res.addGroup(rsp_item.getGroupId()); } RunningInstancesSetType set = item.getInstancesSet(); Iterator instances_iter = set.getItems().iterator(); while (instances_iter.hasNext()) { RunningInstancesItemType rsp_item = (RunningInstancesItemType) instances_iter.next(); res.addInstance(rsp_item.getImageId(), rsp_item.getInstanceId(), rsp_item.getPrivateDnsName(), rsp_item.getDnsName(), rsp_item.getInstanceState(), rsp_item.getReason(), rsp_item.getKeyName(), rsp_item.getLaunchTime().toGregorianCalendar(), InstanceType.getTypeFromString(rsp_item.getInstanceType()), rsp_item.getPlacement().getAvailabilityZone(), rsp_item.getKernelId(), rsp_item.getRamdiskId()); } result.add(res); } 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
/** * Gets a list of security groups and their associated permissions. * // w w w. j a v a 2 s .c om * @param groupNames A list of groups to describe. * @return A list of groups ({@link GroupDescription}. * @throws EC2Exception wraps checked exceptions */ public List<GroupDescription> describeSecurityGroups(List<String> groupNames) throws EC2Exception { Map<String, String> params = new HashMap<String, String>(); for (int i = 0; i < groupNames.size(); i++) { params.put("GroupName." + (i + 1), groupNames.get(i)); } GetMethod method = new GetMethod(); try { DescribeSecurityGroupsResponse response = makeRequest(method, "DescribeSecurityGroups", params, DescribeSecurityGroupsResponse.class); List<GroupDescription> result = new ArrayList<GroupDescription>(); SecurityGroupSetType rsp_set = response.getSecurityGroupInfo(); Iterator set_iter = rsp_set.getItems().iterator(); while (set_iter.hasNext()) { SecurityGroupItemType item = (SecurityGroupItemType) set_iter.next(); GroupDescription group = new GroupDescription(item.getGroupName(), item.getGroupDescription(), item.getOwnerId()); IpPermissionSetType perms = item.getIpPermissions(); Iterator perm_iter = perms.getItems().iterator(); while (perm_iter.hasNext()) { IpPermissionType perm = (IpPermissionType) perm_iter.next(); GroupDescription.IpPermission group_perms = group.addPermission(perm.getIpProtocol(), perm.getFromPort(), perm.getToPort()); Iterator group_iter = perm.getGroups().getItems().iterator(); while (group_iter.hasNext()) { UserIdGroupPairType uid_group = (UserIdGroupPairType) group_iter.next(); group_perms.addUserGroupPair(uid_group.getUserId(), uid_group.getGroupName()); } Iterator iprange_iter = perm.getIpRanges().getItems().iterator(); while (iprange_iter.hasNext()) { IpRangeItemType range = (IpRangeItemType) iprange_iter.next(); group_perms.addIpRange(range.getCidrIp()); } } result.add(group); } 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
/** * Modifies an attribute by the given items with the given operation. * * @param imageId The ID of the AMI to modify the attributes for. * @param attribute The name of the attribute to change. * @param operationType The name of the operation to change. May be add or remove. * @throws EC2Exception wraps checked exceptions *//* ww w . ja v a 2 s . c om*/ public void modifyImageAttribute(String imageId, ImageListAttribute attribute, ImageListAttributeOperationType operationType) throws EC2Exception { Map<String, String> params = new HashMap<String, String>(); params.put("ImageId", imageId); if (attribute.getType().equals(ImageAttribute.ImageAttributeType.launchPermission)) { params.put("Attribute", "launchPermission"); switch (operationType) { case add: params.put("OperationType", "add"); break; case remove: params.put("OperationType", "remove"); break; default: throw new IllegalArgumentException("Unknown attribute operation."); } } else if (attribute.getType().equals(ImageAttribute.ImageAttributeType.productCodes)) { params.put("Attribute", "productCodes"); } int gNum = 1; int iNum = 1; int pNum = 1; for (ImageListAttributeItem item : attribute.getImageListAttributeItems()) { switch (item.getType()) { case group: params.put("UserGroup." + gNum, item.getValue()); gNum++; break; case userId: params.put("UserId." + iNum, item.getValue()); iNum++; break; case productCode: params.put("ProductCode." + pNum, item.getValue()); pNum++; break; default: throw new IllegalArgumentException("Unknown item type."); } } GetMethod method = new GetMethod(); try { ModifyImageAttributeResponse response = makeRequest(method, "ModifyImageAttribute", params, ModifyImageAttributeResponse.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
/** * Describes an attribute of an AMI.// ww w .j av a2s . c om * * @param imageId The AMI for which the attribute is described. * @param imageAttribute The attribute type to describe. * @return An object containing the imageId and a list of list attribute item types and values. * @throws EC2Exception wraps checked exceptions */ public DescribeImageAttributeResult describeImageAttribute(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)) { params.put("Attribute", "productCodes"); } GetMethod method = new GetMethod(); try { DescribeImageAttributeResponse response = makeRequest(method, "DescribeImageAttribute", params, DescribeImageAttributeResponse.class); ImageListAttribute attribute = null; if (response.getLaunchPermission() != null) { LaunchPermissionListType list = response.getLaunchPermission(); attribute = new LaunchPermissionAttribute(); java.util.ListIterator i = list.getItems().listIterator(); while (i.hasNext()) { LaunchPermissionItemType item = (LaunchPermissionItemType) i.next(); if (item.getGroup() != null) { attribute.addImageListAttributeItem(ImageListAttribute.ImageListAttributeItemType.group, item.getGroup()); } else if (item.getUserId() != null) { attribute.addImageListAttributeItem(ImageListAttribute.ImageListAttributeItemType.userId, item.getUserId()); } } } else if (response.getProductCodes() != null) { ProductCodeListType list = response.getProductCodes(); attribute = new ProductCodesAttribute(); java.util.ListIterator i = list.getItems().listIterator(); while (i.hasNext()) { ProductCodeItemType item = (ProductCodeItemType) i.next(); if (item.getProductCode() != null) { attribute.addImageListAttributeItem( ImageListAttribute.ImageListAttributeItemType.productCode, item.getProductCode()); } } } ArrayList<String> codes = new ArrayList<String>(); ProductCodeListType set = response.getProductCodes(); if (set != null) { for (ProductCodeItemType code : set.getItems()) { codes.add(code.getProductCode()); } } NullableAttributeValueType val = response.getKernel(); String kernel = (val != null) ? val.getValue() : ""; val = response.getRamdisk(); String ramdisk = (val != null) ? val.getValue() : ""; ArrayList<BlockDeviceMapping> bdm = new ArrayList<BlockDeviceMapping>(); BlockDeviceMappingType bdmSet = response.getBlockDeviceMapping(); if (bdmSet != null) { for (BlockDeviceMappingItemType mapping : bdmSet.getItems()) { bdm.add(new BlockDeviceMapping(mapping.getVirtualName(), mapping.getDeviceName())); } } return new DescribeImageAttributeResult(response.getImageId(), attribute, codes, kernel, ramdisk, bdm); } 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
/** * Requests reservation of a number of instances. * <p>/* w w w . j a v a2 s .c om*/ * This will begin launching those instances for which a reservation was * successfully obtained. * <p> * If less than <code>minCount</code> instances are available no instances * will be reserved. * * @param lc object containing launch configuration * @return A {@link com.xerox.amazonws.ec2.ReservationDescription} describing the instances that * have been reserved. * @throws EC2Exception wraps checked exceptions */ public ReservationDescription runInstances(LaunchConfiguration lc) throws EC2Exception { Map<String, String> params = new HashMap<String, String>(); params.put("ImageId", lc.getImageId()); params.put("MinCount", "" + lc.getMinCount()); params.put("MaxCount", "" + lc.getMaxCount()); byte[] userData = lc.getUserData(); if (userData != null && userData.length > 0) { params.put("UserData", new String(Base64.encodeBase64(userData))); } params.put("AddressingType", "public"); String keyName = lc.getKeyName(); if (keyName != null && !keyName.trim().equals("")) { params.put("KeyName", keyName); } if (lc.getSecurityGroup() != null) { for (int i = 0; i < lc.getSecurityGroup().size(); i++) { params.put("SecurityGroup." + (i + 1), lc.getSecurityGroup().get(i)); } } params.put("InstanceType", lc.getInstanceType().getTypeId()); if (lc.getAvailabilityZone() != null && !lc.getAvailabilityZone().trim().equals("")) { params.put("Placement.AvailabilityZone", lc.getAvailabilityZone()); } if (lc.getKernelId() != null && !lc.getKernelId().trim().equals("")) { params.put("KernelId", lc.getKernelId()); } if (lc.getRamdiskId() != null && !lc.getRamdiskId().trim().equals("")) { params.put("RamdiskId", lc.getRamdiskId()); } if (lc.getBlockDevicemappings() != null) { for (int i = 0; i < lc.getBlockDevicemappings().size(); i++) { BlockDeviceMapping bdm = lc.getBlockDevicemappings().get(i); params.put("BlockDeviceMapping." + (i + 1) + ".VirtualName", bdm.getVirtualName()); params.put("BlockDeviceMapping." + (i + 1) + ".DeviceName", bdm.getDeviceName()); } } GetMethod method = new GetMethod(); try { RunInstancesResponse response = makeRequest(method, "RunInstances", params, RunInstancesResponse.class); ReservationDescription res = new ReservationDescription(response.getOwnerId(), response.getReservationId()); GroupSetType grp_set = response.getGroupSet(); Iterator groups_iter = grp_set.getItems().iterator(); while (groups_iter.hasNext()) { GroupItemType rsp_item = (GroupItemType) groups_iter.next(); res.addGroup(rsp_item.getGroupId()); } RunningInstancesSetType set = response.getInstancesSet(); Iterator instances_iter = set.getItems().iterator(); while (instances_iter.hasNext()) { RunningInstancesItemType rsp_item = (RunningInstancesItemType) instances_iter.next(); res.addInstance(rsp_item.getImageId(), rsp_item.getInstanceId(), rsp_item.getPrivateDnsName(), rsp_item.getDnsName(), rsp_item.getInstanceState(), rsp_item.getReason(), rsp_item.getKeyName(), rsp_item.getLaunchTime().toGregorianCalendar(), InstanceType.getTypeFromString(rsp_item.getInstanceType()), rsp_item.getPlacement().getAvailabilityZone(), rsp_item.getKernelId(), rsp_item.getRamdiskId()); } return res; } 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:osh.busdriver.mielegateway.MieleGatewayDispatcher.java
@Override public void run() { MieleDeviceList deviceList = new MieleDeviceList(); JAXBContext context;//from www. j av a 2s . c om // initialize empty device list deviceList.setDevices(Collections.<MieleDeviceHomeBusData>emptyList()); try { context = JAXBContext.newInstance(MieleDeviceList.class); } catch (JAXBException e1) { logger.logError("unable to initialize XML marshaller", e1); return; } while (true) { // fetch device list try { HttpGet httpget = new HttpGet(homebusUrl); HttpResponse response = httpclient.execute(httpget, httpcontext); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); // Process the XML try { Unmarshaller unmarshaller = context.createUnmarshaller(); deviceList = (MieleDeviceList) unmarshaller.unmarshal(instream); } catch (JAXBException e) { logger.logError("failed to unmarshall miele homebus xml", e); deviceList.setDevices(Collections.<MieleDeviceHomeBusData>emptyList()); // set empty list } finally { instream.close(); if (deviceList == null) { deviceList = new MieleDeviceList(); } if (deviceList.getDevices() == null) { deviceList.setDevices(Collections.<MieleDeviceHomeBusData>emptyList()); // set empty list } } } } catch (IOException e1) { deviceList.setDevices(Collections.<MieleDeviceHomeBusData>emptyList()); // set empty list logger.logWarning("miele@home bus driver: failed to fetch device list; " + e1.getMessage()); logger.logInfo("miele@home bus driver: failed to fetch device list", e1); } // fetch device details for (MieleDeviceHomeBusData dev : deviceList.getDevices()) { try { HttpGet httpget = new HttpGet(dev.getDetailsUrl()); HttpResponse response = httpclient.execute(httpget, httpcontext); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); // Process the XML try { Unmarshaller unmarshaller = context.createUnmarshaller(); MieleApplianceRawData deviceDetails = (MieleApplianceRawData) unmarshaller .unmarshal(instream); dev.setDeviceDetails(deviceDetails); } catch (JAXBException e) { logger.logError("failed to unmarshall miele homebus detail xml", e); } finally { instream.close(); } } } catch (IOException e2) { // ignore } } // store device state synchronized (this) { deviceData.clear(); for (MieleDeviceHomeBusData dev : deviceList.getDevices()) { deviceData.put(dev.getUid(), dev); } this.notifyAll(); } // wait a second till next state fetch try { Thread.sleep(1000); } catch (InterruptedException e3) { logger.logError("sleep interrupted - miele@home bus driver dies right now..."); break; } } }
From source file:biz.wolschon.finance.jgnucash.panels.TaxReportPanel.java
/** * @param aFile the file to write to/* w w w . j a v a 2 s .c o m*/ * @param aGran the granularity */ private void exportCSV(final File aFile, final ExportGranularities aGran) { //TODO: implement CSV-export FileWriter fw = null; try { fw = new FileWriter(aFile); // write headers List<TransactionSum> sums = mySums; fw.write("day"); for (TransactionSum transactionSum : sums) { fw.write(","); fw.write(transactionSum.getName()); } fw.write("\n"); // write data GregorianCalendar cal = new GregorianCalendar(); int add = aGran.getCalendarConstant(); DateFormat dateFormat = DateFormat.getDateInstance(); //NumberFormat numberFormat = NumberFormat.getInstance(); // we do NOT use getCurrencyInstance because it // contains a locale-specific currency-symbol for (int i = 0; i < 100; i++) { Date maxDate = cal.getTime(); fw.write(dateFormat.format(maxDate)); int transactionsCounted = 0; for (TransactionSum transactionSum : sums) { fw.write(","); try { transactionSum.setMaxDate(maxDate); FixedPointNumber value = transactionSum.getValue(); if (value != null) { //fw.write(numberFormat.format(value)); fw.write(value.toString()); } transactionsCounted += transactionSum.getTransactionsCounted(); } catch (JAXBException e) { LOGGER.error("Error calculating one of the TransactionSums", e); fw.write("ERROR"); } } fw.write("\n"); if (transactionsCounted == 0) { break; // we are walking back in time, // when there are no matching transactions, // all future runs will we a waste of time. // This happens often when add==YEAR } long old = cal.getTimeInMillis(); if (add == GregorianCalendar.MONTH) { cal.set(GregorianCalendar.DAY_OF_MONTH, 1); } if (add == GregorianCalendar.YEAR) { cal.set(GregorianCalendar.DAY_OF_MONTH, 1); cal.set(GregorianCalendar.MONTH, 1); } // usually we are in the middle of a month, // so do not skip the first day of the current // month if (i != 0 || old == cal.getTimeInMillis() || add == GregorianCalendar.DAY_OF_MONTH) { cal.add(add, -1); } } fw.close(); fw = null; } catch (IOException e) { LOGGER.error("cannot write csv-file", e); JOptionPane.showMessageDialog(this, "Cannot write CSV-file\n" + e.getMessage()); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { LOGGER.error("cannot close csv-file", e); } } for (TransactionSum transactionSum : mySums) { try { transactionSum.setMaxDate(null); } catch (JAXBException e) { LOGGER.error("cannot set maxDate back to it's original value", e); } } } }