List of usage examples for javax.xml.bind JAXBException getMessage
public String getMessage()
From source file:org.dasein.cloud.azure.compute.vm.AzureVM.java
@Override public void reboot(@Nonnull String vmId) throws CloudException, InternalException { if (vmId == null) throw new InternalException("The id of the Virtual Machine to reboot cannot be null."); ProviderContext ctx = getProvider().getContext(); if (ctx == null) { throw new AzureConfigException("No context was set for this request"); }//from w w w. java 2s.c om VirtualMachine vm = getVirtualMachine(vmId); if (vm == null) { throw new CloudException("No such virtual machine: " + vmId); } String resourceUrl = String.format(OPERATIONS_RESOURCES, vm.getTag("serviceName").toString(), vm.getTag("deploymentName").toString(), vm.getTag("roleName").toString()); AzureMethod azureMethod = new AzureMethod(getProvider()); try { azureMethod.post(resourceUrl, new Operation.RestartRoleOperation()); } catch (JAXBException e) { logger.error(e.getMessage()); throw new InternalException(e); } }
From source file:org.dasein.cloud.azure.compute.vm.AzureVM.java
@Override public void start(@Nonnull String vmId) throws InternalException, CloudException { if (vmId == null) throw new InternalException("The id of the Virtual Machine to start cannot be null."); VirtualMachine vm = getVirtualMachine(vmId); if (vm == null) { throw new CloudException("No such virtual machine: " + vmId); }/* w w w . j a v a2 s. com*/ ProviderContext ctx = getProvider().getContext(); if (ctx == null) { throw new AzureConfigException("No context was set for this request"); } String resourceUrl = String.format(OPERATIONS_RESOURCES, vm.getTag("serviceName").toString(), vm.getTag("deploymentName").toString(), vm.getTag("roleName").toString()); AzureMethod azureMethod = new AzureMethod(getProvider()); try { azureMethod.post(resourceUrl, new Operation.StartRoleOperation()); } catch (JAXBException e) { logger.error(e.getMessage()); throw new InternalException(e); } }
From source file:org.dasein.cloud.azure.compute.vm.AzureVM.java
@Override public void stop(@Nonnull String vmId, boolean force) throws InternalException, CloudException { if (vmId == null) throw new InternalException("The id of the Virtual Machine to stop cannot be null."); ProviderContext ctx = getProvider().getContext(); if (ctx == null) { throw new AzureConfigException("No context was set for this request"); }// w w w. java 2 s. c o m VirtualMachine vm = getVirtualMachine(vmId); if (vm == null) { throw new CloudException("No such virtual machine: " + vmId); } String resourceUrl = String.format(OPERATIONS_RESOURCES, vm.getTag("serviceName").toString(), vm.getTag("deploymentName").toString(), vm.getTag("roleName").toString()); AzureMethod azureMethod = new AzureMethod(getProvider()); Operation.ShutdownRoleOperation shutdownRoleOperation = new Operation.ShutdownRoleOperation(); shutdownRoleOperation.setPostShutdownAction("Stopped"); try { azureMethod.post(resourceUrl, shutdownRoleOperation); } catch (JAXBException e) { logger.error(e.getMessage()); throw new InternalException(e); } }
From source file:org.dasein.cloud.azure.compute.vm.AzureVM.java
@Override public void suspend(@Nonnull String vmId) throws CloudException, InternalException { if (vmId == null) throw new InternalException("The id of the Virtual Machine to suspend cannot be null."); ProviderContext ctx = getProvider().getContext(); if (ctx == null) { throw new AzureConfigException("No context was set for this request"); }/* w w w . jav a 2 s . co m*/ VirtualMachine vm = getVirtualMachine(vmId); if (vm == null) { throw new CloudException("No such virtual machine: " + vmId); } String resourceUrl = String.format(OPERATIONS_RESOURCES, vm.getTag("serviceName").toString(), vm.getTag("deploymentName").toString(), vm.getTag("roleName").toString()); AzureMethod azureMethod = new AzureMethod(getProvider()); Operation.ShutdownRoleOperation shutdownRoleOperation = new Operation.ShutdownRoleOperation(); shutdownRoleOperation.setPostShutdownAction("StoppedDeallocated"); try { azureMethod.post(resourceUrl, shutdownRoleOperation); } catch (JAXBException e) { logger.error(e.getMessage()); throw new InternalException(e); } }
From source file:org.dasein.cloud.azure.compute.vm.AzureVM.java
private void CreateHostedService(String description, String regionId, String label, String hostName, String affinityGroupId) throws CloudException, InternalException { CreateHostedServiceModel createHostedServiceModel = new CreateHostedServiceModel(); createHostedServiceModel.setServiceName(hostName); createHostedServiceModel.setLabel(label); createHostedServiceModel.setDescription(description); if (affinityGroupId != null) { createHostedServiceModel.setAffinityGroup(affinityGroupId); } else {/* w ww . j a v a2 s . c o m*/ createHostedServiceModel.setLocation(regionId); } try { AzureMethod method = new AzureMethod(getProvider()); String requestId = method.post(HOSTED_SERVICES, createHostedServiceModel); if (requestId != null) { AzureOperationStatus operationStatus = method.get(AzureOperationStatus.class, "/operations/" + requestId); while (operationStatus.getStatus().equalsIgnoreCase("inprogress")) { try { Thread.sleep(15000L); } catch (InterruptedException ignored) { } operationStatus = method.get(AzureOperationStatus.class, "/operations/" + requestId); } if (operationStatus.getStatus().equalsIgnoreCase("failed")) { String errorMessage = "An error occurred while trying to launch the virtual machine. Create hosted service failed."; if (operationStatus.getError() != null) { errorMessage = errorMessage + String.format("%s reason: %s", operationStatus.getError().getCode(), operationStatus.getError().getMessage()); if (errorMessage.contains("ConflictError") || errorMessage.contains("409")) { throw new CloudException(CloudErrorType.GENERAL, 409, operationStatus.getError().getCode(), errorMessage); } } throw new CloudException(errorMessage); } } } catch (JAXBException e) { logger.error(e.getMessage()); throw new CloudException(e); } }
From source file:org.dasein.cloud.azure.compute.vm.AzureVM.java
private String CreateDeployment(VMLaunchOptions options, String storageEndpoint, AzureMachineImage image, String label, String hostName, String deploymentSlot, Subnet subnet, String vlanName, String username, String password) throws CloudException, InternalException { DeploymentModel deploymentModel = new DeploymentModel(); deploymentModel.setName(hostName);//w w w . jav a2 s. c o m deploymentModel.setDeploymentSlot(deploymentSlot); deploymentModel.setLabel(label); DeploymentModel.RoleModel roleModel = new DeploymentModel.RoleModel(); roleModel.setRoleName(hostName); roleModel.setRoleType("PersistentVMRole"); ArrayList<ConfigurationSetModel> configurations = new ArrayList<ConfigurationSetModel>(); if (image.getPlatform().isWindows()) { ConfigurationSetModel windowsConfigurationSetModel = new ConfigurationSetModel(); windowsConfigurationSetModel.setConfigurationSetType("WindowsProvisioningConfiguration"); windowsConfigurationSetModel.setType("WindowsProvisioningConfigurationSet"); windowsConfigurationSetModel.setComputerName(hostName); windowsConfigurationSetModel.setAdminPassword(password); windowsConfigurationSetModel.setEnableAutomaticUpdates("true"); windowsConfigurationSetModel.setTimeZone("UTC"); windowsConfigurationSetModel.setAdminUsername(username); if (options.getUserData() != null && !options.getUserData().equals("")) windowsConfigurationSetModel .setCustomData(new String(Base64.encodeBase64(options.getUserData().getBytes()))); configurations.add(windowsConfigurationSetModel); } else { ConfigurationSetModel unixConfigurationSetModel = new ConfigurationSetModel(); unixConfigurationSetModel.setConfigurationSetType("LinuxProvisioningConfiguration"); unixConfigurationSetModel.setType("LinuxProvisioningConfigurationSet"); unixConfigurationSetModel.setHostName(hostName); unixConfigurationSetModel.setUserName(username); unixConfigurationSetModel.setUserPassword(password); unixConfigurationSetModel.setDisableSshPasswordAuthentication("false"); if (options.getUserData() != null && !options.getUserData().equals("")) unixConfigurationSetModel .setCustomData(new String(Base64.encodeBase64(options.getUserData().getBytes()))); configurations.add(unixConfigurationSetModel); } ConfigurationSetModel networkConfigurationSetModel = new ConfigurationSetModel(); networkConfigurationSetModel.setConfigurationSetType("NetworkConfiguration"); ArrayList<ConfigurationSetModel.InputEndpointModel> inputEndpointModels = new ArrayList<ConfigurationSetModel.InputEndpointModel>(); if (image.getPlatform().isWindows()) { ConfigurationSetModel.InputEndpointModel inputEndpointModel = new ConfigurationSetModel.InputEndpointModel(); inputEndpointModel.setLocalPort("3389"); inputEndpointModel.setName("RemoteDesktop"); inputEndpointModel.setPort("58622"); inputEndpointModel.setProtocol("TCP"); inputEndpointModels.add(inputEndpointModel); } else { ConfigurationSetModel.InputEndpointModel inputEndpointModel = new ConfigurationSetModel.InputEndpointModel(); inputEndpointModel.setLocalPort("22"); inputEndpointModel.setName("SSH"); inputEndpointModel.setPort("22"); inputEndpointModel.setProtocol("TCP"); inputEndpointModels.add(inputEndpointModel); } networkConfigurationSetModel.setInputEndpoints(inputEndpointModels); if (subnet != null) { ArrayList<String> subnets = new ArrayList<String>(); subnets.add(subnet.getName()); networkConfigurationSetModel.setSubnetNames(subnets); } configurations.add(networkConfigurationSetModel); roleModel.setConfigurationsSets(configurations); if (image.getAzureImageType().equalsIgnoreCase("osimage")) { DeploymentModel.OSVirtualHardDiskModel osVirtualHardDiskModel = new DeploymentModel.OSVirtualHardDiskModel(); osVirtualHardDiskModel.setHostCaching("ReadWrite"); osVirtualHardDiskModel.setDiskLabel("OS"); String vhdFileName = String.format("%s-%s-%s-%s.vhd", hostName, hostName, hostName, new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())); osVirtualHardDiskModel.setMediaLink(storageEndpoint + "vhds/" + vhdFileName); osVirtualHardDiskModel.setSourceImageName(options.getMachineImageId()); roleModel.setOsVirtualDisk(osVirtualHardDiskModel); } else if (image.getAzureImageType().equalsIgnoreCase("vmimage")) { roleModel.setVmImageName(image.getProviderMachineImageId()); } roleModel.setRoleSize(options.getStandardProductId()); ArrayList<DeploymentModel.RoleModel> roles = new ArrayList<DeploymentModel.RoleModel>(); roles.add(roleModel); deploymentModel.setRoles(roles); if (options.getVlanId() != null) { deploymentModel.setVirtualNetworkName(vlanName); } try { AzureMethod method = new AzureMethod(getProvider()); return method.post(HOSTED_SERVICES + "/" + hostName + "/deployments", deploymentModel); } catch (JAXBException e) { logger.error(e.getMessage()); throw new CloudException(e); } }
From source file:de.tu_dortmund.ub.api.paia.core.PaiaCoreEndpoint.java
/** * * @param httpServletRequest/*w w w .jav a 2 s .com*/ * @param httpServletResponse * @throws IOException */ private void authorize(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String format, DocumentList documents) throws IOException { httpServletResponse.setHeader("Access-Control-Allow-Origin", config.getProperty("Access-Control-Allow-Origin")); httpServletResponse.setHeader("Cache-Control", config.getProperty("Cache-Control")); ObjectMapper mapper = new ObjectMapper(); // Error handling mit suppress_response_codes=true if (httpServletRequest.getParameter("suppress_response_codes") != null) { httpServletResponse.setStatus(HttpServletResponse.SC_OK); } // Error handling mit suppress_response_codes=false (=default) else { httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError( this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_UNAUTHORIZED))); requestError.setCode(HttpServletResponse.SC_UNAUTHORIZED); requestError.setDescription(this.config .getProperty("error." + Integer.toString(HttpServletResponse.SC_UNAUTHORIZED) + ".description")); requestError.setErrorUri( this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_UNAUTHORIZED) + ".uri")); // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(RequestError.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse httpServletResponse.setContentType("application/xml;charset=UTF-8"); m.marshal(requestError, httpServletResponse.getWriter()); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } } // JSON-Ausgabe mit Jackson if (format.equals("json")) { httpServletResponse.setContentType("application/json;charset=UTF-8"); mapper.writeValue(httpServletResponse.getWriter(), requestError); } // html > redirect zu "PAIA auth - login" mit redirect_url = "PAIA core - service" if (format.equals("html")) { httpServletResponse.setContentType("text/html;charset=UTF-8"); if (documents != null) { // set Cookie with urlencoded DocumentList-JSON StringWriter stringWriter = new StringWriter(); mapper.writeValue(stringWriter, documents); Cookie cookie = new Cookie("PaiaServiceDocumentList", URLEncoder.encode(stringWriter.toString(), "UTF-8")); if (this.config.getProperty("service.cookie.domain") != null && !this.config.getProperty("service.cookie.domain").equals("")) { cookie.setDomain(this.config.getProperty("service.cookie.domain")); } cookie.setMaxAge(-1); cookie.setPath("/"); httpServletResponse.addCookie(cookie); } //String redirect_url = "http://" + httpServletRequest.getServerName() + ":" + httpServletRequest.getServerPort() + this.config.getProperty("service.endpoint.core") + httpServletRequest.getPathInfo(); String redirect_url = this.config.getProperty("service.base_url") + this.config.getProperty("service.endpoint.core") + httpServletRequest.getPathInfo(); if (httpServletRequest.getQueryString() != null && !httpServletRequest.getQueryString().equals("")) { redirect_url += "?" + httpServletRequest.getQueryString(); } this.logger.info("redirect_url = " + redirect_url); //String login_url = "http://" + httpServletRequest.getServerName() + ":" + httpServletRequest.getServerPort() + this.config.getProperty("service.endpoint.auth") + "/login?redirect_url=" + redirect_url; String login_url = this.config.getProperty("service.base_url") + this.config.getProperty("service.endpoint.auth") + "/login?redirect_url=" + redirect_url; this.logger.info("login_url = " + login_url); httpServletResponse.sendRedirect(login_url); } }
From source file:com.intuit.tank.service.impl.v1.script.ScriptServiceV1.java
/** * @{inheritDoc/* www. j a v a 2s . c o m*/ */ @Override public Response convertScript(FormDataMultiPart formData) { ScriptUploadRequest request = null; InputStream is = null; Map<String, List<FormDataBodyPart>> fields = formData.getFields(); ScriptDao dao = new ScriptDao(); for (Entry<String, List<FormDataBodyPart>> entry : fields.entrySet()) { String formName = entry.getKey(); LOG.debug("Entry name: " + formName); for (FormDataBodyPart part : entry.getValue()) { MediaType mediaType = part.getMediaType(); if (MediaType.APPLICATION_XML_TYPE.equals(mediaType) || MediaType.APPLICATION_JSON_TYPE.equals(mediaType)) { request = part.getEntityAs(ScriptUploadRequest.class); } else if (MediaType.TEXT_PLAIN_TYPE.equals(mediaType)) { String s = part.getEntityAs(String.class); if ("xmlString".equalsIgnoreCase(formName)) { try { JAXBContext ctx = JAXBContext .newInstance(ScriptUploadRequest.class.getPackage().getName()); request = (ScriptUploadRequest) ctx.createUnmarshaller().unmarshal(new StringReader(s)); } catch (JAXBException e) { throw new RuntimeException(e); } } } else if (MediaType.APPLICATION_OCTET_STREAM_TYPE.equals(mediaType)) { // get the file is = part.getValueAs(InputStream.class); } } } ResponseBuilder responseBuilder = null; if (request == null) { responseBuilder = Response.status(Status.BAD_REQUEST); responseBuilder.entity("Requests to store Scripts must include a ScriptUploadRequest."); } else { Script script = descriptorToScript(dao, request.getScript()); if (is != null) { try { ScriptProcessor scriptProcessor = new ServletInjector<ScriptProcessor>() .getManagedBean(servletContext, ScriptProcessor.class); List<ScriptStep> scriptSteps = scriptProcessor.getScriptSteps( new BufferedReader(new InputStreamReader(is)), getFilters(request.getFilterIds())); scriptProcessor.setScriptSteps(script, scriptSteps); script = dao.saveOrUpdate(script); } finally { IOUtils.closeQuietly(is); } } try { URI location = uriInfo.getBaseUriBuilder().path(ScriptService.class) .path(ScriptService.class.getMethod("getScript", Integer.class)).build(script.getId()); responseBuilder = Response.created(location); } catch (Exception e) { LOG.error("Error building uri: " + e.getMessage(), e); throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); } } return responseBuilder.build(); }
From source file:net.emotivecloud.scheduler.drp4one.DRP4OVF.java
private OCAComputeWrapper parseOcaCompute(String s) { OCAComputeWrapper rv = null;// w w w . j av a 2s . c o m StringBuilder cause = new StringBuilder(); try { rv = OCAComputeWrapperFactory.parse(s); } catch (SAXException se) { throw new DRPOneException("XML Parsing error", se, StatusCodes.INTERNAL); } catch (JAXBException e) { if (e instanceof PropertyException) { cause.append("Access to property failed: " + e.getErrorCode()); } else if (e instanceof MarshalException) { cause.append("Marshalling failed: " + e.getLocalizedMessage()); } else if (e instanceof UnmarshalException) { cause.append("Unmarshalling failed: " + e.getCause()); } else if (e instanceof ValidationException) { cause.append("XML Validation failed: " + e.getErrorCode()); } else { cause.append("Unespected " + e.getErrorCode()); cause.append(e.getClass().getName()); cause.append(": "); } cause.append(e.getMessage()); log.error(cause.toString()); if (log.isTraceEnabled()) { log.trace(cause, e); } throw new DRPOneException(cause.toString(), e, StatusCodes.ONE_FAILURE); } return rv; }
From source file:net.emotivecloud.scheduler.drp4one.DRP4OVF.java
private OCAComputeListWrapper parseOcaComputeList(String s) { OCAComputeListWrapper rv = null;/*from w w w. j a v a 2s. c o m*/ StringBuilder cause = new StringBuilder(); try { rv = OCAComputeListWrapperFactory.parseList(s); } catch (SAXException se) { throw new DRPOneException("XML Parsing error", se, StatusCodes.INTERNAL); } catch (JAXBException e) { if (e instanceof PropertyException) { cause.append("Access to property failed: " + e.getErrorCode()); } else if (e instanceof MarshalException) { cause.append("Marshalling failed: " + e.getLocalizedMessage()); } else if (e instanceof UnmarshalException) { cause.append("Unmarshalling failed: " + e.getCause()); } else if (e instanceof ValidationException) { cause.append("XML Validation failed: " + e.getErrorCode()); } else { cause.append("Unespected " + e.getErrorCode()); cause.append(e.getClass().getName()); cause.append(": "); } cause.append(e.getMessage()); log.error(cause.toString()); if (log.isTraceEnabled()) { log.trace(cause, e); } throw new DRPOneException(cause.toString(), e, StatusCodes.ONE_FAILURE); } return rv; }