List of usage examples for javax.xml.bind Marshaller JAXB_FORMATTED_OUTPUT
String JAXB_FORMATTED_OUTPUT
To view the source code for javax.xml.bind Marshaller JAXB_FORMATTED_OUTPUT.
Click Source Link
From source file:com.axelor.controller.ConnectionToPrestashop.java
@SuppressWarnings("null") @Transactional/*from w w w. j ava2 s . c o m*/ public void insertAddress(int addressId) { com.axelor.pojo.Address pojoAddress = new com.axelor.pojo.Address(); pojoAddress.setId_customer(0); pojoAddress.setId_country(0); pojoAddress.setId_state(0); pojoAddress.setPrestashopAddressId(0); pojoAddress.setFirstname("FIRSTNAME"); pojoAddress.setLastname("LASTNAME"); pojoAddress.setPhone_mobile("0000000000"); pojoAddress.setAddress1("ADDRESS1"); pojoAddress.setAddress2("ADDRESS2"); pojoAddress.setCity("CITY"); pojoAddress.setPostcode("000000"); pojoAddress.setAlias("ALIAS"); try { URL url = new URL("http://localhost/client-lib/crud/action.php?resource=addresses&action=retrieve&id=" + addressId + "&Akey=" + apiKey); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); JAXBContext jaxbContext = JAXBContext.newInstance(com.axelor.pojo.Address.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); connection.setDoOutput(true); connection.setDoInput(true); OutputStream outputStream = connection.getOutputStream(); jaxbMarshaller.marshal(pojoAddress, outputStream); connection.connect(); InputStream inputStream = connection.getInputStream(); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); pojoAddress = (com.axelor.pojo.Address) jaxbUnmarshaller .unmarshal(new UnmarshalInputStream(connection.getInputStream())); // Resolve Country Country baseCountry = Country.all().filter("prestashop_country_id=?", pojoAddress.getId_country()) .fetchOne(); // Resolve Region Region baseRegion = Region.all().filter("prestashop_region_id=?", pojoAddress.getId_state()).fetchOne(); Address prestashopAddress = new Address(); // add this address into ERP prestashopAddress.setAddressL2(pojoAddress.getFirstname()); prestashopAddress.setAddressL3(pojoAddress.getLastname()); prestashopAddress.setAddressL4(pojoAddress.getAddress1()); prestashopAddress.setAddressL5(pojoAddress.getAddress2()); prestashopAddress.setAddressL6(pojoAddress.getPostcode() + " " + pojoAddress.getCity()); prestashopAddress.setFullName(pojoAddress.getAlias()); prestashopAddress.setAddressL7Country(baseCountry); prestashopAddress.setPhoneMobile(pojoAddress.getPhone_mobile()); prestashopAddress.setPostcode(pojoAddress.getPostcode()); prestashopAddress.setPrestashopid(addressId); prestashopAddress.setRegion(baseRegion); prestashopAddress.save(); } catch (Exception e) { System.out.println(e); } }
From source file:de.tu_dortmund.ub.api.paia.core.PaiaCoreEndpoint.java
/** * PAIA core services: Prfe jeweils die scopes und liefere die Daten *///w ww. j av a 2 s . c om private void provideService(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String patronid, String service, String format, String language, String redirect_url, 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(); if (Lookup.lookupAll(IntegratedLibrarySystem.class).size() > 0) { try { IntegratedLibrarySystem integratedLibrarySystem = Lookup.lookup(IntegratedLibrarySystem.class); // init ILS integratedLibrarySystem.init(this.config); switch (service) { case "patron": { Patron patron = integratedLibrarySystem.patron(patronid, false); if (patron != null) { StringWriter json = new StringWriter(); mapper = new ObjectMapper(); mapper.writeValue(json, patron); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "read_patron"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(patron, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(Patron.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(patron, 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(), patron); } } else { // 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_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "fullpatron": { Patron patron = integratedLibrarySystem.patron(patronid, true); if (patron != null) { StringWriter json = new StringWriter(); mapper = new ObjectMapper(); mapper.writeValue(json, patron); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "write_patron"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(patron, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(Patron.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(patron, 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(), patron); } } else { // 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_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "items": { DocumentList documentList = integratedLibrarySystem.items(patronid, "all"); if (documentList != null) { StringWriter json = new StringWriter(); mapper = new ObjectMapper(); mapper.writeValue(json, documentList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "read_items"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(documentList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(DocumentList.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(documentList, 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(), documentList); } } else { // 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_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "items/borrowed": { DocumentList documentList = integratedLibrarySystem.items(patronid, "borrowed"); if (documentList != null) { StringWriter json = new StringWriter(); mapper = new ObjectMapper(); mapper.writeValue(json, documentList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "read_items"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(documentList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(DocumentList.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(documentList, 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(), documentList); } } else { // 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_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "items/borrowed/ill": { DocumentList documentList = integratedLibrarySystem.items(patronid, "borrowed", "ill"); if (documentList != null) { StringWriter json = new StringWriter(); mapper = new ObjectMapper(); mapper.writeValue(json, documentList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "read_items"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(documentList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(DocumentList.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(documentList, 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(), documentList); } } else { // 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_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "items/borrowed/renewed": { DocumentList documentList = integratedLibrarySystem.items(patronid, "borrowed", "renewed"); if (documentList != null) { StringWriter json = new StringWriter(); mapper = new ObjectMapper(); mapper.writeValue(json, documentList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "read_items"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(documentList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(DocumentList.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(documentList, 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(), documentList); } } else { // 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_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "items/borrowed/recalled": { DocumentList documentList = integratedLibrarySystem.items(patronid, "borrowed", "recalled"); if (documentList != null) { StringWriter json = new StringWriter(); mapper = new ObjectMapper(); mapper.writeValue(json, documentList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "read_items"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(documentList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(DocumentList.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(documentList, 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(), documentList); } } else { // 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_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "items/ordered": { DocumentList documentList = integratedLibrarySystem.items(patronid, "ordered"); if (documentList != null) { StringWriter json = new StringWriter(); mapper = new ObjectMapper(); mapper.writeValue(json, documentList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "read_items"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(documentList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(DocumentList.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(documentList, 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(), documentList); } } else { // 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_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "items/reserved": { DocumentList documentList = integratedLibrarySystem.items(patronid, "reserved"); if (documentList != null) { StringWriter json = new StringWriter(); mapper = new ObjectMapper(); mapper.writeValue(json, documentList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "read_items"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(documentList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(DocumentList.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(documentList, 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(), documentList); } } else { // 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_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "request": { DocumentList documentList = integratedLibrarySystem.request(patronid, documents); if (documentList != null) { StringWriter json = new StringWriter(); mapper.writeValue(json, documentList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); // set Cookie with new value for 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); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "write_items"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { this.logger.info("redirect_url = " + redirect_url); if (!redirect_url.equals("")) { httpServletResponse.sendRedirect(redirect_url); } else { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(documentList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(DocumentList.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(documentList, 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(), documentList); } } else { // 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_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "renew": { DocumentList documentList = integratedLibrarySystem.renew(patronid, documents); if (documentList != null) { StringWriter json = new StringWriter(); mapper.writeValue(json, documentList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); // delete DocumentList cookie Cookie cookie = new Cookie("PaiaServiceDocumentList", null); 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(0); httpServletResponse.addCookie(cookie); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "write_items"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(documentList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(DocumentList.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(documentList, 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(), documentList); } } else { // 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_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "cancel": { DocumentList documentList = integratedLibrarySystem.cancel(patronid, documents); if (documentList != null) { StringWriter json = new StringWriter(); mapper.writeValue(json, documentList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); // delete DocumentList cookie Cookie cookie = new Cookie("PaiaServiceDocumentList", null); 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(0); httpServletResponse.addCookie(cookie); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "write_items"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(documentList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(DocumentList.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(documentList, 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(), documentList); } } else { // 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_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } case "fees": { FeeList feeList = integratedLibrarySystem.fees(patronid); if (feeList != null) { StringWriter json = new StringWriter(); mapper = new ObjectMapper(); mapper.writeValue(json, feeList); this.logger.debug("[" + this.config.getProperty("service.name") + "] " + json); httpServletResponse.setHeader("X-Accepted-OAuth-Scopes", "read_fees"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); if (format.equals("html")) { if (Lookup.lookupAll(ObjectToHtmlTransformation.class).size() > 0) { try { ObjectToHtmlTransformation htmlTransformation = Lookup .lookup(ObjectToHtmlTransformation.class); // init transformator htmlTransformation.init(this.config); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("lang", language); parameters.put("service", service); httpServletResponse.setContentType("text/html;charset=UTF-8"); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.getWriter() .println(htmlTransformation.transform(feeList, parameters)); } catch (TransformationException e) { httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal Server Error: Error while rendering a HTML message."); } } else { this.logger.error("ObjectToHtmlTransformation not configured! Switch to JSON."); format = "json"; } } // XML-Ausgabe mit JAXB if (format.equals("xml")) { try { JAXBContext context = JAXBContext.newInstance(FeeList.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(feeList, 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(), feeList); } } else { // 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_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } break; } } } catch (ILSException e) { StringWriter json = new StringWriter(); // TODO Frage nach "570-unknown patron" ist nicht gut! Lsung: Welche Typen von ILSExceptions treten auf? Erzeuge fr jeden Typ eine eigene Exception! if (e.getMessage().contains("570-unknown patron")) { this.logger.error("[" + this.config.getProperty("service.name") + "] " + HttpServletResponse.SC_NOT_FOUND + ": '" + patronid + "'"); // 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_NOT_FOUND); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError( this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_NOT_FOUND))); requestError.setCode(HttpServletResponse.SC_NOT_FOUND); requestError.setDescription(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_NOT_FOUND) + ".description")); requestError.setErrorUri(this.config .getProperty("error." + Integer.toString(HttpServletResponse.SC_NOT_FOUND) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } else { this.logger.error("[" + this.config.getProperty("service.name") + "] " + HttpServletResponse.SC_SERVICE_UNAVAILABLE + ": ILS!"); // 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_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config .getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } } catch (Exception e) { e.printStackTrace(); } } else { this.logger.error("[" + this.config.getProperty("service.name") + "] " + HttpServletResponse.SC_SERVICE_UNAVAILABLE + ": Config Error!"); // 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_SERVICE_UNAVAILABLE); } // Json fr Response body RequestError requestError = new RequestError(); requestError.setError(this.config .getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE))); requestError.setCode(HttpServletResponse.SC_SERVICE_UNAVAILABLE); requestError.setDescription(this.config.getProperty( "error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".description")); requestError.setErrorUri(this.config .getProperty("error." + Integer.toString(HttpServletResponse.SC_SERVICE_UNAVAILABLE) + ".uri")); this.sendRequestError(httpServletResponse, requestError, format, language, redirect_url); } }
From source file:com.flexoodb.common.FlexUtils.java
/** * extracts the plain XML equivalent of the passed object. * * @param obj the object containing the elements that will be used to populate the XML. * @return XML string.// w ww . j a v a 2 s . c o m * @see Hashtable *@see Element */ static public String getSimpleXML(Object obj) throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); JAXBContext context = JAXBContext.newInstance(((FlexContainer) obj).getObject().getClass()); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(new JAXBElement(new QName("", ((FlexContainer) obj).getObject().getClass().getSimpleName()), ((FlexContainer) obj).getObject().getClass(), ((FlexContainer) obj).getObject()), bos); return new String(bos.toByteArray()); }
From source file:com.tremolosecurity.openunison.util.OpenUnisonUtils.java
private static void storeMethod(String unisonXMLFile, TremoloType tt, String ksPath, KeyStore ks) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, JAXBException, PropertyException { logger.info("Storing the keystore"); ks.store(new FileOutputStream(ksPath), tt.getKeyStorePassword().toCharArray()); logger.info("Saving the unison xml file"); JAXBContext jc = JAXBContext.newInstance("com.tremolosecurity.config.xml"); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); OutputStream os = new FileOutputStream(unisonXMLFile); JAXBElement<TremoloType> root = new JAXBElement<TremoloType>( new QName("http://www.tremolosecurity.com/tremoloConfig", "tremoloConfig", "tns"), TremoloType.class, tt); marshaller.marshal(root, os);//from w w w . j ava2s .co m os.flush(); os.close(); }
From source file:at.ac.tuwien.dsg.cloud.salsa.engine.smartdeployment.main.SmartDeploymentService.java
public MultiLevelRequirements generateQuelleRequirementFromCAMFTosca(TDefinitions def) { // get all Node policy String serviceName = ToscaStructureQuery.getServiceTemplateList(def).get(0).getName(); MultiLevelRequirements serviceReq = new MultiLevelRequirements( MonitoredElement.MonitoredElementLevel.SERVICE); serviceReq.setName(serviceName);/*from w ww .j a va 2s . c o m*/ // get Strategy TServiceTemplate st = ToscaStructureQuery.getServiceTemplateList(def).get(0); Strategy newStra = new Strategy(); newStra.setStrategyCategory(StrategyCategory.OVERALL_REQUIREMENTS); serviceReq.addStrategy(newStra); newStra.setStrategyCategory(StrategyCategory.MINIMUM_COST); serviceReq.addStrategy(newStra); newStra.setStrategyCategory(StrategyCategory.MINIMUM_RESOURCES); serviceReq.addStrategy(newStra); // add requirement MultiLevelRequirements topoReq = new MultiLevelRequirements( MonitoredElement.MonitoredElementLevel.SERVICE_TOPOLOGY); topoReq.setName(serviceName + "topo"); serviceReq.addMultiLevelRequirements(topoReq); // GET ALL NODE's POLICIES List<TNodeTemplate> nodeTemplates = ToscaStructureQuery.getNodeTemplateList(def); for (TNodeTemplate node : nodeTemplates) { if (node.getPolicies() != null) { EngineLogger.logger.debug("Found policies of node: " + node.getId()); List<TPolicy> policies = node.getPolicies().getPolicy(); MultiLevelRequirements suReq = new MultiLevelRequirements( MonitoredElement.MonitoredElementLevel.SERVICE_UNIT); suReq.setName(node.getName()); topoReq.addMultiLevelRequirements(suReq); Requirements reqs = new Requirements(); reqs.setName(node.getName() + ".IaaS"); suReq.addRequirements(reqs); for (TPolicy p : policies) { EngineLogger.logger.debug("Analyzing policy name: {}, type:{} ", p.getName(), p.getPolicyType().toString()); if (p.getPolicyType().getLocalPart().equals("Requirement") && p.getPolicyType().getPrefix().equals("SmartDeployment")) { String theReq = p.getName(); EngineLogger.logger.debug("Parsing the requirement: " + theReq); // E>G> CONSTRAINT Memory&gt;2048 String keyword = theReq.split(" ", 2)[0].trim(); EngineLogger.logger.debug("The first word: {}", keyword); if (keyword.equals("CONSTRAINT")) { EngineLogger.logger.debug("Parsing SYBL constraint: {}" + theReq); Requirement req = syblPolicyToQuelleRequirement(theReq, node, p); topoReq.addRequirement(req); reqs.addRequirement(req); } else { EngineLogger.logger.debug("Parsing CAMF constraint: {}" + theReq); List<Requirement> req = CAMFPolicyToQuelleRequirement(theReq, node, p); for (Requirement r : req) { EngineLogger.logger.debug("Adding requirement {}", r.toString()); topoReq.addRequirement(r); reqs.addRequirement(r); } } } } } // end node.getPolicies() != null } // end For // try to save it, useless but ya JAXBContext jaxbContext; try { String saveReq = SalsaConfiguration.getToscaTemplateStorage() + File.separator + serviceName + requirementExt; EngineLogger.logger.debug("Requirement is generated, trying to save to: " + saveReq); jaxbContext = JAXBContext.newInstance(MultiLevelRequirements.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(serviceReq, new File(saveReq)); } catch (JAXBException ex) { Logger.getLogger(SmartDeploymentService.class.getName()).log(Level.SEVERE, null, ex); } return serviceReq; }
From source file:com.kdmanalytics.toif.framework.toolAdaptor.ToolAdaptor.java
/** * marshall the elements to xml./*from www . ja v a 2 s. co m*/ * * @param outFile * @param elementList * @throws ToifException */ private void marshall(java.io.File outFile, final ArrayList<Element> elementList) throws ToifException { segment.clearSegment(); /* * sort according to the custom comparator. Facts should always be after * entities. */ Collections.sort(elementList, new ElementComparator()); /* * now that we have all the elements, now would be a good time to * normalize and increment the id's. This could have been done when the * element was created but would cause the id's to be all over the * place. */ int id = 0; // give the segment it's id. segment.setId(id++); // for each of the elements, increment and apply its id. for (final Element element : elementList) { element.setId(id++); } JAXBContext context; try { /* * There must be a shorter way to create the context. You can * probably do it by giving it the package all these are in. * However, this was not working for me. */ context = JAXBContext.newInstance(Segment.class, Finding.class, Project.class, Organization.class, Person.class, Generator.class, Adaptor.class, Date.class, WeaknessDescription.class, FindingIsDescribedByWeaknessDescription.class, CWEIdentifier.class, FindingHasCWEIdentifier.class, CodeLocation.class, CodeLocationReferencesFile.class, File.class, Directory.class, FileIsContainedInDirectory.class, DirectoryIsContainedInDirectory.class, Entity.class, Element.class, TOIFSegmentIsGeneratedByGenerator.class, TOIFSegmentIsProcessedByAdaptor.class, TOIFSegmentIsRelatedToProject.class, TOIFSegmentIsCreatedAtDate.class, TOIFSegmentIsProducedByOrganization.class, TOIFSegmentIsOwnedByOrganization.class, TOIFSegmentIsGeneratedByPerson.class, TOIFSegmentIsSupervisedByPerson.class, Role.class, PersonIsInvolvedInProjectAsRole.class, OrganizationIsInvolvedInProjectAsRole.class, AdaptorSupportsGenerator.class, Vendor.class, AdaptorIsSuppliedByVendor.class, GeneratorIsSuppliedByVendor.class, OrganizationIsPartOfOrganizationAsRole.class, PersonIsEmployedByOrganizationAsRole.class, DataElement.class, DataElementIsInvolvedInFinding.class, Statement.class, StatementIsInvolvedInFinding.class, StatementIsSinkInFinding.class, StatementHasCodeLocation.class, FindingHasCodeLocation.class, LineNumber.class, Name.class, Text.class, Description.class, Address.class, EmailAddress.class, Checksum.class, SFPIdentifier.class, FindingHasSFPIdentifier.class, ClusterIdentifier.class, FindingHasClusterIdentifier.class, Offset.class, Position.class, DataElementIsInvolvedInStatement.class, TOIFSegmentReferencesFile.class, StatementIsProceededByStatement.class); final Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // Add all the elements to the segment. for (final Element element : elementList) { segment.addElement(element); } /* * marshal the segment (and its contained elements) to the output * xml. */ m.marshal(segment, new FileOutputStream(outFile)); } catch (final JAXBException e) { final String msg = options.getAdaptor().toString() + ": Failed to create XML output \n"; LOG.error(msg, e); throw new ToifException(msg); } catch (final FileNotFoundException ex) { final String msg = options.getAdaptor().toString() + ": Not able to write to output file " + outFile; LOG.error(msg, ex); throw new ToifException(msg); } }
From source file:it.cnr.icar.eric.common.BindingUtility.java
public String marshalObject(Object obj) throws JAXBException { StringWriter sw = new StringWriter(); // javax.xml.bind.Marshaller marshaller = rsFac.createMarshaller(); javax.xml.bind.Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(obj, sw);//w w w .j a v a 2 s.com //Now get the object as a String String str = sw.toString(); return str; }
From source file:it.cnr.icar.eric.common.BindingUtility.java
public void printObject(Object obj) throws JAXBException { StringWriter sw = new StringWriter(); // javax.xml.bind.Marshaller marshaller = rsFac.createMarshaller(); javax.xml.bind.Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(obj, sw);// w ww. j av a 2 s . c o m //Now get the object as a String String str = sw.toString(); System.err.println(str); }
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 {/*from w w w . j a 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."); } }