List of usage examples for javax.xml.datatype DatatypeFactory newInstance
public static DatatypeFactory newInstance() throws DatatypeConfigurationException
From source file:it.txt.access.capability.revocation.test.RevocationServiceTest.java
@Test public void testPut() throws UnsupportedEncodingException, IOException, JAXBException { IoTTestForPUT test = new IoTTestForPUT(); System.out.println("**********************************************************"); System.out.println("* NPR400 : BAD NOTIFICATION (at least one missing element*"); System.out.println("**********************************************************"); StringEntity input0 = new StringEntity(readFileAsString(System.getProperty("NOTIFICATION_NPR400"))); String url0 = System.getProperty("URL_NPR400"); String result0 = test.testPut(url0, input0); assertEquals(StatusCode.NPR400, result0); System.out.println("**********************************************************"); System.out.println("* NPR404 : REVOCATION NOT FOUND *"); System.out.println("**********************************************************"); StringEntity input1 = new StringEntity(readFileAsString(System.getProperty("NOTIFICATION_NPR404"))); String url1 = System.getProperty("URL_NPR404"); String result1 = test.testPut(url1, input1); assertEquals(StatusCode.NPR404, result1); System.out.println("**********************************************************"); System.out.println("* NPR450 : BAD REVOCATION PROCESSING STATUS CODE *"); System.out.println("**********************************************************"); StringEntity input2 = new StringEntity(readFileAsString(System.getProperty("NOTIFICATION_NPR450"))); String url2 = System.getProperty("URL_NPR450"); String result2 = test.testPut(url2, input2); assertEquals(StatusCode.NPR450, result2); System.out.println("**********************************************************"); System.out.println("* NPR451 : BAD RESOLUTION ISTANT *"); System.out.println("**********************************************************"); StringEntity input3 = new StringEntity(readFileAsString(System.getProperty("NOTIFICATION_NPR451"))); String url3 = System.getProperty("URL_NPR451"); String result3 = test.testPut(url3, input3); assertEquals(StatusCode.NPR451, result3); System.out.println("**********************************************************"); System.out.println("* NPR452 : BAD REVOCATION PROCESSING STATUS *"); System.out.println("**********************************************************"); StringEntity input4 = new StringEntity(readFileAsString(System.getProperty("NOTIFICATION_NPR452"))); String url4 = System.getProperty("URL_NPR452"); String result4 = test.testPut(url4, input4); assertEquals(StatusCode.NPR452, result4); System.out.println("**********************************************************"); System.out.println("* NPR200 : OK *"); System.out.println("**********************************************************"); IoTTestForPOST testa = new IoTTestForPOST(); StringEntity inp = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP201"))); String res = testa.testPost(inp); assertNotNull(res);//from www . j a v a2s . co m DataMapper delete = new DataMapper(); delete.clearPendingIndex(); StringEntity input5 = new StringEntity(readFileAsString(System.getProperty("NOTIFICATION_NPR200"))); String url5 = System.getProperty("URL_NPR200"); String result5 = test.testPut(url5, input5); assertEquals(StatusCode.NPR200, result5); ODatabaseDocumentTx capRevDb = new ODatabaseDocumentTx(Constants.revocationDBUrl).open(Constants.iUserName, Constants.iUserPassword); String querySelRev = "select statusCode, status, processedOn from " + Constants.REVOCATION_CLASS + " where " + Constants.REVOCATION_ID + " = '_e49af3ee828b03a32c39df493cf4c674'"; List<ODocument> rev = capRevDb.command(new OCommandSQL(querySelRev)).execute(); ODocument element = rev.get(0); assertEquals(element.field(Constants.STATUS), "ACCEPTED"); assertEquals(element.field(Constants.STATUS_CODE), StatusCode.NPR200); String processedOn = null; try { XMLGregorianCalendar cal = DatatypeFactory.newInstance() .newXMLGregorianCalendar("2012-03-30T09:35:58.011+02:00"); Date gCal = cal.toGregorianCalendar().getTime(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); processedOn = sdf.format(gCal.getTime()); } catch (Exception e) { } String date = null; try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); date = sdf.format(element.field(Constants.PROCESSED_ON)); } catch (Exception e) { } assertEquals(date, processedOn); }
From source file:com.alliander.osgp.acceptancetests.basicfunctions.VerifyAuthorizeDeviceFunctionSteps.java
private void getPowerUsageHistory() throws OsgpException { final GetPowerUsageHistoryRequest request = new GetPowerUsageHistoryRequest(); request.setDeviceIdentification(this.device.getDeviceIdentification()); request.setHistoryTermType(HistoryTermType.SHORT); final TimePeriod timePeriod = new TimePeriod(); try {/* w ww . j a va 2s . co m*/ timePeriod.setStartTime(DatatypeFactory.newInstance() .newXMLGregorianCalendar(DateTime.now().minusDays(1).toGregorianCalendar())); timePeriod.setEndTime( DatatypeFactory.newInstance().newXMLGregorianCalendar(DateTime.now().toGregorianCalendar())); } catch (final DatatypeConfigurationException e) { throw new TechnicalException(ComponentType.DOMAIN_PUBLIC_LIGHTING, e); } request.setTimePeriod(timePeriod); // device always responds ok final com.alliander.osgp.oslp.Oslp.GetPowerUsageHistoryResponse oslpResponse = com.alliander.osgp.oslp.Oslp.GetPowerUsageHistoryResponse .newBuilder() .addPowerUsageData( PowerUsageData.newBuilder().setMeterType(MeterType.P1).setRecordTime("20130101120000") .setActualConsumedPower(2).setTotalConsumedEnergy(2).build()) .setStatus(Status.OK).build(); this.oslpEnvelope = OslpTestUtils.createOslpEnvelopeBuilder().withDeviceId(Base64.decodeBase64(DEVICE_UID)) .withPayloadMessage(Message.newBuilder().setGetPowerUsageHistoryResponse(oslpResponse).build()) .build(); this.oslpChannelHandler = OslpTestUtils.createOslpChannelHandlerWithResponse(this.oslpEnvelope, this.channelMock, this.device.getNetworkAddress()); this.deviceService.setOslpChannelHandler(this.oslpChannelHandler); this.response = this.lightDeviceMonitoringEndpoint .getPowerUsageHistory(this.organisation.getOrganisationIdentification(), request); }
From source file:fr.cls.atoll.motu.library.misc.intfce.Organizer.java
/** * Date to XML gregorian calendar.//from w ww . java 2 s . co m * * @param date the date * * @return the XML gregorian calendar * * @throws MotuException the motu exception */ public static XMLGregorianCalendar dateToXMLGregorianCalendar(Date date) throws MotuException { GregorianCalendar gCalendar = new GregorianCalendar(); gCalendar.setTime(date); XMLGregorianCalendar xmlGregorianCalendar; try { xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gCalendar); } catch (DatatypeConfigurationException e) { throw new MotuException("ERROR in dateToXMLGregorianCalendar", e); } return xmlGregorianCalendar; }
From source file:com.ccserver.digital.service.LOSService.java
private XMLGregorianCalendar dateToXMLGregorianCalendar(Date date) { if (date == null) { return null; }/*ww w . ja va 2s. c o m*/ try { GregorianCalendar gregory = new GregorianCalendar(); gregory.setTime(date); return DatatypeFactory.newInstance() .newXMLGregorianCalendarDate(gregory.get(Calendar.YEAR), gregory.get(Calendar.MONTH) + 1, gregory.get(Calendar.DAY_OF_MONTH), DatatypeConstants.FIELD_UNDEFINED) .normalize(); } catch (DatatypeConfigurationException e) { logger.error(Utils.getErrorFormatLog("LOSService", "dateToXMLGregorianCalendar", "", "Can not convert from LocalDateTime to XMLGregorianCalenda", e.toString())); } return null; }
From source file:com.ccserver.digital.service.LOSService.java
private CommonType getCommonType(String messageId) { CommonType commonType = new CommonType(); commonType.setServiceVersion(getConfiguration("LOS_SERVICE_VERSION", "1")); commonType.setMessageId(messageId);/*from w w w .j a v a 2 s.com*/ commonType.setTransactionId(java.util.UUID.randomUUID().toString()); try { GregorianCalendar gregory = new GregorianCalendar(); gregory.setTime(new Date()); XMLGregorianCalendar dealCloseDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregory); commonType.setMessageTimestamp(dealCloseDate); } catch (DatatypeConfigurationException e) { logger.error(Utils.getErrorFormatLog("LOSService", "getCommonType", "", e.toString())); } return commonType; }
From source file:eu.europa.ec.fisheries.uvms.rules.service.bean.RulesMessageServiceBean.java
private void setFluxResponseCreationDate(FLUXResponseDocument fluxResponseDocument) throws DatatypeConfigurationException { GregorianCalendar date = DateTime.now(DateTimeZone.UTC).toGregorianCalendar(); XMLGregorianCalendar calender = DatatypeFactory.newInstance().newXMLGregorianCalendar(date); DateTimeType dateTime = new DateTimeType(); dateTime.setDateTime(calender);//from ww w.j ava2 s . c om fluxResponseDocument.setCreationDateTime(dateTime); // Set creation date time }
From source file:ddf.catalog.pubsub.PredicateTest.java
@Test public void testMultipleCriteria() throws Exception { String methodName = "testMultipleCriteria"; LOGGER.debug("*************** START: " + methodName + " *****************"); // test with temporal, spatial, and entry MockQuery query = new MockQuery(); DatatypeFactory df = DatatypeFactory.newInstance(); XMLGregorianCalendar start = df.newXMLGregorianCalendarDate(2011, 10, 25, 0); XMLGregorianCalendar end = df.newXMLGregorianCalendarDate(2011, 10, 27, 0); query.addTemporalFilter(start, end, Metacard.MODIFIED); String wkt = "POLYGON((0 10, 0 0, 10 0, 10 10, 0 10))"; query.addSpatialFilter(wkt, 0.0, "Meter", "CONTAINS"); // create entry criteria String catalogId = "ABC123"; query.addEntryFilter(catalogId);/*from w w w . j a v a 2 s.c om*/ MetacardImpl metacard = new MetacardImpl(); metacard.setLocation("POINT(5 5)"); metacard.setId(catalogId); metacard.setCreatedDate(new Date()); metacard.setExpirationDate(new Date()); metacard.setEffectiveDate(new Date()); metacard.setMetadata(TestDataLibrary.getCatAndDogEntry()); XMLGregorianCalendar cal = df.newXMLGregorianCalendarDate(2011, 10, 26, 0); Date modifiedDate = cal.toGregorianCalendar().getTime(); metacard.setModifiedDate(modifiedDate); HashMap<String, Object> properties = new HashMap<>(); properties.put(PubSubConstants.HEADER_ID_KEY, metacard.getId()); properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard); properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE); Map<String, Object> contextualMap = constructContextualMap(metacard); properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap); // Above Pulled from PubSubProviderImpl Event testEvent = new Event("topic", properties); // input passes temporal, id, and geo SubscriptionFilterVisitor visitor = new SubscriptionFilterVisitor(); Predicate pred = (Predicate) query.getFilter().accept(visitor, null); LOGGER.debug("resulting predicate: " + pred); Filter filter = query.getFilter(); FilterTransformer transform = new FilterTransformer(); transform.setIndentation(2); String filterXml = transform.transform(filter); LOGGER.debug(filterXml); assertTrue(pred.matches(testEvent)); // input passes temporal, id, but fails geo metacard.setLocation("POINT(5 50)"); // geo out of range properties.clear(); properties.put(PubSubConstants.HEADER_ID_KEY, metacard.getId()); properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard); properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE); // Below Pulled from PubSubProviderImpl contextualMap = constructContextualMap(metacard); properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap); // Above Pulled from PubSubProviderImpl testEvent = new Event("topic", properties); assertFalse(pred.matches(testEvent)); // input passes geo, and id, but fails temporal metacard.setLocation("POINT(5 5)"); XMLGregorianCalendar cal1 = df.newXMLGregorianCalendarDate(2011, 10, 28, 0); Date modifiedDate1 = cal1.toGregorianCalendar().getTime(); metacard.setModifiedDate(modifiedDate1); // date out of range properties.clear(); properties.put(PubSubConstants.HEADER_ID_KEY, metacard.getId()); properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard); properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE); // Below Pulled from PubSubProviderImpl contextualMap = constructContextualMap(metacard); properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap); // Above Pulled from PubSubProviderImpl testEvent = new Event("topic", properties); assertFalse(pred.matches(testEvent)); // input passes temporal, geo, but fails id XMLGregorianCalendar cal2 = df.newXMLGregorianCalendarDate(2011, 10, 26, 0); Date modifiedDate2 = cal2.toGregorianCalendar().getTime(); metacard.setModifiedDate(modifiedDate2); metacard.setId("invalid_id"); // bad id properties.clear(); properties.put(PubSubConstants.HEADER_ID_KEY, metacard.getId()); properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard); properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE); // Below Pulled from PubSubProviderImpl contextualMap = constructContextualMap(metacard); properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap); // Above Pulled from PubSubProviderImpl testEvent = new Event("topic", properties); assertFalse(pred.matches(testEvent)); LOGGER.debug("*************** END: " + methodName + " *****************"); }
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 {/*ww w . j a v a2s . c o 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:edu.harvard.hms.dbmi.i2b2.api.pm.PMCell.java
/** * Create an approval/*from w w w .j a v a2 s . c o m*/ * * @param client * HTTP Client * @param id * Approval id * @param approvalName * Approval Name * @param approvalDescription * Approval description * @param approvalObservationCd * Approval observation cd * @param activationDate * Activation date * @param expirationDate * Expiration date * @throws DatatypeConfigurationException * @throws JAXBException * An XML processing exception occurred * @throws UnsupportedOperationException * @throws I2B2InterfaceException * An error occurred on the i2b2 server * @throws IOException * An IO exception occurred */ public void setApproval(HttpClient client, String id, String approvalName, String approvalDescription, String approvalObservationCd, GregorianCalendar activationDate, GregorianCalendar expirationDate) throws DatatypeConfigurationException, JAXBException, UnsupportedOperationException, I2B2InterfaceException, IOException { RequestMessageType rmt = createMinimumBaseMessage(""); ApprovalType at = pmOF.createApprovalType(); at.setId(id); at.setName(approvalName); at.setDescription(approvalDescription); at.setObjectCd(approvalObservationCd); at.setActivationDate((DatatypeFactory.newInstance().newXMLGregorianCalendar(activationDate))); at.setExpirationDate((DatatypeFactory.newInstance().newXMLGregorianCalendar(expirationDate))); rmt.getMessageBody().getAny().add(pmOF.createSetApproval(at)); StringWriter sw = new StringWriter(); pmMarshaller.marshal(pmOF.createRequest(rmt), sw); checkForError(runRequest(client, sw.toString(), "")); }
From source file:it.cg.main.process.mapping.easyway.MapperProductAssetToPASS.java
/** * Return a TypeData for PASS from a passed Date * @param Date data//from ww w . jav a 2 s.co m * @return TypeData from input */ public TypeData dataToTypeData(Date data) { TypeData dataOpenTypeData = new TypeData(); GregorianCalendar c = new GregorianCalendar(); XMLGregorianCalendar dataOpen = null; try { c.setTime(data); dataOpen = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); } catch (NullPointerException ex) { logger.error("Date passed is null : " + data + " "); } catch (DatatypeConfigurationException ex) { logger.error("Error conversion for data : " + data + " "); } dataOpenTypeData.setData(dataOpen); return dataOpenTypeData; }