diff --git a/common/pom.xml b/common/pom.xml index 7de18fd49..e178e2393 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -34,11 +34,6 @@ simple-xml 2.7.1 - - com.fasterxml.jackson.dataformat - jackson-dataformat-xml - 2.9.9 - diff --git a/java/pom.xml b/java/pom.xml index c305a3284..da4c7522c 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -115,11 +115,6 @@ jackson-databind 2.9.9 - - com.fasterxml.jackson.dataformat - jackson-dataformat-xml - 2.9.9 - com.google.apis google-api-services-androidpublisher diff --git a/java/src/main/java/com/genexus/util/GXServices.java b/java/src/main/java/com/genexus/util/GXServices.java index f9596de94..6819b820f 100644 --- a/java/src/main/java/com/genexus/util/GXServices.java +++ b/java/src/main/java/com/genexus/util/GXServices.java @@ -1,26 +1,15 @@ package com.genexus.util; import java.io.File; -import java.io.IOException; import java.util.Hashtable; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; +import com.genexus.ApplicationContext; import com.genexus.ModelContext; import com.genexus.internet.HttpContext; -import com.genexus.util.cloudservice.Property; -import com.genexus.util.cloudservice.Service; -import com.genexus.util.cloudservice.Services; import com.genexus.webpanels.HttpContextWeb; -import com.genexus.diagnostics.core.ILogger; -import com.genexus.diagnostics.core.LogManager; +import com.genexus.xml.XMLReader; public class GXServices { - - public static final ILogger logger = LogManager.getLogger(GXServices.class); - private static final boolean DEBUG = com.genexus.DebugFlag.DEBUG; public static final String WEBNOTIFICATIONS_SERVICE = "WebNotifications"; public static final String STORAGE_SERVICE = "Storage"; @@ -55,46 +44,29 @@ public static void endGXServices() { instance = null; } - public static void loadFromFile(String basePath, String fileName, GXServices services) { + public static void loadFromFile(String basePath, String fileName, GXServices services){ if (basePath.equals("")) { basePath = services.configBaseDirectory(); } String fullPath = basePath + fileName; - XmlMapper xmlMapper = new XmlMapper(); - xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true); - Services xmlServices = null; - try { - xmlServices = xmlMapper.readValue(new File(fullPath), Services.class); - } catch (JsonParseException e) { - logger.error(e.getMessage(), e); - e.printStackTrace(); - } catch (JsonMappingException e) { - logger.error(e.getMessage(), e); - e.printStackTrace(); - } catch (IOException e) { - logger.error(e.getMessage(), e); - e.printStackTrace(); - } - - if (services == null) - services = new GXServices(); - - for (Service xmlService : xmlServices.getService()) { - GXService service = new GXService(); - service.setName(xmlService.getName()); - service.setType(xmlService.getType()); - service.setClassName(xmlService.getClassName()); - service.setAllowMultiple(xmlService.getAllowMultiple()); - GXProperties ptys = new GXProperties(); - for (Property xmlPty : xmlService.getProperties().getProperty()) { - ptys.add(xmlPty.getName(), xmlPty.getValue()); + XMLReader reader = new XMLReader(); + reader.open(fullPath); + reader.readType(1, "Services"); + reader.read(); + if (reader.getErrCode() == 0) { + while (!reader.getName().equals("Services")) { + services.processService(reader); + reader.read(); + if (reader.getName().equals("Service") && reader.getNodeType() == 2) // + reader.read(); } - service.setProperties(ptys); - - if (service.getAllowMultiple()) { - services.services.put(service.getType() + ":" + service.getName(), service); - } else { - services.services.put(service.getType(), service); + reader.close(); + } + else + { + if (!ApplicationContext.getInstance().getReorganization() && DEBUG) + { + System.out.println("GXServices - Could not load Services Config: " + fullPath + " - " + reader.getErrDescription()); } } } @@ -108,13 +80,15 @@ private String configBaseDirectory() { if (ModelContext.getModelContext() != null) { HttpContext webContext = (HttpContext) ModelContext.getModelContext().getHttpContext(); if ((webContext != null) && (webContext instanceof HttpContextWeb)) { - baseDir = com.genexus.ModelContext.getModelContext().getHttpContext().getDefaultPath() + File.separator - + "WEB-INF" + File.separatorChar; + baseDir = com.genexus.ModelContext.getModelContext() + .getHttpContext().getDefaultPath() + + File.separator + "WEB-INF" + File.separatorChar; } } if (baseDir.equals("")) { String servletPath = com.genexus.ApplicationContext.getInstance().getServletEngineDefaultPath(); - if (servletPath != null && !servletPath.equals("")) { + if (servletPath != null && !servletPath.equals("")) + { baseDir = servletPath + File.separator + "WEB-INF" + File.separatorChar; } } @@ -125,15 +99,66 @@ private void readServices(String basePath) { if (basePath.equals("")) basePath = configBaseDirectory(); - if (new File(basePath + SERVICES_DEV_FILE).exists()) { + if (new File(basePath + SERVICES_DEV_FILE).exists()){ loadFromFile(basePath, SERVICES_DEV_FILE, this); } - if (new File(basePath + SERVICES_FILE).exists()) { + if (new File(basePath + SERVICES_FILE).exists()){ loadFromFile(basePath, SERVICES_FILE, this); } } + private void processService(XMLReader reader) { + short result; + result = reader.readType(1, "Name"); + String name = new String(reader.getValue()); + + result = reader.readType(1, "Type"); + String type = new String(reader.getValue()); + + result = reader.readType(1, "ClassName"); + String className = new String(reader.getValue()); + + boolean allowMultiple = false; + reader.read(); + if (reader.getName() == "AllowMultiple") + { + allowMultiple = Boolean.parseBoolean(reader.getValue()); + reader.read(); + } + GXProperties properties = processProperties(reader); + + GXService service = new GXService(); + service.setName(name); + service.setType(type); + service.setClassName(className); + service.setAllowMultiple(allowMultiple); + service.setProperties(properties); + if (service.getAllowMultiple()){ + services.put(service.getType() + ":" + service.getName(), service); + } + else{ + services.put(type, service); + } + } + + private GXProperties processProperties(XMLReader reader) { + short result; + GXProperties properties = new GXProperties(); + reader.read(); + while (reader.getName().equals("Property")) { + result = reader.readType(1, "Name"); + String name = new String(reader.getValue()); + result = reader.readType(1, "Value"); + String value = new String(reader.getValue()); + properties.add(name, value); + reader.read(); + reader.read(); + } + return properties; + } + public GXService get(String name) { return services.get(name); } + } \ No newline at end of file diff --git a/java/src/main/java/com/genexus/util/cloudservice/Properties.java b/java/src/main/java/com/genexus/util/cloudservice/Properties.java deleted file mode 100644 index 24a4843b2..000000000 --- a/java/src/main/java/com/genexus/util/cloudservice/Properties.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.genexus.util.cloudservice; - -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; - -public class Properties -{ - @JacksonXmlElementWrapper(useWrapping = false) - @JacksonXmlProperty(localName = "Property") - private Property[] property; - - public Property[] getProperty () - { - return property; - } - - public void setProperty (Property[] property) - { - this.property = property; - } - - @Override - public String toString() - { - return "ClassPojo [Property = "+property+"]"; - } -} \ No newline at end of file diff --git a/java/src/main/java/com/genexus/util/cloudservice/Property.java b/java/src/main/java/com/genexus/util/cloudservice/Property.java deleted file mode 100644 index ef8e231ee..000000000 --- a/java/src/main/java/com/genexus/util/cloudservice/Property.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.genexus.util.cloudservice; - -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; - -@JsonPropertyOrder({ "Name", "Value" }) -public class Property -{ - - @JacksonXmlProperty(localName = "Value") - private String value; - - @JacksonXmlProperty(localName = "Name") - private String name; - - public String getValue () - { - return value; - } - - public void setValue (final String value) { - this.value = value; - } - - public String getName() { - return name; - } - - public void setName(final String name) - { - this.name = name; - } - - @Override - public String toString() - { - return "ClassPojo [Value = "+value+", Name = "+name+"]"; - } -} \ No newline at end of file diff --git a/java/src/main/java/com/genexus/util/cloudservice/Service.java b/java/src/main/java/com/genexus/util/cloudservice/Service.java deleted file mode 100644 index be8ba83fa..000000000 --- a/java/src/main/java/com/genexus/util/cloudservice/Service.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.genexus.util.cloudservice; - -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; - -@JsonPropertyOrder({ "Name", "Type", "ClassName", "AllowMultiple", "Properties"}) -public class Service { - - @JacksonXmlProperty(localName = "Type") - private String type; - - @JacksonXmlProperty(localName = "Name") - private String name; - - @JacksonXmlProperty(localName = "AllowMultiple") - private boolean allowMultiple; - - @JacksonXmlProperty(localName = "ClassName") - private String className; - - @JacksonXmlProperty(localName = "Properties") - private Properties properties; - - - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getClassName() { - return className; - } - - public void setClassName(String className) { - this.className = className; - } - - public boolean getAllowMultiple(){ - return this.allowMultiple; - } - - public void setAllowMultiple(boolean allowMultiple){ - this.allowMultiple = allowMultiple; - } - - public Properties getProperties() { - return properties; - } - - public void setProperties(Properties properties) { - this.properties = properties; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @Override - public String toString() { - return "ClassPojo [Type = " + type + ", ClassName = " + className + ", Properties = " + properties + ", Name = " - + name + "]"; - } -} \ No newline at end of file diff --git a/java/src/main/java/com/genexus/util/cloudservice/Services.java b/java/src/main/java/com/genexus/util/cloudservice/Services.java deleted file mode 100644 index 86264925e..000000000 --- a/java/src/main/java/com/genexus/util/cloudservice/Services.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.genexus.util.cloudservice; - -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; - -@JacksonXmlRootElement( localName = "Services") -public class Services -{ - @JacksonXmlElementWrapper(useWrapping = false) - @JacksonXmlProperty(localName = "Service") - private Service[] service; - - public Service[] getService () - { - return service; - } - - public void setService (Service[] Service) - { - this.service = Service; - } - - @Override - public String toString() - { - return "ClassPojo [Service = "+service+"]"; - } -} \ No newline at end of file