Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Saturday, June 10, 2017

Always specify xml version in a XML file

<?xml version="1.0" encoding="UTF-8"?>
There was a case where one forgot it in a beans.xml file, and WebLogic tries to open a Socket to retrieve some stuff (no clue what) attempting some alternate way to retrieve the version information. Crazy. It's crazy to use XML in any case.... XML is the biggest failure in IT history.

"[STANDBY] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)'" daemon prio=10 tid=0x00007f1a380184b0 nid=0x1f65 runnable [0x00007f1aa47bb000]

   java.lang.Thread.State: RUNNABLE

               at java.net.PlainSocketImpl.socketConnect(Native Method)

               at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:344)

               - locked <0x00000007f12f65b0> (a java.net.SocksSocketImpl)

               at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)

               at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)

               at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)

               at java.net.Socket.connect(Socket.java:579)

               at java.net.Socket.connect(Socket.java:528)

               at sun.net.NetworkClient.doConnect(NetworkClient.java:180)

               at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)

               at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)

               - locked <0x00000007f12f6528> (a sun.net.www.http.HttpClient)

               at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)

               at sun.net.www.http.HttpClient.New(HttpClient.java:308)

               at sun.net.www.http.HttpClient.New(HttpClient.java:326)

               at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1039)

               at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:975)

               at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:893)

               at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1343)

               - locked <0x00000007f12f23e8> (a sun.net.www.protocol.http.HttpURLConnection)

               at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:664)

               at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:148)

               at com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaParsingConfig.parse(SchemaParsingConfig.java:582)

               at com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaParsingConfig.parse(SchemaParsingConfig.java:685)

               at com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOMParser.parse(SchemaDOMParser.java:530)

               at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getSchemaDocument(XSDHandler.java:2173)

               at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:569)

               at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:613)

               at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.findSchemaGrammar(XMLSchemaValidator.java:2446)

               at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1766)

               at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:740)

               at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:374)

               at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:613)

               at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3132)

               at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:856)

               at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)

               at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)

               at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:504)

               at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)

               at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)

               at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)

               at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)

               at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:642)

               at weblogic.xml.jaxp.WebLogicXMLReader.parse(WebLogicXMLReader.java:133)

               at javax.xml.parsers.SAXParser.parse(SAXParser.java:392)

               at org.jboss.weld.xml.BeansXmlParser.parse(BeansXmlParser.java:107)

               at org.jboss.weld.xml.BeansXmlParser.parse(BeansXmlParser.java:137)

               at org.jboss.weld.bootstrap.WeldBootstrap.parse(WeldBootstrap.java:485)

               at org.jboss.weld.bootstrap.WeldBootstrap.parse(WeldBootstrap.java:481)

               at com.oracle.injection.provider.weld.BasicBeanDeploymentArchive.getBeansXml(BasicBeanDeploymentArchive.java:87)

               at org.jboss.weld.bootstrap.BeanDeployment.loadClasses(BeanDeployment.java:154)

               at org.jboss.weld.bootstrap.BeanDeployment.createBeans(BeanDeployment.java:184)

               at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:349)

               - locked <0x00000007ecfe8cd0> (a org.jboss.weld.bootstrap.WeldBootstrap)

               at com.oracle.injection.provider.weld.WeldInjectionContainer.deploy(WeldInjectionContainer.java:103)

               at com.oracle.injection.integration.CDIAppDeploymentExtension.initCdi(CDIAppDeploymentExtension.java:74)

               at com.oracle.injection.integration.CDIAppDeploymentExtension.activate(CDIAppDeploymentExtension.java:49)

               at weblogic.application.internal.flow.AppDeploymentExtensionFlow.activate(AppDeploymentExtensionFlow.java:37)

               at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:729)

               at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)

               at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:258)

               at weblogic.application.internal.EarDeployment.activate(EarDeployment.java:61)

               at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:165)

               at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:80)

               at weblogic.deploy.internal.targetserver.BasicDeployment.activate(BasicDeployment.java:226)

               at weblogic.deploy.internal.targetserver.BasicDeployment.activateFromServerLifecycle(BasicDeployment.java:418)

               at weblogic.management.deploy.internal.DeploymentAdapter$1.doActivate(DeploymentAdapter.java:51)

               at weblogic.management.deploy.internal.DeploymentAdapter.activate(DeploymentAdapter.java:200)

               at weblogic.management.deploy.internal.AppTransition$2.transitionApp(AppTransition.java:30)

               at weblogic.management.deploy.internal.ConfiguredDeployments.transitionApps(ConfiguredDeployments.java:240)

               at weblogic.management.deploy.internal.ConfiguredDeployments.activate(ConfiguredDeployments.java:169)

               at weblogic.management.deploy.internal.ConfiguredDeployments.deploy(ConfiguredDeployments.java:123)

               at weblogic.management.deploy.internal.DeploymentServerService.resume(DeploymentServerService.java:211)

               at weblogic.management.deploy.internal.DeploymentServerService.start(DeploymentServerService.java:119)

               at weblogic.server.AbstractServerService.postConstruct(AbstractServerService.java:78)

               at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)

               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

               at java.lang.reflect.Method.invoke(Method.java:606)

               at org.glassfish.hk2.utilities.reflection.ReflectionHelper.invoke(ReflectionHelper.java:1017)

               at org.jvnet.hk2.internal.ClazzCreator.postConstructMe(ClazzCreator.java:388)

               at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:430)

               at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:456)

               at org.glassfish.hk2.runlevel.internal.AsyncRunLevelContext.findOrCreate(AsyncRunLevelContext.java:225)

               at org.glassfish.hk2.runlevel.RunLevelContext.findOrCreate(RunLevelContext.java:82)

               at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2488)

               at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:98)

               - locked <0x00000007063c7078> (a java.lang.Object)

               at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:606)

               at org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:77)

               at org.jvnet.hk2.internal.ClazzCreator.resolve(ClazzCreator.java:231)

               at org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(ClazzCreator.java:254)

               at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:413)

               at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:456)

               at org.glassfish.hk2.runlevel.internal.AsyncRunLevelContext.findOrCreate(AsyncRunLevelContext.java:225)

               at org.glassfish.hk2.runlevel.RunLevelContext.findOrCreate(RunLevelContext.java:82)

               at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2488)

               at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:98)

               - locked <0x00000007ffe69e58> (a java.lang.Object)

               at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:87)

               at org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$QueueRunner.oneJob(CurrentTaskFuture.java:1162)

               at org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$QueueRunner.run(CurrentTaskFuture.java:1147)

               at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:553)

               at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311)

               at weblogic.work.ExecuteThread.run(ExecuteThread.java:263)

               




Saturday, August 18, 2012

Parsing XML in Java, how frustrating...

<%@page import="java.net.*" %>
<%@page import="java.io.*" %>
<%@page import="javax.xml.xpath.*" %>
<%@page import="org.xml.sax.*" %>
<%@page import="javax.xml.parsers.*" %>
<%@page import="org.w3c.dom.*" %>

  

<% 
   String urlToRead = "http://acme.com:8101/sbresource?SCHEMA/httptest/version";
      URL url;
      HttpURLConnection conn;
      BufferedReader rd;
      String line;
      String xml = "";
      String version = "N/A";
      try {
         url = new URL(urlToRead);
         conn = (HttpURLConnection) url.openConnection();
         conn.setRequestMethod("GET");
         rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
         while ((line = rd.readLine()) != null) {
          xml += line;
         }
         rd.close();
      } catch (Exception e) {
         e.printStackTrace();
      }
      XPathFactory factory = XPathFactory.newInstance();
      XPath xpath = factory.newXPath();
      //String expression = "//xs:element[@name='version']/@id";
      String expression = "//*";
      DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      InputSource is = new InputSource(new StringReader(xml));
      Document document = builder.parse(is);
      out.write("parsed");
      Node widgetNode = (Node) xpath.evaluate(expression, document, XPathConstants.NODE);
      out.write("evaluated");
      out.write(widgetNode.getTextContent());
      out.write("widgetNode is null? " + (widgetNode == null));
%>



I promise you, this is hell when you compare to XML Parsing in Groovy or Python...



Saturday, May 26, 2012

Replacing values in XML is easy with XmlTask

http://www.oopsconsultancy.com/software/xmltask/

especially the replace command is quite useful:

  <xmltask source="../${env.BUILD_ENVIRONMENT}/tmp/System/SMTP_Servers/EmailServer.SMTPServer" dest="../${env.BUILD_ENVIRONMENT}/tmp/System/SMTP_Servers/EmailServer.SMTPServer">
    <!-- change email server URL -->
    <replace path="/xml-fragment/*[local-name(.)='serverURL']/text()" withText="${EmailServer.smtp.Server_URL}"/>
    <!-- change email server port number -->
    <replace path="/xml-fragment/*[local-name(.)='portNumber']/text()" withText="${EmailServer.smtp.Port_Number}"/>
  </xmltask>
  


as explained in this excellent post, you can use it to customize a OSB project

Wednesday, November 2, 2011

XML parsing in Python/Jython/ WLST: lxml , libxml2 and minidom

you have the option of using libxml2 http://users.skynet.be/sbi/libxml-python/

but I read better things about http://lxml.de/. To use lxml you must first install http://users.skynet.be/sbi/libxml-python/.


To determine which version of Python you are running in WLST, do

import sys
sys.version_info


for instance with WLS 10.3.5 I get:

(2, 2, 1, 'final', 0)

So the most recent version of libxml2 available for Python 2.2.1 is the 2.6.9:

http://users.skynet.be/sbi/libxml-python/libxml2-python-2.6.9.win32-py2.2.exe

Anyway lxml requires Python 2.4 as a minimum, so you are screwed. In any case WLST uses Jython, not Python, so again you are screwed unless you install Python.


Alternatively, use minidom which is supported in WLST:

from xml.dom.minidom import parse
dom1 = parse('ALSBCustomizationFile.xml'
)

dom1 is a xml.dom.minidom.Document

here the javadoc

then you can do:

envValueAssignments=dom1.getElementsByTagName('cus:envValueAssignments')

and you get a NodeList http://docs.python.org/library/xml.dom.html

if you do:


print envValueAssignments[0].__class__

it says
xml.dom.minidom.Element
whose javadoc is here


you can also do

print envValueAssignments[0].toxml()


Honestly parsing is very painful using a DOM-based approach.
I would rather use Groovy which has got a much more intuitive semantic approach to xml parsing.

Sunday, July 31, 2011

Best XML editor

I have used Altova XML Spy, but it's not free http://www.altova.com/xmlspy.html
I hear good things about Oxygen - also not free http://www.oxygenxml.com/

I have been recommended Komodo Edit http://www.activestate.com/komodo-edit/downloads

I will start using it from today.

Eclipse XML Buddy plugin is so-and-so http://download.cnet.com/XMLBuddy/3000-7241_4-10405546.html

Also Eclipse WTP is so-and.so http://www.eclipse.org/webtools/index.php

As reported in the comments, a star also for  Liquid XML editor ( http://www.liquid-technologies.com/xml-editor.aspx )

Saturday, March 19, 2011

Generating a GUI to edit XML, starting from XSD

When you give your customer a XML-based interface, you better help him produce the XML, at least for testers to play with your service.... not everybody is comfortable with XMLSpy (besides, its licence is VERY expensive).

I have tried Excel as a XML editor, but it flattens a complex graph to a single row,
so every repetead dependent object occupies a new row and forces you to repeat the master object data (sucks).
Besides when you try to export XML it keeps saying:

Cannot save or export XML data. The XML maps in this workbook are not exportable

I have tried adding ID to help Excel track dependent objects:

at the end of your complex type, add:

xs:attribute name="id" type="xs:ID" use="required"

and the ancestor should have:

xs:attribute name="idref" type="xs:IDREF" use="required"

here some examples (really cool musing over Schema Design):
http://www.xfront.com/GlobalVersusLocal.html




here how to define an id

P1 is a good ID
1 is NOT a good ID

IDs must be unique in the document, otherwise you get a validation error

Still Excel gets confused and gives unhelpful error messages when exporting.

Looking for some better way to visually edit I found JAXFront

Here an excellent demo of JaxFront XUIeditor

here the FAQs; My first question was : does it generate Java code, And the answer is: no, it generates a XUI file which is then run my the JaxFront engine.


I have tested on my XSD and the result was quite satisfactory.

Saturday, February 26, 2011

Quick Java code to convert a Java object into XML

I keep having to do it and I keep forgetting...

private static String objectToXML(Object object, Class clazz) throws JAXBException,
 PropertyException {

 JAXBContext jc = JAXBContext.newInstance(clazz);
 Marshaller marshaller = jc.createMarshaller();
 marshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
 ByteArrayOutputStream baos = new ByteArrayOutputStream();   
 marshaller.marshal(object, baos);
 return new String(baos.toByteArray());
}
 



This is another working example (courtesy of Adam Bien):



import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Duke {
 private String language;
 private int age;
 
 
 @Override
 public String toString() {
  return "Duke [language=" + language + ", age=" + age + "]";
 }

 public Duke(String language, int age) {
  super();
  this.language = language;
  this.age = age;
 }
 
 public Duke() {
  
 }
 
}





import java.io.File;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import org.junit.jupiter.api.Test;

public class DukeTest {
 @Test
 public void testSerialization() throws JAXBException {
  JAXBContext context = JAXBContext.newInstance(Duke.class);
  Marshaller marshaller = context.createMarshaller();
  marshaller.marshal(new Duke("Java", 2), new File("duke.xml"));
  Unmarshaller unmarshaller = context.createUnmarshaller();
  Object unmarshalled = unmarshaller.unmarshal(new File("duke.xml"));
  System.out.println(unmarshalled);
 }
}



Thursday, January 20, 2011

OSB parsing a file into XML with FileAdapter: memory consumption


this is the behaviour of memory every time we parse a 5MB file into XML.
Basically 5MB of info generates a 500 MB spike in the heap memory - luckily garbage collected quite soon.

A 10000% increase in memory occupation in not such a great idea.

The believers that XML is the next best thing after sex should probably change their mind. And not in the sense that XML is better than sex.

Monday, October 4, 2010

Data Serialization standards.... beyond XML

I am reading a series of EXCELLENT pages on the Wikipedia:

XML

JSON

YAML


I am not saying one is better than the other. Each has pros and cons.

XML disturbs me for his prolixity, the entities like < and > and &, and the close tags . I like it because it's fairly robust and unambiguous - barred Namespaces.

JSON disturbs me for his quotes. I like its simplicity.

YAML disturbs for the reliance on indentation and special notations. I like the rigorous representation of complex data structures.


But the huge question mark raising in my head is: why on Earth do we need a format that is directly readable/editable by humans?
So that one can use Notepad or vi to edit them?

Ok, then I will give you a YAMLNotepad and a YAMLvi and we move away from a (necessarily inefficient) human readable format and use a more rigorous binary representation, mutuated for instance from Java .ser format or Coherence POF format or TIBCO or whatever other high-speed serialization standard.
We will gain in performance, validation, readibility (you can customize the program to display in whatever format you want, attaching the stylesheets of your choice)...

Why on Earth the actual data on the wire must be in the same format that we display to the user? To me it's only because it's difficult to have a standard be supported across multiple products / platform, and an ASCII editor is the most universal too available. Too bad though.... so much is lost.