List of usage examples for org.dom4j DocumentHelper parseText
public static Document parseText(String text) throws DocumentException
parseText
parses the given text as an XML document and returns the newly created Document.
From source file:org.sipfoundry.openfire.vcard.provider.RestInterface.java
License:Contributor Agreement License
public Element buildVCardFromXMLContactInfoXSLT(String xmlString) { try {// ww w. j a v a 2s.co m Document contactDoc = DocumentHelper.parseText(xmlString); InputStream inStream = this.getClass().getResourceAsStream("/vCardTemp.xsl"); logger.debug("before XSLT " + contactDoc.getRootElement().asXML()); Document vcardDoc = styleDocument(contactDoc, inStream); logger.debug("After XSLT " + vcardDoc.getRootElement().asXML()); return vcardDoc.getRootElement(); } catch (Exception ex) { logger.error(ex.getMessage()); return null; } }
From source file:org.springfield.albright.homer.LazyHomer.java
License:Open Source License
private Boolean checkKnown() { // System.out.println("MYIP="+myip+" SM="+selectedsmithers); String xml = "<fsxml><properties><depth>1</depth></properties></fsxml>"; ServiceInterface smithers = ServiceManager.getService("smithers"); if (smithers == null) return false; String nodes = smithers.get("/domain/internal/service/albright/nodes", xml, "text/xml"); boolean iamok = false; try {/*from w w w .j a v a 2s. c o m*/ boolean foundmynode = false; Document result = DocumentHelper.parseText(nodes); for (Iterator<Node> iter = result.getRootElement().nodeIterator(); iter.hasNext();) { Element child = (Element) iter.next(); if (!child.getName().equals("properties")) { String ipnumber = child.attributeValue("id"); String status = child.selectSingleNode("properties/status").getText(); String name = child.selectSingleNode("properties/name").getText(); // lets put all in our albright list AlbrightProperties mp = albrights.get(ipnumber); if (mp == null) { mp = new AlbrightProperties(); albrights.put(ipnumber, mp); } mp.setIpNumber(ipnumber); mp.setName(name); mp.setStatus(status); mp.setDefaultLogLevel(child.selectSingleNode("properties/defaultloglevel").getText()); mp.setPreferedSmithers(child.selectSingleNode("properties/preferedsmithers").getText()); //System.out.println("comparing ip "+ipnumber+" with "+myip); if (ipnumber.equals(myip)) { //System.out.println("ip was equal"); foundmynode = true; retryCounter = 0; if (name.equals("unknown")) { LOG.info("This albright is not verified change its name, use smithers todo this for ip " + myip); } else { // so we have a name (verified) return true iamok = true; } } else { //System.out.println("ip was not equal!"); } } } if (!foundmynode) { if (retryCounter < 30) { //retry 30 times (= 5 min) to handle temp smithers downtime (eg daily restarts) retryCounter++; } else { System.out.println("LazyHomer : Creating my processing node " + LazyHomer.getSmithersUrl() + "/domain/internal/service/albright/properties"); String os = "unknown"; // we assume windows ? try { os = System.getProperty("os.name"); } catch (Exception e) { LOG.error("LazyHomer : " + e.getMessage()); } String newbody = "<fsxml>"; newbody += "<nodes id=\"" + myip + "\"><properties>"; newbody += "<name>unknown</name>"; newbody += "<status>off</status>"; newbody += "<lastseen>" + new Date().getTime() + "</lastseen>"; newbody += "<preferedsmithers>" + myip + "</preferedsmithers>"; newbody += "<activesmithers>" + selectedsmithers.getIpNumber() + "</activesmithers>"; // i know this looks weird but left it for future extentions if (isWindows()) { newbody += "<defaultloglevel>info</defaultloglevel>"; } if (isMac()) { newbody += "<defaultloglevel>info</defaultloglevel>"; } if (isUnix()) { newbody += "<defaultloglevel>info</defaultloglevel>"; } else { newbody += "<defaultloglevel>info</defaultloglevel>"; } newbody += "</properties></nodes></fsxml>"; smithers.put("/domain/internal/service/albright/properties", newbody, "text/xml"); } } } catch (Exception e) { LOG.info("LazyHomer exception doc"); e.printStackTrace(); } return iamok; }
From source file:org.springfield.barney.homer.LazyHomer.java
License:Open Source License
private Boolean checkKnown() { String xml = "<fsxml><properties><depth>1</depth></properties></fsxml>"; ServiceInterface smithers = ServiceManager.getService("smithers"); if (smithers == null) return false; String nodes = smithers.get("/domain/internal/service/barney/nodes", xml, "text/xml"); boolean iamok = false; try {/*w ww. j av a 2 s .c o m*/ boolean foundmynode = false; Document result = DocumentHelper.parseText(nodes); for (Iterator<Node> iter = result.getRootElement().nodeIterator(); iter.hasNext();) { Element child = (Element) iter.next(); if (!child.getName().equals("properties")) { String ipnumber = child.attributeValue("id"); String status = child.selectSingleNode("properties/status").getText(); String name = child.selectSingleNode("properties/name").getText(); // lets put all in our barney list BarneyProperties mp = barneys.get(ipnumber); if (mp == null) { mp = new BarneyProperties(); barneys.put(ipnumber, mp); } mp.setIpNumber(ipnumber); mp.setName(name); mp.setStatus(status); mp.setDefaultLogLevel(child.selectSingleNode("properties/defaultloglevel").getText()); mp.setPreferedSmithers(child.selectSingleNode("properties/preferedsmithers").getText()); if (ipnumber.equals(myip)) { foundmynode = true; if (name.equals("unknown")) { System.out.println( "This barney is not verified change its name, use smithers todo this for ip " + myip); } else { // so we have a name (verified) return true iamok = true; } } } } if (!foundmynode) { if (retryCounter < 30) { //retry 30 times (= 5 min) to handle temp smithers downtime (eg daily restarts) retryCounter++; } else { LOG.info("LazyHomer : Creating my processing node " + LazyHomer.getSmithersUrl() + "/domain/internal/service/barney/properties"); String os = "unknown"; // we assume windows ? try { os = System.getProperty("os.name"); } catch (Exception e) { System.out.println("LazyHomer : " + e.getMessage()); } String newbody = "<fsxml>"; newbody += "<nodes id=\"" + myip + "\"><properties>"; newbody += "<name>unknown</name>"; newbody += "<status>off</status>"; newbody += "<activesmithers>" + selectedsmithers.getIpNumber() + "</activesmithers>"; newbody += "<lastseen>" + new Date().getTime() + "</lastseen>"; newbody += "<preferedsmithers>" + myip + "</preferedsmithers>"; if (isWindows()) { newbody += "<defaultloglevel>info</defaultloglevel>"; newbody += "<temporarydirectory>c:\\springfield\\barney\\temp</temporarydirectory>"; } if (isMac()) { newbody += "<defaultloglevel>info</defaultloglevel>"; newbody += "<temporarydirectory>/springfield/barney/temp</temporarydirectory>"; } if (isUnix()) { newbody += "<defaultloglevel>info</defaultloglevel>"; newbody += "<temporarydirectory>/springfield/barney/temp</temporarydirectory>"; } else { newbody += "<defaultloglevel>info</defaultloglevel>"; newbody += "<temporarydirectory>c:\\springfield\\barney\\temp</temporarydirectory>"; } newbody += "</properties></nodes></fsxml>"; smithers.put("/domain/internal/service/barney/properties", newbody, "text/xml"); } } } catch (Exception e) { LOG.info("LazyHomer exception doc"); e.printStackTrace(); } return iamok; }
From source file:org.springfield.bart.homer.LazyHomer.java
License:Open Source License
private Boolean checkKnown() { ServiceInterface smithers = ServiceManager.getService("smithers"); if (smithers == null) return false; String xml = "<fsxml><properties><depth>1</depth></properties></fsxml>"; String nodes = smithers.get("/domain/internal/service/bart/nodes", xml, "text/xml"); boolean iamok = false; try {/*w w w. j a v a 2s .c o m*/ boolean foundmynode = false; //System.out.println("NODES="+nodes); Document result = DocumentHelper.parseText(nodes); for (Iterator<Node> iter = result.getRootElement().nodeIterator(); iter.hasNext();) { Element child = (Element) iter.next(); if (!child.getName().equals("properties")) { String ipnumber = child.attributeValue("id"); String status = child.selectSingleNode("properties/status").getText(); String name = child.selectSingleNode("properties/name").getText(); // lets put all in our bart list BartProperties mp = barts.get(ipnumber); if (mp == null) { mp = new BartProperties(); barts.put(ipnumber, mp); } mp.setIpNumber(ipnumber); mp.setName(name); mp.setStatus(status); mp.setDefaultLogLevel(child.selectSingleNode("properties/defaultloglevel").getText()); mp.setPreferedSmithers(child.selectSingleNode("properties/preferedsmithers").getText()); //System.out.println("comparing ip "+ipnumber+" with "+myip); if (ipnumber.equals(myip)) { //System.out.println("ip was equal"); foundmynode = true; retryCounter = 0; if (name.equals("unknown")) { LOG.info("This bart is not verified change its name, use smithers todo this for ip " + myip); } else { // so we have a name (verified) return true iamok = true; } } else { //System.out.println("ip was not equal!"); } } } if (!foundmynode) { if (retryCounter < 30) { //retry 30 times (= 5 min) to handle temp smithers downtime (eg daily restarts) retryCounter++; } else { LOG.info("LazyHomer : Creating my processing node " + LazyHomer.getSmithersUrl() + "/domain/internal/service/bart/properties"); String os = "unknown"; // we assume windows ? try { os = System.getProperty("os.name"); } catch (Exception e) { LOG.error("LazyHomer : " + e.getMessage()); } String newbody = "<fsxml>"; newbody += "<nodes id=\"" + myip + "\"><properties>"; newbody += "<name>unknown</name>"; newbody += "<status>off</status>"; newbody += "<lastseen>" + new Date().getTime() + "</lastseen>"; newbody += "<preferedsmithers>" + myip + "</preferedsmithers>"; newbody += "<activesmithers>" + selectedsmithers.getIpNumber() + "</activesmithers>"; // i know this looks weird but left it for future extentions if (isWindows()) { newbody += "<defaultloglevel>info</defaultloglevel>"; } if (isMac()) { newbody += "<defaultloglevel>info</defaultloglevel>"; } if (isUnix()) { newbody += "<defaultloglevel>info</defaultloglevel>"; } else { newbody += "<defaultloglevel>info</defaultloglevel>"; } newbody += "</properties></nodes></fsxml>"; smithers.put("/domain/internal/service/bart/properties", newbody, "text/xml"); } } } catch (Exception e) { LOG.info("LazyHomer exception doc"); e.printStackTrace(); } return iamok; }
From source file:org.springfield.carl.fs.ParentVideo.java
License:Open Source License
/** * Determine if this video is marked as private * in the Springfield file system and for that * reason requires a ticket// w w w .j a va 2 s. c o m * * @param identifier */ public boolean isPrivate() { LOG.info("Checking video is Private for uri " + identifier); Request request = new Request(Method.GET, baseurl + "/smithers2" + identifier); Context context = new Context(); Series<Parameter> parameters = context.getParameters(); parameters.add("socketTimeout", "1000"); context.setParameters(parameters); Client client = new Client(context, Protocol.HTTP); Response response = client.handle(request); LOG.debug("response = " + response); LOG.debug(response.getEntityAsText()); boolean privateVideo = true; try { Document fsxml = DocumentHelper.parseText(response.getEntityAsText()); privateVideo = fsxml.selectSingleNode("//properties/private") == null ? true : Boolean.parseBoolean(fsxml.selectSingleNode("//properties/private").getText()); } catch (DocumentException e) { } request.release(); response.release(); LOG.debug("Is video private ? " + String.valueOf(privateVideo)); return privateVideo; }
From source file:org.springfield.carl.homer.CarlResource.java
License:Open Source License
/** * Handle GET request// w w w. java 2 s. co m */ @Get public void handleGet() { CarlProperties conf = LazyHomer.getMyCarlProperties(); String basePath = conf.getBasePath(); HttpServletRequest req = ServletUtils.getRequest(getRequest()); String baseurl = req.getScheme() + "://" + req.getServerName() + ":" + req.getLocalPort(); LOG.debug("base url = " + baseurl); String fileIdentifier = getIdentifier(Request.getCurrent().getResourceRef().getPath(), conf.getContextPath()); LOG.info("identifier = " + fileIdentifier); // set server info ServerInfo serverInfo = new ServerInfo(); serverInfo.setAgent(SERVER_INFO); getResponse().setServerInfo(serverInfo); File resource = new File(basePath + fileIdentifier); // check if requested file exists if (resource.exists() && resource.isFile()) { // check if we support this type String extension = fileIdentifier.lastIndexOf(".") == -1 ? "" : fileIdentifier.substring(fileIdentifier.lastIndexOf(".") + 1); if (!supportedExtension(extension)) { getResponse().setStatus(Status.SERVER_ERROR_NOT_IMPLEMENTED); return; } // get query Form queryForm = getRequest().getResourceRef().getQueryAsForm(CharacterSet.UTF_8); String filePath = null; Status status = null; status = Status.SUCCESS_OK; filePath = basePath + fileIdentifier; getResponse().setStatus(status); if (!status.equals(Status.SUCCESS_OK)) { return; } Series<Header> series = ((HttpRequest) getRequest()).getHeaders(); Header range = series.getFirst("range"); File file = new File(filePath); String parentVideo = ""; Pattern pattern = Pattern.compile("/domain/.*/video/[^/]*/"); Matcher matcher = pattern.matcher(fileIdentifier); if (matcher.find()) { parentVideo = matcher.group(0); } if (new ParentVideo(parentVideo, baseurl).isPrivate()) { String apiKey = conf.getApiKey(); /** TODO: Abstract ticket handling in separate class **/ String ticket = queryForm.getFirstValue("ticket", true, "").toLowerCase(); LOG.debug("ticket = " + ticket); //Range request if (range != null) { String byteRange = range.getValue(); LOG.debug("Requested byte range " + byteRange); byteRange = byteRange.substring(byteRange.indexOf("=") + 1); long start = Long.parseLong(byteRange.substring(0, byteRange.indexOf("-"))); long end = -1; if (byteRange.indexOf("-") < byteRange.length() - 1) { end = Long.parseLong(byteRange.substring(byteRange.indexOf("-") + 1)); } if (end == -1l) { end = file.length(); } LOG.debug("start = " + start + " end = " + end); //Safari fix that does multiple 0-1 requests if (start == 0l && end > 1l) { //only allowed with ticket //get ticket StringRepresentation entity = new StringRepresentation( "<fsxml><properties><uri>" + fileIdentifier + "</uri></properties></fsxml>"); entity.setMediaType(MediaType.TEXT_XML); Request request = new Request(Method.PUT, baseurl + "/lenny/acl/ticketaccess/" + ticket, entity); if (apiKey != null && !apiKey.equals("")) { Series<Header> headers = (Series<Header>) request.getAttributes() .get("org.restlet.http.headers"); if (headers == null) { headers = new Series<Header>(Header.class); request.getAttributes().put("org.restlet.http.headers", headers); } headers.set("X-Api-Key", apiKey); } Context context = new Context(); Series<Parameter> parameters = context.getParameters(); parameters.add("socketTimeout", "1000"); context.setParameters(parameters); Client client = new Client(context, Protocol.HTTP); Response response = client.handle(request); LOG.debug("response = " + response); LOG.debug(response.getEntityAsText()); try { Document fsxml = DocumentHelper.parseText(response.getEntityAsText()); boolean allowed = fsxml.selectSingleNode("//properties/allowed") == null ? false : Boolean .parseBoolean(fsxml.selectSingleNode("//properties/allowed").getText()); if (!allowed) { status = Status.CLIENT_ERROR_FORBIDDEN; getResponse().setStatus(status); return; } } catch (DocumentException e) { status = Status.SERVER_ERROR_INTERNAL; getResponse().setStatus(status); return; } request.release(); response.release(); } else { //for now unlimited allowed } } else { //entire request only allowed once //get ticket StringRepresentation entity = new StringRepresentation( "<fsxml><properties><uri>" + fileIdentifier + "</uri></properties></fsxml>"); entity.setMediaType(MediaType.TEXT_XML); Request request = new Request(Method.PUT, baseurl + "/lenny/acl/ticketaccess/" + ticket, entity); if (apiKey != null && !apiKey.equals("")) { Series<Header> headers = (Series<Header>) request.getAttributes() .get("org.restlet.http.headers"); if (headers == null) { headers = new Series<Header>(Header.class); request.getAttributes().put("org.restlet.http.headers", headers); } headers.set("X-Api-Key", apiKey); } Context context = new Context(); Series<Parameter> parameters = context.getParameters(); parameters.add("socketTimeout", "1000"); context.setParameters(parameters); Client client = new Client(context, Protocol.HTTP); Response response = client.handle(request); LOG.debug("response = " + response); LOG.debug(response.getEntityAsText()); try { Document fsxml = DocumentHelper.parseText(response.getEntityAsText()); boolean allowed = fsxml.selectSingleNode("//properties/allowed") == null ? false : Boolean.parseBoolean(fsxml.selectSingleNode("//properties/allowed").getText()); if (!allowed) { status = Status.CLIENT_ERROR_FORBIDDEN; getResponse().setStatus(status); return; } } catch (DocumentException e) { status = Status.SERVER_ERROR_INTERNAL; getResponse().setStatus(status); return; } request.release(); response.release(); } } MediaType type = MediaType.ALL; if (extension.toLowerCase().equals("jpg")) { type = MediaType.IMAGE_JPEG; } FileRepresentation rep = new FileRepresentation(file, type); getResponse().setEntity(rep); if (new ParentVideo(parentVideo, baseurl).isPrivate()) { Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes() .get(HeaderConstants.ATTRIBUTE_HEADERS); if (responseHeaders == null) { responseHeaders = new Series(Header.class); getResponse().getAttributes().put(HeaderConstants.ATTRIBUTE_HEADERS, responseHeaders); } responseHeaders.add(new Header("Pragma", "no-cache")); getResponse().getEntity().setExpirationDate(new Date(0)); getResponse().setCacheDirectives(new ArrayList<CacheDirective>()); getResponse().getCacheDirectives().add(CacheDirective.noCache()); } return; } else if (resource.exists() && resource.isDirectory()) { //resource is a folder LOG.debug("FORBIDDEN"); getResponse().setStatus(Status.CLIENT_ERROR_FORBIDDEN); return; } else { LOG.debug("NOT FOUND"); getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND); return; } }
From source file:org.springfield.carl.homer.LazyHomer.java
License:Open Source License
private Boolean checkKnown() { String xml = "<fsxml><properties><depth>1</depth></properties></fsxml>"; ServiceInterface smithers = ServiceManager.getService("smithers"); if (smithers == null) return false; String nodes = smithers.get("/domain/internal/service/carl/nodes", xml, "text/xml"); boolean iamok = false; try {/* ww w. j a v a2 s . c o m*/ boolean foundmynode = false; Document result = DocumentHelper.parseText(nodes); for (Iterator<Node> iter = result.getRootElement().nodeIterator(); iter.hasNext();) { Element child = (Element) iter.next(); if (!child.getName().equals("properties")) { String ipnumber = child.attributeValue("id"); String status = child.selectSingleNode("properties/status").getText(); String name = child.selectSingleNode("properties/name").getText(); // lets put all in our carls list CarlProperties mp = carls.get(ipnumber); if (mp == null) { mp = new CarlProperties(); carls.put(ipnumber, mp); } mp.setIpNumber(ipnumber); mp.setName(name); mp.setStatus(status); mp.setDefaultLogLevel(child.selectSingleNode("properties/defaultloglevel").getText()); mp.setPreferedSmithers(child.selectSingleNode("properties/preferedsmithers").getText()); mp.setBasePath(child.selectSingleNode("properties/basepath").getText()); mp.setContextPath(child.selectSingleNode("properties/contextpath").getText()); mp.setApiKey(apiKey); if (ipnumber.equals(myip)) { foundmynode = true; retryCounter = 0; if (name.equals("unknown")) { System.out.println( "This carl is not verified change its name, use smithers todo this for ip " + myip); } else { // so we have a name (verified) return true iamok = true; } } } } if (!foundmynode) { if (retryCounter < 30) { //retry 30 times (= 5 min) to handle temp smithers downtime (eg daily restarts) retryCounter++; } else { LOG.info("LazyHomer : Creating my processing node " + LazyHomer.getSmithersUrl() + "/domain/internal/service/carl/properties"); String os = "unknown"; // we assume windows ? try { os = System.getProperty("os.name"); } catch (Exception e) { System.out.println("LazyHomer : " + e.getMessage()); } String newbody = "<fsxml><properties>"; newbody += "<info>File server with ticket support</info></properties>"; newbody += "<nodes id=\"" + myip + "\"><properties>"; newbody += "<name>unknown</name>"; newbody += "<status>off</status>"; newbody += "<activesmithers>" + selectedsmithers.getIpNumber() + "</activesmithers>"; newbody += "<lastseen>" + new Date().getTime() + "</lastseen>"; newbody += "<preferedsmithers>" + myip + "</preferedsmithers>"; newbody += "<defaultloglevel>info</defaultloglevel>"; newbody += "<basepath>/usr/local/data</basepath>"; newbody += "<contextpath>/carl</contextpath>"; newbody += "</properties></nodes></fsxml>"; smithers.put("/domain/internal/service/carl/properties", newbody, "text/xml"); } } } catch (Exception e) { LOG.info("LazyHomer exception doc"); e.printStackTrace(); } return iamok; }
From source file:org.springfield.edna.homer.LazyHomer.java
License:Open Source License
private static void readMounts() { mounts = new HashMap<String, MountProperties>(); ServiceInterface smithers = ServiceManager.getService("smithers"); if (smithers == null) { System.out.println("can't reach smithers"); return;// www .j av a2 s .c o m } // String mountslist = LazyHomer.sendRequest("GET","/domain/internal/service/edna/mounts",null,null); String mountslist = smithers.get("/domain/internal/service/edna/mounts", null, null); try { Document result = DocumentHelper.parseText(mountslist); for (Iterator<Node> iter = result.getRootElement().nodeIterator(); iter.hasNext();) { Element child = (Element) iter.next(); if (!child.getName().equals("properties")) { String name = child.attributeValue("id"); String hostname = child.selectSingleNode("properties/hostname").getText(); String path = child.selectSingleNode("properties/path").getText(); String account = child.selectSingleNode("properties/account").getText(); String password = child.selectSingleNode("properties/password").getText(); String protocol = child.selectSingleNode("properties/protocol").getText(); MountProperties mp = new MountProperties(); mp.setHostname(hostname); mp.setPath(path); mp.setAccount(account); mp.setPassword(password); mp.setProtocol(protocol); mounts.put(name, mp); } } } catch (DocumentException e) { LOG.info("LazyHomer: " + e.getMessage()); } }
From source file:org.springfield.edna.homer.LazyHomer.java
License:Open Source License
private Boolean checkKnown() { ServiceInterface smithers = ServiceManager.getService("smithers"); if (smithers == null) { System.out.println("can't reach smithers"); return false; }//from w w w . j a v a 2s . c om String xml = "<fsxml><properties><depth>1</depth></properties></fsxml>"; //String nodes = LazyHomer.sendRequest("GET","/domain/internal/service/edna/nodes",xml,"text/xml"); String nodes = smithers.get("/domain/internal/service/edna/nodes", xml, "text/xml"); //System.out.println("NODES="+nodes); boolean iamok = false; try { boolean foundmynode = false; Document result = DocumentHelper.parseText(nodes); for (Iterator<Node> iter = result.getRootElement().nodeIterator(); iter.hasNext();) { Element child = (Element) iter.next(); if (!child.getName().equals("properties")) { String ipnumber = child.attributeValue("id"); String status = child.selectSingleNode("properties/status").getText(); String name = child.selectSingleNode("properties/name").getText(); // lets put all in our edna list EdnaProperties mp = ednas.get(ipnumber); if (mp == null) { mp = new EdnaProperties(); ednas.put(ipnumber, mp); } mp.setIpNumber(ipnumber); mp.setName(name); mp.setStatus(status); mp.setDefaultLogLevel(child.selectSingleNode("properties/defaultloglevel").getText()); mp.setPreferedSmithers(child.selectSingleNode("properties/preferedsmithers").getText()); mp.setImagePath(child.selectSingleNode("properties/imagepath").getText()); if (ipnumber.equals(myip)) { foundmynode = true; retryCounter = 0; if (name.equals("unknown")) { System.out.println( "This edna is not verified change its name, use smithers todo this for ip " + myip); } else { // so we have a name (verified) return true iamok = true; } } } } if (!foundmynode) { if (retryCounter < 30) { //retry 30 times (= 5 min) to handle temp smithers downtime (eg daily restarts) retryCounter++; } else { LOG.info("LazyHomer : Creating my processing node " + LazyHomer.getSmithersUrl() + "/domain/internal/service/edna/properties"); String os = "unknown"; // we assume windows ? try { os = System.getProperty("os.name"); } catch (Exception e) { System.out.println("LazyHomer : " + e.getMessage()); } String newbody = "<fsxml>"; newbody += "<nodes id=\"" + myip + "\"><properties>"; newbody += "<name>unknown</name>"; newbody += "<status>off</status>"; newbody += "<activesmithers>" + selectedsmithers.getIpNumber() + "</activesmithers>"; newbody += "<lastseen>" + new Date().getTime() + "</lastseen>"; newbody += "<preferedsmithers>" + myip + "</preferedsmithers>"; if (isWindows()) { newbody += "<defaultloglevel>info</defaultloglevel>"; newbody += "<imagepath>c:\\springfield\\tomcat\\webapps\\ROOT\\images</imagepath>"; newbody += "<temporarydirectory>c:\\springfield\\edna\\temp</temporarydirectory>"; } if (isMac()) { newbody += "<defaultloglevel>info</defaultloglevel>"; newbody += "<imagepath>/springfield/tomcat/webapps/ROOT/images</imagepath>"; newbody += "<temporarydirectory>/springfield/edna/temp</temporarydirectory>"; } if (isUnix()) { newbody += "<defaultloglevel>info</defaultloglevel>"; newbody += "<imagepath>/springfield/tomcat/webapps/ROOT/images</imagepath>"; newbody += "<temporarydirectory>/springfield/edna/temp</temporarydirectory>"; } else { newbody += "<defaultloglevel>info</defaultloglevel>"; newbody += "<imagepath>/springfield/tomcat/webapps/ROOT/images</imagepath>"; newbody += "<temporarydirectory>c:\\springfield\\edna\\temp</temporarydirectory>"; } newbody += "</properties></nodes></fsxml>"; smithers.put("/domain/internal/service/edna/properties", newbody, "text/xml"); } } } catch (Exception e) { LOG.info("LazyHomer exception doc"); e.printStackTrace(); } return iamok; }
From source file:org.springfield.flanders.homer.LazyHomer.java
License:Open Source License
private Boolean checkKnown() { String xml = "<fsxml><properties><depth>1</depth></properties></fsxml>"; ServiceInterface smithers = ServiceManager.getService("smithers"); if (smithers == null) { LOG.error("No smithers found to check nodes properties!"); return false; }/*from w ww . j a va 2 s.co m*/ String nodes = smithers.get("/domain/internal/service/flanders/nodes", xml, "text/xml"); boolean iamok = false; try { boolean foundmynode = false; Document result = DocumentHelper.parseText(nodes); for (Iterator<Node> iter = result.getRootElement().nodeIterator(); iter.hasNext();) { Element child = (Element) iter.next(); if (!child.getName().equals("properties")) { String ipnumber = child.attributeValue("id"); String status = child.selectSingleNode("properties/status").getText(); String name = child.selectSingleNode("properties/name").getText(); // lets put all in our flanders list FlandersProperties fp = flanders.get(ipnumber); if (fp == null) { fp = new FlandersProperties(); flanders.put(ipnumber, fp); } fp.setIpNumber(ipnumber); fp.setName(name); fp.setStatus(status); fp.setDefaultLogLevel(child.selectSingleNode("properties/defaultloglevel").getText()); fp.setPreferedSmithers(child.selectSingleNode("properties/preferedsmithers").getText()); fp.setFFMPEGPath(child.selectSingleNode("properties/ffmpegpath").getText()); fp.setTemporaryDirectory(child.selectSingleNode("properties/temporarydirectory").getText()); fp.setMjpegIndexPath(child.selectSingleNode("properties/mjpegindexpath").getText()); if (ipnumber.equals(myip)) { foundmynode = true; if (name.equals("unknown")) { System.out.println( "This flanders is not verified change its name, use smithers todo this for ip " + myip); } else { // so we have a name (verified) return true iamok = true; if (child.selectSingleNode("properties/port") == null || !child.selectSingleNode("properties/port").getText() .equals(Integer.toString(smithers_port))) { smithers.put( "/domain/internal/service/flanders/nodes/" + ipnumber + "/properties/port", "" + smithers_port, "text/xml"); } } } } } if (!foundmynode) { if (retryCounter < 30) { //retry 30 times (= 5 min) to handle temp smithers downtime (eg daily restarts) retryCounter++; } else { LOG.info("LazyHomer : Creating my processing node " + LazyHomer.getSmithersUrl() + "/domain/internal/service/flanders/properties"); String os = "unknown"; // we assume windows ? try { os = System.getProperty("os.name"); } catch (Exception e) { System.out.println("LazyHomer : " + e.getMessage()); } String newbody = "<fsxml><properties>"; newbody += "<info>Metadata Extraction nodes</info></properties>"; newbody += "<nodes id=\"" + myip + "\"><properties>"; newbody += "<name>unknown</name>"; newbody += "<status>off</status>"; newbody += "<activesmithers>" + selectedsmithers.getIpNumber() + "</activesmithers>"; newbody += "<lastseen>" + new Date().getTime() + "</lastseen>"; newbody += "<port>" + smithers_port + "</port>"; newbody += "<preferedsmithers>" + myip + "</preferedsmithers>"; if (isWindows()) { newbody += "<defaultloglevel>info</defaultloglevel>"; newbody += "<ffmpegpath>c:\\springfield\\flanders\\bin</ffmpegpath>"; newbody += "<temporarydirectory>c:\\springfield\\flanders\\temp</temporarydirectory>"; newbody += "<mjpegindexpath>c:\\springfield\\flanders\\bin\\mjpeg_index</mjpegindexpath>"; } if (isMac()) { newbody += "<defaultloglevel>info</defaultloglevel>"; newbody += "<ffmpegpath>/springfield/flanders/bin</ffmpegpath>"; newbody += "<temporarydirectory>/springfield/flanders/temp</temporarydirectory>"; newbody += "<mjpegindexpath>/springfield/flanders/bin/mjpeg_index</mjpegindexpath>"; } if (isUnix()) { newbody += "<defaultloglevel>info</defaultloglevel>"; newbody += "<ffmpegpath>/springfield/flanders/bin</ffmpegpath>"; newbody += "<temporarydirectory>/springfield/flanders/temp</temporarydirectory>"; newbody += "<mjpegindexpath>/springfield/flanders/bin/mjpeg_index</mjpegindexpath>"; } else { newbody += "<defaultloglevel>info</defaultloglevel>"; newbody += "<ffmpegpath>c:\\springfield\\flanders\\bin</ffmpegpath>"; newbody += "<temporarydirectory>c:\\springfield\\flanders\\temp</temporarydirectory>"; newbody += "<mjpegindexpath>c:\\springfield\\flanders\\bin\\mjpeg_index</mjpegindexpath>"; } newbody += "</properties></nodes></fsxml>"; smithers.put("/domain/internal/service/flanders/properties", newbody, "text/xml"); } } } catch (Exception e) { LOG.info("LazyHomer exception doc"); e.printStackTrace(); } return iamok; }