List of usage examples for java.lang StackTraceElement toString
public String toString()
From source file:org.evosuite.utils.generic.GenericClass.java
/** {@inheritDoc} */ @Override// w w w . ja v a 2 s. c o m public String toString() { if (type == null) { LoggingUtils.getEvoLogger().info("Type is null for raw class " + rawClass); for (StackTraceElement elem : Thread.currentThread().getStackTrace()) { LoggingUtils.getEvoLogger().info(elem.toString()); } assert (false); } return type.toString(); }
From source file:de.decoit.visa.topology.TopologyStorage.java
/** * Layout the topology by using the de.decoit.visa.gridlayout.GridLayout * class. By default, the 'neato' executable will be used for layouting. If * any nodes with fixed positions are detected, the 'fdp' executable will be * used to get better results. All existing switches and VMs will be used as * nodes, all cables as edges. Already positioned nodes will not be moved. *//*from w w w.ja v a 2 s. com*/ public void layoutTopology() { try { // Layout the subgrids of all component groups HashSet<ComponentGroup> processedGroups = new HashSet<>(); for (Map.Entry<String, ComponentGroup> groupEntry : storage.entrySet()) { // Process all groups except the global group 0.0.0.0 if (!groupEntry.getValue().isGlobalGroup()) { // neato is the default layouter String command = "neato"; // Create a new layouter GridLayout layout = new GridLayout(groupEntry.getValue().subGridDimensions); // Add all components of this group to the layouter for (NetworkComponent nc : groupEntry.getValue().componentList) { // Use fdp layouter if there are nodes with fixed // positions if (!layout.addComponent(nc)) { command = "fdp"; } } for (NetworkCable nc : groupEntry.getValue().cables) { layout.addCable(nc); } for (Map.Entry<String, GroupSwitch> gsEntry : groupEntry.getValue().groupSwitches.entrySet()) { // Use fdp layouter if there are nodes with fixed // positions if (!layout.addGroupSwitch(gsEntry.getValue())) { command = "fdp"; } } // Run the layouter layout.run(command); // Add the current group to the processed groups set processedGroups.add(groupEntry.getValue()); } } // Layout the base layer group 0.0.0.0 // neato is the default layouter String command = "neato"; // Create a new layouter GridLayout layout = new GridLayout(TEBackend.getGridDimensions()); // Add all components to the layouter for (NetworkComponent nc : getComponentGroupByName("0.0.0.0").componentList) { // Use fdp layouter if there are nodes with fixed positions if (!layout.addComponent(nc)) { command = "fdp"; } } for (NetworkCable nc : getComponentGroupByName("0.0.0.0").cables) { if (nc.getLeft().getComponentGroup().equals(nc.getRight().getComponentGroup())) { layout.addCable(nc); } } // Add all group objects to the layouter for (ComponentGroup cg : processedGroups) { // Use fdp layouter if there are nodes with fixed positions if (!layout.addComponentGroup(cg)) { command = "fdp"; } } // Run the layouter layout.run(command); } catch (IOException ex) { StringBuilder sb = new StringBuilder("Caught: ["); sb.append(ex.getClass().getSimpleName()); sb.append("] "); sb.append(ex.getMessage()); log.error(sb.toString()); if (log.isDebugEnabled()) { for (StackTraceElement ste : ex.getStackTrace()) { log.debug(ste.toString()); } } } }
From source file:org.nightlabs.jfire.trade.Article.java
public void setReleaseException(Throwable t) { if (t == null) { this.releaseExceptionClass = null; this.releaseExceptionMessage = null; this.releaseExceptionStackTrace = null; return;//from w w w . j av a2 s . c o m } Throwable root = ExceptionUtils.getRootCause(t); if (root == null) root = t; StackTraceElement ste = root.getStackTrace()[0]; this.releaseExceptionClass = root.getClass().getName(); this.releaseExceptionMessage = root.getLocalizedMessage(); this.releaseExceptionStackTrace = ste.toString(); }
From source file:de.tu_dortmund.ub.api.daia.DaiaOpenUrlEndpoint.java
private void provideService(HttpServletRequest request, HttpServletResponse response, String format, HashMap<String, String> latinParameters, boolean isTUintern, boolean isUBintern, boolean is52bIBA) throws IOException { String openurl = ""; try {/* w w w . ja v a 2 s. co m*/ // build openurl for (String k : latinParameters.keySet()) { // repeat input-openurl if (!k.equals("format") && !k.equals("system") && !latinParameters.get(k).equals("")) { if (latinParameters.get(k).contains("/>")) { latinParameters.put(k, latinParameters.get(k).replaceAll("/>", "")); } if (latinParameters.get(k).contains(">")) { latinParameters.put(k, latinParameters.get(k).replaceAll(">", "")); } String prefix = ""; if (!k.startsWith("rft")) { prefix = "rft."; } String value = ""; if (k.contains("title") || k.contains("au")) { value = latinParameters.get(k); } else if (k.contains("issn") && !latinParameters.get(k).equals("")) { if (latinParameters.get(k).contains("-")) { value = latinParameters.get(k); } else { value = latinParameters.get(k).subSequence(0, 4) + "-" + latinParameters.get(k).subSequence(4, 8); } } else { value = latinParameters.get(k); } openurl += "&" + prefix + k + "=" + URLEncoder.encode(value, "UTF-8"); } } this.logger.debug("\n" + "\tOpenURL-Parameter = " + this.config.getProperty("linkresolver.baseurl") + this.config.getProperty("linkresolver.parameters") + openurl); ArrayList<Document> daiaDocuments = new ArrayList<Document>(); // falls OpenURL contains isbn: Anfrage an "normalen DaiaService Endpoint String isbn = ""; if (latinParameters.get("rft.isbn") != null && !latinParameters.get("rft.isbn").equals("")) { isbn = latinParameters.get("rft.isbn"); } else if (latinParameters.get("isbn") != null && !latinParameters.get("isbn").equals("")) { isbn = latinParameters.get("isbn"); } else if (latinParameters.get("id") != null && latinParameters.get("id").contains("isbn:")) { isbn = latinParameters.get("id").split(":")[1]; } this.logger.debug("ISBN = " + isbn); if (!isbn.equals("")) { if (Lookup.lookupAll(IntegratedLibrarySystem.class).size() > 0) { // erst DAIA isbn fragen if (isbn.contains("; ")) { isbn = isbn.replaceAll("; ", ","); } String daiaUrl = "http://" + request.getServerName() + ":" + request.getServerPort() + "/daia/?id=isbn:" + isbn; this.logger.debug("daiaUrl = " + daiaUrl); CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet(daiaUrl); httpGet.addHeader("Accept", "application/xml"); CloseableHttpResponse httpResponse = httpclient.execute(httpGet); try { int statusCode = httpResponse.getStatusLine().getStatusCode(); HttpEntity httpEntity = httpResponse.getEntity(); switch (statusCode) { case 200: { JAXBContext jaxbContext = JAXBContext.newInstance(Daia.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); Daia daia = (Daia) unmarshaller.unmarshal(httpEntity.getContent()); if (daia.getDocument() != null) { daiaDocuments.addAll(daia.getDocument()); } break; } default: { // TODO Evaluieren: Das mssten die Flle sein, in denen E-Books in der Knowledgebase eingetragen sind if (Lookup.lookupAll(LinkResolver.class).size() > 0) { Document daiaDocument = null; LinkResolver linkResolver = Lookup.lookup(LinkResolver.class); // init Linkresolver linkResolver.init(this.config); // get items ArrayList<Document> linkresolverDocument = linkResolver.items("openurl", openurl); if (linkresolverDocument != null && linkresolverDocument.size() > 0) { daiaDocument = new Document(); daiaDocument.setId("urn:isbn:" + isbn); if (daiaDocument.getItem() == null || daiaDocument.getItem().size() == 0) { daiaDocument.setItem(linkresolverDocument.get(0).getItem()); } else { daiaDocument.getItem().addAll(linkresolverDocument.get(0).getItem()); } if (daiaDocument != null) { daiaDocuments.add(daiaDocument); } } } } } EntityUtils.consume(httpEntity); } finally { httpResponse.close(); } } } else { // Wenn JOP registriert ist if (Lookup.lookupAll(JournalOnlinePrintService.class).size() > 0) { // build OpenURL for JOP String issn = ""; if (latinParameters.get("rft.issn") != null && !latinParameters.get("rft.issn").equals("")) { issn = latinParameters.get("rft.issn"); } else if (latinParameters.get("issn") != null && !latinParameters.get("issn").equals("")) { issn = latinParameters.get("issn"); } if (latinParameters.get("rft.eissn") != null && !latinParameters.get("rft.eissn").equals("")) { issn = latinParameters.get("rft.eissn"); } else if (latinParameters.get("eissn") != null && !latinParameters.get("eissn").equals("")) { issn = latinParameters.get("eissn"); } else if (latinParameters.get("id") != null && latinParameters.get("id").contains("issn:")) { issn = latinParameters.get("id").split(":")[1]; } this.logger.debug("ISSN = " + issn); String jop_openurl = ""; for (String k : latinParameters.keySet()) { // mit rft if ((latinParameters.keySet().contains("rft.atitle") || latinParameters.keySet().contains("atitle")) && k.equals("rft.date") && !latinParameters.get(k).equals("")) { jop_openurl += "&date=" + latinParameters.get(k); } if (k.equals("rft.volume") && !latinParameters.get(k).equals("")) { jop_openurl += "&volume=" + latinParameters.get(k); } if (k.equals("rft.issue") && !latinParameters.get(k).equals("")) { jop_openurl += "&issue=" + latinParameters.get(k); } // ohne rft if ((latinParameters.keySet().contains("rft.atitle") || latinParameters.keySet().contains("atitle")) && k.equals("date") && !latinParameters.get(k).equals("")) { jop_openurl += "&date=" + latinParameters.get(k); } if (k.equals("volume") && !latinParameters.get(k).equals("")) { jop_openurl += "&volume=" + latinParameters.get(k); } if (k.equals("issue") && !latinParameters.get(k).equals("")) { jop_openurl += "&issue=" + latinParameters.get(k); } } if (!issn.equals("")) { if (issn.contains("-")) { jop_openurl += "&issn=" + issn; } else { jop_openurl += "&issn=" + issn.subSequence(0, 4) + "-" + issn.subSequence(4, 8); } } if (latinParameters.keySet().contains("rft.atitle") || latinParameters.keySet().contains("atitle")) { jop_openurl += "&genre=article"; } else { jop_openurl += "&genre=journal"; } this.logger.debug("\n" + jop_openurl + "\tOpenURL-Parameter (JOP) = " + this.config.getProperty("jop.url.openurl") + jop_openurl); if (!jop_openurl.equals("&genre=journal") && (jop_openurl.contains("&title=") || jop_openurl.contains("&issn="))) { // get data try { JournalOnlinePrintService journalOnlinePrintService = Lookup .lookup(JournalOnlinePrintService.class); // init JOP journalOnlinePrintService.init(this.config); // get items ArrayList<de.tu_dortmund.ub.api.daia.jop.model.Document> jopDocuments = journalOnlinePrintService .items("openurl", jop_openurl); if (jopDocuments != null && jopDocuments.size() > 0) { Document daiaDocument = new Document(); this.logger.debug("JOP hits: " + jopDocuments.size()); if (jopDocuments.get(0).getId() != null && jopDocuments.get(0).getHref() != null) { daiaDocument.setId(jopDocuments.get(0).getId()); daiaDocument.setHref(jopDocuments.get(0).getHref()); } else { daiaDocument.setId("urn:issn:" + issn); } // print if (jopDocuments.get(0).getItem() != null && jopDocuments.get(0).getItem().size() > 0) { daiaDocument.setItem(jopDocuments.get(0).getItem()); } // digital if (jopDocuments.get(0).isExistsDigitalItems() && Lookup.lookupAll(LinkResolver.class).size() > 0) { // TODO define a boolean variable for executing a linkresolver request // TODO auslagern! LinkResolver linkResolver = Lookup.lookup(LinkResolver.class); // init Linkresolver linkResolver.init(this.config); // get items ArrayList<Document> linkresolverDocument = linkResolver.items("openurl", openurl); if (linkresolverDocument != null && linkresolverDocument.size() > 0 && linkresolverDocument.get(0).getItem().size() >= jopDocuments.get(0) .getCountDigitlItems()) { if (daiaDocument.getItem() == null || daiaDocument.getItem().size() == 0) { daiaDocument.setItem(linkresolverDocument.get(0).getItem()); } else { daiaDocument.getItem().addAll(linkresolverDocument.get(0).getItem()); } } else { // TODO Ticket 11679 // E-Mail an katalogplus@ub.tu-dortmund.de mit Betreff-Prefix [Content] boolean isNatLic = true; if (isNatLic) { if (!issn.equals("")) { // request JOP again with only ISSN jopDocuments = journalOnlinePrintService.eonly("issn", issn); if (jopDocuments != null && jopDocuments.size() > 0) { this.logger.debug("JOP hits: " + jopDocuments.size()); if (daiaDocument.getItem() == null || daiaDocument.getItem().size() == 0) { daiaDocument.setItem(jopDocuments.get(0).getItem()); } else { if (jopDocuments.get(0).getItem() != null) { daiaDocument.getItem() .addAll(jopDocuments.get(0).getItem()); } else { // Error-E-Mail "JOP<>LinkResolver: Not an NatLic" Mailer mailer = new Mailer( this.config.getProperty("service.mailer.conf")); try { int cnt = 0; if (linkresolverDocument != null) { cnt = linkresolverDocument.get(0).getItem() .size(); } mailer.postMail( "[DAIAopenurl] JOP-Document ohne Items ", "JOP-Link " + jopDocuments.get(0) .getCountDigitlItems() + ": " + this.config.getProperty( "jop.url.openurl") + jop_openurl + ".\n"); } catch (MessagingException e) { this.logger.error(e.getMessage(), e.getCause()); this.logger.debug("[DAIAopenurl] CONTENT-ERROR"); this.logger.debug("OpenUrl: " + openurl + "\n\n\tJOP-URL: " + jop_openurl); } if (daiaDocument.getItem() == null || daiaDocument.getItem().size() == 0) { daiaDocument = null; } } } } } else { // Error-E-Mail "JOP<>LinkResolver: Not an NatLic" Mailer mailer = new Mailer( this.config.getProperty("service.mailer.conf")); try { int cnt = 0; if (linkresolverDocument != null) { cnt = linkresolverDocument.get(0).getItem().size(); } mailer.postMail( "[DAIAopenurl] JOP<>LinkResolver: NatLic without ISSN ", "Laut ZDB/EZB gibt es " + jopDocuments.get(0).getCountDigitlItems() + "-mal elektronischen Bestand (vgl. " + this.config.getProperty("jop.url.openurl") + jop_openurl + ").\n" + "Laut 360 Link aber " + cnt + "-mal (vgl. " + this.config .getProperty("linkresolver.baseurl") + this.config .getProperty("linkresolver.parameters") + openurl + ")."); } catch (MessagingException e) { this.logger.error(e.getMessage(), e.getCause()); this.logger.debug("[DAIAopenurl] CONTENT-ERROR"); this.logger.debug("OpenUrl: " + openurl + "\n\n\tJOP-URL: " + jop_openurl); } if (daiaDocument.getItem() == null || daiaDocument.getItem().size() == 0) { daiaDocument = null; } } } else { // Hier kann man nix machen! } } } if (daiaDocument != null) { daiaDocuments.add(daiaDocument); } } } catch (LinkResolverException e) { // daiaDocuments bleibt leer this.logger.error("[DaiaService OpenUrl Endpoint] Exception: " + HttpServletResponse.SC_SERVICE_UNAVAILABLE + " Service unavailable (LinkResolver)."); this.logger.error(e.getMessage(), e.getCause()); for (StackTraceElement stackTraceElement : e.getStackTrace()) { this.logger.error("\t" + stackTraceElement.toString()); } Mailer mailer = new Mailer(this.config.getProperty("service.mailer.conf")); try { mailer.postMail( "[DaiaService OpenUrl Endpoint] Exception: " + HttpServletResponse.SC_SERVICE_UNAVAILABLE + " Service unavailable (LinkResolver).", e.getMessage() + "\n" + this.config.getProperty("linkresolver.baseurl") + this.config.getProperty("linkresolver.parameters") + openurl); } catch (MessagingException e1) { this.logger.error(e1.getMessage(), e1.getCause()); } } catch (JOPException e) { // daiaDocuments bleibt leer this.logger.error("[DaiaService OpenUrl Endpoint] Exception: " + HttpServletResponse.SC_SERVICE_UNAVAILABLE + " Service unavailable (Journals Online & Print)."); this.logger.error(e.getMessage(), e.getCause()); for (StackTraceElement stackTraceElement : e.getStackTrace()) { this.logger.error("\t" + stackTraceElement.toString()); } Mailer mailer = new Mailer(this.config.getProperty("service.mailer.conf")); try { mailer.postMail( "[DaiaService OpenUrl Endpoint] Exception: " + HttpServletResponse.SC_SERVICE_UNAVAILABLE + " Service unavailable (Journals Online & Print).", e.getMessage() + "\n" + this.config.getProperty("jop.url.openurl") + jop_openurl); } catch (MessagingException e1) { this.logger.error(e1.getMessage(), e1.getCause()); } } } else { // tue nix: daiaDocuments bleibt leer } } } // Abschlusskorrektur fr ACM, IEEE und LNCS vor dem response // LNCS if (Lookup.lookupAll(LncsResolver.class).size() > 0 && Boolean.parseBoolean(this.config.getProperty("licenced.lncs"))) { if (daiaDocuments.size() > 0) { for (Document daiaDocument : daiaDocuments) { if (daiaDocument != null && daiaDocument.getId() != null && daiaDocument.getId().contains("urn:issn:03029743") && ((latinParameters.keySet().contains("id") && latinParameters.get("id").startsWith("doi:10.1007")) || (latinParameters.keySet().contains("rft.id") && latinParameters.get("rft.id").startsWith("doi:10.1145")))) { daiaDocument.setItem(null); LncsResolver lncsResolver = Lookup.lookup(LncsResolver.class); lncsResolver.init(this.config); Document lncsDocument = lncsResolver.items(latinParameters); daiaDocument.setId(lncsDocument.getId()); daiaDocument.setHref(lncsDocument.getHref()); daiaDocument.setItem(lncsDocument.getItem()); } } } } // ACM if (Lookup.lookupAll(AcmResolver.class).size() > 0 && Boolean.parseBoolean(this.config.getProperty("licenced.acm"))) { if ((latinParameters.keySet().contains("id") && latinParameters.get("id").contains("10.1145")) || (latinParameters.keySet().contains("rft.id") && latinParameters.get("rft.id").contains("10.1145"))) { if (daiaDocuments.size() > 0) { for (Document daiaDocument : daiaDocuments) { daiaDocument.setItem(null); AcmResolver acmResolver = Lookup.lookup(AcmResolver.class); acmResolver.init(this.config); Document acmDocument = acmResolver.items(latinParameters); daiaDocument.setId(acmDocument.getId()); daiaDocument.setHref(acmDocument.getHref()); if (daiaDocument.getItem() == null) { daiaDocument.setItem(acmDocument.getItem()); } else { daiaDocument.getItem().addAll(acmDocument.getItem()); } } } else { Document daiaDocument = new Document(); AcmResolver acmResolver = Lookup.lookup(AcmResolver.class); acmResolver.init(this.config); Document acmDocument = acmResolver.items(latinParameters); daiaDocument.setId(acmDocument.getId()); daiaDocument.setHref(acmDocument.getHref()); if (daiaDocument.getItem() == null) { daiaDocument.setItem(acmDocument.getItem()); } else { daiaDocument.getItem().addAll(acmDocument.getItem()); } daiaDocuments.add(daiaDocument); } } } // IEEE if (Lookup.lookupAll(IeeeResolver.class).size() > 0 && Boolean.parseBoolean(this.config.getProperty("licenced.ieee"))) { if ((latinParameters.keySet().contains("id") && latinParameters.get("id").contains("10.1109")) || (latinParameters.keySet().contains("rft.id") && latinParameters.get("rft.id").contains("10.1109"))) { if (daiaDocuments.size() > 0) { for (Document daiaDocument : daiaDocuments) { daiaDocument.setItem(null); IeeeResolver ieeeResolver = Lookup.lookup(IeeeResolver.class); ieeeResolver.init(this.config); Document ieeeDocument = ieeeResolver.items(latinParameters); daiaDocument.setId(ieeeDocument.getId()); daiaDocument.setHref(ieeeDocument.getHref()); if (daiaDocument.getItem() == null) { daiaDocument.setItem(ieeeDocument.getItem()); } else { daiaDocument.getItem().addAll(ieeeDocument.getItem()); } } } else { Document daiaDocument = new Document(); IeeeResolver ieeeResolver = Lookup.lookup(IeeeResolver.class); ieeeResolver.init(this.config); Document ieeeDocument = ieeeResolver.items(latinParameters); daiaDocument.setId(ieeeDocument.getId()); daiaDocument.setHref(ieeeDocument.getHref()); if (daiaDocument.getItem() == null) { daiaDocument.setItem(ieeeDocument.getItem()); } else { daiaDocument.getItem().addAll(ieeeDocument.getItem()); } daiaDocuments.add(daiaDocument); } } } if (daiaDocuments.size() > 0) { this.logger.debug("200 Document Found"); // TODO query footnotes from ils if configured // Ausgabe Daia daia = new Daia(); daia.setVersion(this.config.getProperty("daia.version")); daia.setSchema(this.config.getProperty("daia.schema")); GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(new Date().getTime()); try { DatatypeFactory df = DatatypeFactory.newInstance(); daia.setTimestamp(df.newXMLGregorianCalendar(gc).toString()); } catch (DatatypeConfigurationException dce) { this.logger.error("ERROR: Service unavailable.", dce.getCause()); } Institution institution = new Institution(); institution.setId(this.config.getProperty("daia.institution.id")); institution.setHref(this.config.getProperty("daia.institution.href")); institution.setContent(this.config.getProperty("daia.institution.content")); daia.setInstitution(institution); daia.setDocument(daiaDocuments); // Ausgabe if (daia.getDocument() == null || daia.getDocument().size() == 0) { // HTML-Ausgabe via XSLT if (format.equals("html")) { try { JAXBContext context = JAXBContext.newInstance(Daia.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse StringWriter stringWriter = new StringWriter(); m.marshal(daia, stringWriter); org.jdom2.Document doc = new org.jdom2.Document(); doc.setRootElement(new Element("daia")); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", "de"); parameters.put("isTUintern", Boolean.toString(isTUintern)); parameters.put("isUBintern", Boolean.toString(isUBintern)); parameters.put("is52bIBA", Boolean.toString(is52bIBA)); parameters.put("id", "openurl:" + URLDecoder.decode(openurl, "UTF-8")); ObjectMapper mapper = new ObjectMapper(); StringWriter json = new StringWriter(); mapper.writeValue(json, daia); parameters.put("json", json.toString()); String html = htmlOutputter(doc, this.config.getProperty("linkresolver.html.xslt"), parameters); response.setContentType("text/html;charset=UTF-8"); response.setStatus(HttpServletResponse.SC_OK); response.getWriter().println(html); } catch (PropertyException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message. Message is 'Document not found'."); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message. Message is 'Document not found'."); } } else { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Document not found."); } } else { this.logger.debug("format = " + format); // HTML-Ausgabe via XSLT if (format.equals("html")) { try { JAXBContext context = JAXBContext.newInstance(Daia.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse StringWriter stringWriter = new StringWriter(); m.marshal(daia, stringWriter); org.jdom2.Document doc = new SAXBuilder() .build(new StringReader(this.cleanup(stringWriter.toString()))); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", "de"); parameters.put("isTUintern", Boolean.toString(isTUintern)); parameters.put("isUBintern", Boolean.toString(isUBintern)); parameters.put("is52bIBA", Boolean.toString(is52bIBA)); parameters.put("id", "openurl:" + URLDecoder.decode(openurl, "UTF-8")); ObjectMapper mapper = new ObjectMapper(); StringWriter json = new StringWriter(); mapper.writeValue(json, daia); parameters.put("json", json.toString()); String html = htmlOutputter(doc, this.config.getProperty("linkresolver.html.xslt"), parameters); response.setContentType("text/html;charset=UTF-8"); response.setStatus(HttpServletResponse.SC_OK); response.getWriter().println(html); } catch (PropertyException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } catch (JDOMException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } catch (IOException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(Daia.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse response.setContentType("application/xml;charset=UTF-8"); response.setStatus(HttpServletResponse.SC_OK); m.marshal(daia, response.getWriter()); } catch (PropertyException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } } // JSON-Ausgabe mit Jackson if (format.equals("json")) { ObjectMapper mapper = new ObjectMapper(); response.setContentType("application/json;charset=UTF-8"); response.setStatus(HttpServletResponse.SC_OK); mapper.writeValue(response.getWriter(), daia); } // RDF-Ausgabe mit XSLT auf XML-Ausgabe if (format.equals("rdf")) { try { JAXBContext context = JAXBContext.newInstance(Daia.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse response.setContentType("application/xml;charset=UTF-8"); response.setStatus(HttpServletResponse.SC_OK); StringWriter xml = new StringWriter(); m.marshal(daia, xml); XMLOutputter out = new XMLOutputter(); out.output( new SAXBuilder().build(new StringReader( xmlOutputter(new SAXBuilder().build(new StringReader(xml.toString())), config.getProperty("xslt_xml2rdf"), null))), response.getWriter()); } catch (JDOMException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } catch (PropertyException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering the results."); } } } } else { this.logger.debug("404 Document Not Found + (format=" + format + ")"); if (format.equals("html")) { try { JAXBContext context = JAXBContext.newInstance(Daia.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // Write to HttpResponse org.jdom2.Document doc = new org.jdom2.Document(); doc.setRootElement(new Element("daia")); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", "de"); parameters.put("isTUintern", Boolean.toString(isTUintern)); parameters.put("isUBintern", Boolean.toString(isUBintern)); parameters.put("is52bIBA", Boolean.toString(is52bIBA)); parameters.put("id", "openurl:" + URLDecoder.decode(openurl, "UTF-8")); String html = htmlOutputter(doc, this.config.getProperty("linkresolver.html.xslt"), parameters); response.setContentType("text/html;charset=UTF-8"); response.setStatus(HttpServletResponse.SC_OK); response.getWriter().println(html); } catch (PropertyException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message. Message is 'Document not found'."); } catch (JAXBException e) { this.logger.error(e.getMessage(), e.getCause()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message. Message is 'Document not found'."); } } else { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Document not found."); } } } catch (Exception e) { this.logger.error("[DaiaService OpenUrl Endpoint] Exception: " + HttpServletResponse.SC_SERVICE_UNAVAILABLE + " Service unavailable."); this.logger.error(e.getMessage(), e.getCause()); for (StackTraceElement stackTraceElement : e.getStackTrace()) { this.logger.error("\t" + stackTraceElement.toString()); } Mailer mailer = new Mailer(this.config.getProperty("service.mailer.conf")); try { mailer.postMail("[DaiaService OpenUrl Endpoint] Exception: " + HttpServletResponse.SC_SERVICE_UNAVAILABLE + " Service unavailable.", e.getMessage() + "\n" + request.getRequestURL()); } catch (MessagingException e1) { this.logger.error(e1.getMessage(), e1.getCause()); } response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Service unavailable."); } }
From source file:com.newsrob.EntryManager.java
public void cancel() { cancelRequested = true;//from w ww. j a v a 2 s . c o m if (currentRunningJob != null) currentRunningJob.cancel(); fireStatusUpdated(); if (runningThread != null) { final Thread t = new Thread(new Runnable() { public void run() { try { if (!runningThread.isAlive()) return; runningThread.join(8000); if (!runningThread.isAlive()) return; runningThread.interrupt(); runningThread.join(2500); if (!runningThread.isAlive()) return; } catch (final Throwable t) { PL.log("CANCEL: " + t.getMessage() + " " + t.getClass(), ctx); } finally { if (runningThread == null || !runningThread.isAlive()) { runningThread = null; // NOPMD by mkamp on 1/18/10 // 8:29 PM clearCancelState(); } else { PL.log("CANCEL: Didn't work out ;-( " + runningThread.getState(), ctx); for (final StackTraceElement ste : new ArrayList<StackTraceElement>( Arrays.asList(runningThread.getStackTrace()))) { PL.log("CANCEL: " + ste.toString(), ctx); } } } } }); t.start(); } }
From source file:de.decoit.visa.rdf.RDFManager.java
/** * Remove all named models and statements in the default model from the TDB * database and delete all uploaded source files. After cleaning up close * the connection to the TDB database.// ww w.j a va2 s .c o m * * @throws IOException */ public void close() throws IOException { ds.begin(ReadWrite.WRITE); try { clearSourceFiles(); // Remove all named models from the database that were not removed // by clearSourceFiles() Iterator<String> itNames = ds.listNames(); ArrayList<String> names = new ArrayList<>(); while (itNames.hasNext()) { names.add(itNames.next()); } for (String n : names) { ds.removeNamedModel(n); } // Clear the default model ds.getDefaultModel().removeAll(); ds.commit(); } catch (Throwable ex) { StringBuilder sb = new StringBuilder("Caught: ["); sb.append(ex.getClass().getSimpleName()); sb.append("] "); sb.append(ex.getMessage()); log.error(sb.toString()); if (log.isDebugEnabled()) { for (StackTraceElement ste : ex.getStackTrace()) { log.debug(ste.toString()); } } ds.abort(); throw ex; } finally { ds.end(); // Sync changes to disk TDB.sync(ds); // Close the TDB database connection ds.close(); } }
From source file:de.decoit.visa.rdf.RDFManager.java
/** * Read a SPARQL query from a file into a String and create a Query object * from that. If a resource was specified all occurrences of $URI$ * placeholder in the read query will be replaced with the URI of the * resource. If a model URI is specified, GRAPH lines will be added to the * query using the placeholders $S_MOD$ and $E_MOD$. * * @param pFileName File name of the SPARQL file. The file must exist and be * located in 'res/sparql'//from w w w . ja va 2 s. c o m * @param pRes Optional resource object, will be used to replace the $URI$ * placeholder. Can be set to null if not required. * @param pMod Optional model URI, will be used to add GRAPH lines to the * query. If set to null the query will be executed on the * default model of the dataset. * @return A Query object containing the read SPARQL query, null if the * input file cannot be read */ private Query readSPARQL(String pFileName, Resource pRes, String pMod) { try { // Open the SPARQL file for reading Path inFile = Paths.get("res/sparql", pFileName); BufferedReader br = Files.newBufferedReader(inFile, StandardCharsets.UTF_8); // Read all lines and concatenate them using a StringBuilder StringBuilder rv = new StringBuilder(); String line = br.readLine(); while (line != null) { rv.append(line); rv.append(System.lineSeparator()); line = br.readLine(); } br.close(); // Get the String from the StringBuilder and, if required, replace // the $URI$ placeholder String rvStr = rv.toString(); if (pRes != null) { rvStr = rvStr.replaceAll("\\$URI\\$", pRes.getURI()); } if (pMod != null && !pMod.isEmpty()) { StringBuilder graphLine = new StringBuilder("GRAPH <"); graphLine.append(pMod); graphLine.append("> {"); rvStr = rvStr.replaceAll("\\$S_MOD\\$", graphLine.toString()).replaceAll("\\$E_MOD\\$", "}"); } else { rvStr = rvStr.replaceAll("\\$S_MOD\\$", "").replaceAll("\\$E_MOD\\$", ""); } // Build a Query object and return it return QueryFactory.create(rvStr); } catch (IOException ex) { StringBuilder sb = new StringBuilder("Caught: ["); sb.append(ex.getClass().getSimpleName()); sb.append("] "); sb.append(ex.getMessage()); log.error(sb.toString()); if (log.isDebugEnabled()) { for (StackTraceElement ste : ex.getStackTrace()) { log.debug(ste.toString()); } } return null; } }
From source file:com.grazerss.EntryManager.java
public void cancel() { cancelRequested = true;//from w w w . java2s . c o m if (currentRunningJob != null) { currentRunningJob.cancel(); } fireStatusUpdated(); if (runningThread != null) { final Thread t = new Thread(new Runnable() { public void run() { try { if (!runningThread.isAlive()) { return; } runningThread.join(8000); if (!runningThread.isAlive()) { return; } runningThread.interrupt(); runningThread.join(2500); if (!runningThread.isAlive()) { return; } } catch (final Throwable t) { PL.log("CANCEL: " + t.getMessage() + " " + t.getClass(), ctx); } finally { if ((runningThread == null) || !runningThread.isAlive()) { runningThread = null; // NOPMD by mkamp on 1/18/10 // 8:29 PM clearCancelState(); } else { PL.log("CANCEL: Didn't work out ;-( " + runningThread.getState(), ctx); for (final StackTraceElement ste : new ArrayList<StackTraceElement>( Arrays.asList(runningThread.getStackTrace()))) { PL.log("CANCEL: " + ste.toString(), ctx); } } } } }); t.start(); } }
From source file:com.atlauncher.data.Settings.java
/** * Logs a stack trace to the console window * * @param exception The exception to show in the console *//*from w w w . ja va 2 s .c om*/ public void logStackTrace(Exception exception) { exception.printStackTrace(); LogManager.error(exception.getMessage()); for (StackTraceElement element : exception.getStackTrace()) { if (element.toString() != null) { LogManager.error(element.toString()); } } }