List of usage examples for javax.xml.bind JAXBException getMessage
public String getMessage()
From source file:ca.phon.ipamap.IpaMap.java
/** * Load favorites IPA map data/*from w w w. j av a2 s .com*/ */ private static IpaGrids getFavData() { final ObjectFactory factory = new ObjectFactory(); final String favXML = PrefHelper.get(FAVORITES_PROP, null); // try to load file if (favGrid == null && favXML != null) { try { JAXBContext ctx = JAXBContext.newInstance(factory.getClass()); Unmarshaller unmarshaller = ctx.createUnmarshaller(); favGrid = (IpaGrids) unmarshaller.unmarshal(new ByteArrayInputStream(favXML.getBytes())); } catch (JAXBException e) { e.printStackTrace(); LOGGER.severe(e.getMessage()); } } // create a default grid if still null if (favGrid == null) { favGrid = factory.createIpaGrids(); Grid fg = factory.createGrid(); fg.setCellheight(10); fg.setCellwidth(10); fg.setCols(MAX_GRID_COLS); fg.setRows(2); fg.setName("Favorites"); favGrid.getGrid().add(fg); } return favGrid; }
From source file:eu.eco2clouds.scheduler.accounting.client.AccountingClientHC.java
@Override public List<Co2> getCo2OfTestbedForInterval(Testbed testbed, long startTime, long endTime) { Boolean exception = false;//from ww w .j av a2s . c o m String testbedsUrl = url + "/testbeds/" + testbed.getName() + "/monitoring/co2?startTime=" + startTime + "&endTime=" + endTime; String response = getMethod(testbedsUrl, null, null, exception); logger.debug("PAYLOAD: " + response); Collection collection = new Collection(); try { JAXBContext jaxbContext = JAXBContext.newInstance(Collection.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); collection = (Collection) jaxbUnmarshaller.unmarshal(new StringReader(response)); } catch (JAXBException e) { logger.warn("Error trying to parse returned list of testbed: " + url + "/testbeds/" + testbed.getName() + "/monitoring/co2?startTime=" + startTime + "&endTime=" + endTime + " Exception: " + e.getMessage()); exception = true; } if (exception) return new ArrayList<Co2>(); List<Co2> co2s = new ArrayList<Co2>(); for (TestbedMonitoring testbedMonitoring : collection.getItems().getTestbedMonitorings()) co2s.add(testbedMonitoring.getCo2()); return co2s; }
From source file:eu.eco2clouds.scheduler.accounting.client.AccountingClientHC.java
@Override public List<HostMonitoring> getHostMonitoringStatus(Testbed testbed, String hostname, long startTime, long endTime) { Boolean exception = false;/*from ww w . j a v a 2 s . co m*/ String testbedsUrl = url + "/testbeds/" + testbed.getName() + "/hosts/" + hostname + "/monitoring?startTime=" + startTime + "&endTime=" + endTime; String response = getMethod(testbedsUrl, null, null, exception); logger.debug("PAYLOAD: " + response); Collection collection = new Collection(); try { JAXBContext jaxbContext = JAXBContext.newInstance(Collection.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); collection = (Collection) jaxbUnmarshaller.unmarshal(new StringReader(response)); } catch (JAXBException e) { logger.warn("Error trying to parse returned list of testbed: " + url + "/testbeds/" + testbed.getName() + "/hosts/" + hostname + "/monitoring?startTime=" + startTime + "&endTime=" + endTime + " Exception: " + e.getMessage()); exception = true; } if (exception) return new ArrayList<HostMonitoring>(); return collection.getItems().getHostMonitorings(); }
From source file:de.iai.ilcd.services.AbstractDataSetResource.java
/** * Process uploaded XML as input stream//from ww w .ja v a 2 s. c om * * @param inputStream * stream with XML * @param stockUuid * UUID of the root stock to import to (or <code>null</code> for default * @return response for client */ private Response importXml(InputStream inputStream, String stockUuid) { try { final CommonDataStockDao dao = new CommonDataStockDao(); AbstractDataStock ads; if (StringUtils.isBlank(stockUuid)) { ads = dao.getById(IDataStockMetaData.DEFAULT_DATASTOCK_ID); } else { ads = dao.getDataStockByUuid(stockUuid); if (!(ads instanceof RootDataStock)) { return Response.status(Response.Status.PRECONDITION_FAILED) .entity("Data sets can only be imported into root data stocks!").type("text/plain") .build(); } } if (ads == null) { return Response.status(Response.Status.BAD_REQUEST).entity("Invalid root data stock UUID specified") .type("text/plain").build(); } SecurityUtil.assertCanImport(ads); PostResourceHelper postHelper = new PostResourceHelper(); final Response resp = postHelper.importByFileUpload(this.modelType, inputStream, (RootDataStock) ads); if (resp.getStatus() != Status.OK.getStatusCode()) { return resp; } else { final DataStockVO dsVo = DataStockListAdapter.getServiceApiVo(ads); final StreamingOutput sout = new StreamingOutput() { @Override public void write(OutputStream out) throws IOException, WebApplicationException { ServiceDAO sDao = new ServiceDAO(); try { sDao.marshal(dsVo, out); } catch (JAXBException e) { if (e.getCause().getCause() instanceof SocketException) { AbstractDataSetResource.LOGGER.warn("exception occurred during marshalling - " + e); } else { AbstractDataSetResource.LOGGER.error("error marshalling data", e); } } } }; return Response.ok(sout).type("application/xml").build(); } } catch (IllegalArgumentException e) { return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).type("text/plain").build(); } catch (AuthorizationException e) { return Response.status(Response.Status.FORBIDDEN).entity(e.getMessage()).type("text/plain").build(); } }
From source file:be.fedict.eid.tsl.TrustServiceList.java
private Node marshallQualifyingProperties(Document document, QualifyingPropertiesType qualifyingProperties) { Node marshallNode = document.createElement("marshall-node"); try {//from w ww. ja va2s.c o m JAXBContext jaxbContext = JAXBContext.newInstance(be.fedict.eid.tsl.jaxb.xades.ObjectFactory.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new TSLNamespacePrefixMapper()); marshaller.marshal(this.xadesObjectFactory.createQualifyingProperties(qualifyingProperties), marshallNode); } catch (JAXBException e) { throw new RuntimeException("JAXB error: " + e.getMessage(), e); } Node qualifyingPropertiesNode = marshallNode.getFirstChild(); return qualifyingPropertiesNode; }
From source file:de.tu_dortmund.ub.api.paia.auth.PaiaAuthEndpoint.java
/** * * @param httpServletRequest//from www .ja v a2 s. c o m * @param httpServletResponse * @throws IOException */ private void authorize(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String format) 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 auth - service" if (format.equals("html")) { httpServletResponse.setContentType("text/html;charset=UTF-8"); String redirect_url = this.config.getProperty("service.base_url") + this.config.getProperty("service.endpoint.auth") + 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:net.emotivecloud.scheduler.drp4ost.DRP4OST.java
private OVFWrapper parse(String ovfXml) { OVFWrapper rv = null;//from w w w .j a v a 2 s . c om StringBuilder cause = new StringBuilder(); try { rv = OVFWrapperFactory.parse(ovfXml); } 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()); throw new DRPOSTException(cause.toString(), e, StatusCodes.XML_PROBLEM); } catch (OVFException e) { cause.append("Problems parsing OVF file: "); cause.append(e.getMessage()); throw new DRPOSTException(cause.toString(), e, StatusCodes.XML_PROBLEM); } return rv; }
From source file:de.tu_dortmund.ub.api.paaa.PaaaEndpoint.java
private void sendRequestError(HttpServletResponse httpServletResponse, RequestError requestError, String format) {/*w w w . j a v a 2s.c o m*/ ObjectMapper mapper = new ObjectMapper(); httpServletResponse.setHeader("WWW-Authentificate", "Bearer"); httpServletResponse.setHeader("WWW-Authentificate", "Bearer realm=\"PAAA\""); httpServletResponse.setContentType("application/json"); try { // 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); } } catch (Exception e) { e.printStackTrace(); } }
From source file:de.tu_dortmund.ub.api.paaa.PaaaEndpoint.java
/** * * @param httpServletRequest/*w w w . j av a 2 s. c om*/ * @param httpServletResponse * @throws IOException */ private void authorize(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String format) throws IOException { 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); } }