I made a change in the blogger configuration to ease the later work when blogging. It is possible that older entries are not correctly formatted.

Sunday, 1 September 2013

Tricky Generation with stupid error with List<JAXBElement> getContent()

I spent too much time trying to understand why my schema did not get generated correctly. So I want to describe here the problem.


I have wsdl with a schema element:

<xsd:complexType name="Person">
   <xsd:sequence>
     <xsd:element name="id" type="xsd:long" minOccurs="0" maxOccurs="1" />
     <xsd:element name="title" type="xsd:string" />
     <xsd:element name="firstName" minOccurs="1" maxOccurs="1" type="xsd:string" />
     <xsd:element name="firstName" minOccurs="1" maxOccurs="1" type="xsd:string" />
   </xsd:sequence maxOccurs="1">
</xsd:complexType>

I was wondering why the generated Element Person did not have the correct fields but instead

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Person", propOrder = {
"content"
})
public class Person
   @XmlElementRefs({
     @XmlElementRef(name = "title", namespace = "http://www.cgi.com/cgicv/", type = JAXBElement.class, required = false),
     @XmlElementRef(name = "id", namespace = "http://www.cgi.com/cgicv/", type = JAXBElement.class, required = false),
     @XmlElementRef(name = "birthDay", namespace = "http://www.cgi.com/cgicv/", type = JAXBElement.class, required = false),
     @XmlElementRef(name = "middleName", namespace = "http://www.cgi.com/cgicv/", type = JAXBElement.class, required = false),
     @XmlElementRef(name = "lastName", namespace = "http://www.cgi.com/cgicv/", type = JAXBElement.class, required = false),
     @XmlElementRef(name = "firstName", namespace = "http://www.cgi.com/cgicv/", type = JAXBElement.class, required = false)
   })
   protected List<JAXBElement<?>> content;




The problem comes from the mistaken firstName twice in the element definition. I spent a long time looking for the answer.
The javadoc contained some kind of unclear warning. As soon as the right info is written, the content is generated correctly:



@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Person", propOrder = {
   "id",
   "title",
   "firstName",
   "lastName",
   "middleName",
   "birthDay",
   "address"
})
public class Person {

Saturday, 20 July 2013

Apache Log Files Analysis

I might be doing this a lot of apache log file analysis in a few days so might as well take look at the the open source (and others) project there are t to perform this task.

I discovered the following projects:

  • logQL (GPL v3)
  • WebLog Expert ( with an Lite Freeware version)

The first one seems nice simple and the GUI is kept very simple. While the second one seems to have a lot of features. However, I have not tried to see exactly which one are available in the lite version.

I might also add a number of other libraires here.

Friday, 12 July 2013

Axiom - XML Processing for Axis and others

I have been taking a look at the Apache Axis2 Web Service framework. Reading the documentation, I was reminded of the Axiom framework used for the processing of XML. Therefore, I will gather here a few informations which I find useful. These info come partially from quickstart-samples. The example are changed a little to be adapted to my way of thinking. This is also a documentation for me.


In addition to be used to process XML efficiently, Axiom can be used to process MTOM messages which are used in SOAP to transport binary data.
Again on the quickstart-samples page, there are some examples. But I will use a separate POST for this.


How to retrieve child elements from root:

public void processXmlFile(File file, String namespace, String elementName) throws IOException, OMException {
// initialize the file input stream to be closed in this method
InputStream in = new FileInputStream(file);
// get the root element
OMElement root = OMXMLBuilderFactory.createOMBuilder(in).getDocumentElement();

// Process the content of the file
OMElement element = root.getFirstChildWithName(
new QName("-http://maven.apache.org/POM/4.0.0", "url"));
if (element == null) {
System.out.println("No <"+elementName+"> element found");
} else {
System.out.println(elementName" = " + element.getText());
}

// Because Axiom uses deferred parsing, the stream must be closed AFTER
// processing the document (unless OMElement#build() is called)
in.close();
}

Schema validation

How to perform partial schema validation (from quickstart-samples).

public void validate(InputStream in, URL schemaUrl) throws Exception {
  SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(in, "UTF-8");
  SOAPEnvelope envelope = builder.getSOAPEnvelope();
  OMElement bodyContent = envelope.getBody().getFirstElement();
  SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
  Schema schema = schemaFactory.newSchema(schemaUrl);
  Validator validator = schema.newValidator();
  validator.validate(bodyContent.getSAXSource(true));
}

quickstart-samples presents also a way to do it with a DOMSource instead of the SAXSource.


Perform on chunks of an XML Document


Often it is useful to perform just on a particular chunk of the XML document.

public interface FragmentProcessor {

    public QName getTagName();

    public void processFragment(OEMElement);

}

  public void processFragments(InputStream in, FragmentProcessor fragmentProcessor) throws XMLStreamException {
    // Create an XMLStreamReader without building the object model
    XMLStreamReader reader =
       OMXMLBuilderFactory.createOMBuilder(in).getDocument().getXMLStreamReader(false);
    QName tagName = fragmentProcessor.getTagName();
    while (reader.hasNext()) {
       if (reader.getEventType() == XMLStreamReader.START_ELEMENT &&
          reader.getName().equals(tagName)) {
             OMElement element =
                OMXMLBuilderFactory.createStAXOMBuilder(reader).getDocumentElement();
             // Make sure that all events belonging to the element are consumed so that
             // that the XMLStreamReader points to a well defined location (namely the
             // event immediately following the END_ELEMENT event).
             element.build();
             // Now process the element.
             fragmentProcessor.processFragment(element);
          } else {
             reader.next();
          }
       }
   }

Wednesday, 10 July 2013

Maven Apt and Code Snippets

For a documentation and course I will give I am using the document creation properties from apt of maven. For a documentation of the format see:
the APT format. In order to give an example, you can use a very simple snippet:

    ------
    The APT format ( or the html title of the document)
    ------
    Me the author
    ------
    2013-7-9


The title at the top of the page (not indented)

  The first introduction paragraph.... which is indented so that it is clear that it is a paragraph.

* The first subsection

  Another paragraph also indented

** a subsection with two * in order to mark it as a sub subsection

  A third paragraph followed by an ordered list with numbers

    [[1]] first element

    [[1]] second element


This create the following snippet HTML fragment (in a given generated page).



<h2>The title at the top of the page (not indented)
<a name="The_title_at_the_top_of_the_page_not_indented"></a></h2>

<p>The first introduction paragraph.... which is indented so that it is clear that it is a paragraph.</p>

<div class="section"><h3>The first subsection

<a name="The_first_subsection"></a>

</h3><p>Another paragraph</p>

<div class="section"><h4>a subsection with two * in order to mark it as a sub subsection<a name="a_subsection_with_two__in_order_to_mark_it_as_a_sub_subsection"></a></h4>

<p>A third paragraph followed by an ordered list with numbers</p>

<ol style="list-style-type: decimal"><li>first element</li><li>second element</li></ol></div></div></div>

In order to get snippets, then I use snippet macros as described in: Guide to the Snippet Macro.

Thursday, 4 July 2013

Eclipse installation Problem onWindows7 with cygwin unzip

Once or twice I had problem using unzip to unpack the eclipse code under windows7. Thanks to this answer, it could start eclipse normally. After downloading eclipse:

$> cd dirtoput-eclipse
$> unzip pathwhere-eclipsezipis/eclipse...-version.zip
$> cd eclipse
$> find . -name "*.dll" -exec chmod +x {} \;

Saturday, 29 June 2013

GDM Configuration

Well I learned something about the GDM configuration by reading the well written gnome gdm manual. However, that did not solve my Gnome cofiguration problems.

But at least I know a little bit more how to configure the user screen and put useful on it through the use of an Xwilling script.

Friday, 28 June 2013

Systemd und service control under fedora

I must say I am currently a bit lost in the different mechanisms to start and stop services. I used to perform these tasks with the standard /etc/init.d/... scripts. But it seems that it does not work completely in this way. There seems to be now systemctl, service and chkconfig commands.

service sshd start

to start the ssh daemon.

service sshd stop

to stop the ssh daemon.

chkconfig sshd on

to enable the ssh daemon so as to start it after boot.


To use systemd, the following commands come handy:

systemctl start sshd.service

to start the ssh daemon.

systemctl stop sshd.service

to stop the ssh daemon.

systemctl enable sshd.service

to enable the ssh daemon so as to start it after boot.




Monday, 24 June 2013

python useful packages in combination with command line

I have been playing with python lately and discovered at least two small utility pacages providing useful features in combination with the commandline. For this reason I created two aliases:

alias openurl='python3 -m webbrowser -t'
alias webshare='python -m SimpleHTTPServer'

The first one opens a web page at the url given as a parameter, if the url does not have a protocol, e.g. http, then the command will interpret it as a local file. The second one starts a webserver for the directory where the command is called. Then you can provide in that way a simple mean of letting someone download local files.

Sunday, 23 June 2013

PAM authentication with multiple passwords

I just learned that it is possible to perform cascading failing authenthication. In that way it is possible to use different passwords, for example password with ldap or passwords with the shadow file. When a user logs in with his local password, the configured system would first try to log in with the ldap password for instance, which would fail, then the pam module for the local shadow file would be used.


I discovered this when reading about barada (see sourceforge page). This project offers the possibility of creating a nice remote password mechanism where a token can be obtained from a telephone app, for instance an android. It uses the HOTP protocol described in this RFC.

Friday, 21 June 2013

cmd Hell No! different colored text does not seem that easy

I have been looking for a cool way to change the color of a part of the text in the command prompt... But this proved to be a time stealer, because there does not seem to be any easy way to do it. There are some complex ways but I am not going to look into them.

Create simple GUIs to your scripts - HTA files

While looking for a way to help my grilfriend be more productive I found ut that one can create hta files. The following example is with VB. I have to see if it is possible to use other kind of scripts.


<head>
<title>HTA Test</title>
<HTA:APPLICATION
APPLICATIONNAME="HTA Test"
SCROLL="yes"
SINGLEINSTANCE="yes"
WINDOWSTATE="maximize"
>
</head>

<script language="VBScript">
Sub TestSub
Msgbox "Testing 1-2-3."
End Sub

Sub GetOSVersion
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" &strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
Msgbox objOperatingSystem.Caption &" " &_
objOperatingSystem.Version
Next
End Sub
</script>

<body>
<input type="button" value="Run Script" name="run_button" onClick="TestSub"><p>
<input type="button" value="Get OS Version" name="run_button" onClick="GetOSVersion"><p>

</body>

This may turn out to be useful once or twice. But I would hate to have to program in visual basic.
There was actually an example how to create a simple selection list in powershell. But I have not tried the described there, but the page might be useful to you

Thursday, 20 June 2013

emacs Malabar Mode

Emacs Malabar is an emacs mode for editing java with emacs. While browsing I found this stackoverflow entry. I still have to dig into it, but it seems to have very useful properties (according to the Stack overflow answer):

  • tight maven integration
  • groovy console for rapid prototyping
  • junit integration
  • import help
  • extra class, overide method and implement interface helpers
  • simplistic refactoring


An interesting extension to this work is to use also a mode for maven.

emacs JDE

Emacs JDE is an emacs mode for editing java with emacs. For a long time I wanted to dig into this again, because I find myself often annoyed by having to start eclipse for very simple java projects.


An interesting extension to this work is to use also a mode for maven.

World Simulation with Map Reduce

After a friend of mine has presented me a pet project of his and one of his friend: Wesen.
I thought of a few things one could do with MapReduce. In particular, I think it is interesting to
look at the use of map reduce for this kind of work.

The basic idea would be to first perform a map/reduce to choose which actions should be performed by the entities.
Then a second map/reduce to perform the action, and then finally a third map reduce to perform clean up operation

Another possibility is the use of a genetic algorithm and see how these evolve.

Using the powershell to download a file

A simple script to download a file:

$url="http://hostname/xxxxFiletoDownload"

$thisir =pwd

$path = $thisdir.toString() "\xxxxFiletoDownload"


$client = new-object System.Net.WebClient

$client.DownloadFile( $url, $path )


Thursday, 13 June 2013

Http Only cookies

I just learned something about http-only cookies to prevent client code of the browser to temper with cookies. I found a little more information in this article:https://www.owasp.org/index.php/HttpOnly. To do this in Java for a cookie, write:


Cookie cookie = getMyCookie("myCookieName");
cookie.setHttpOnly(true);

In particular for the session cookie, you can use the following code:

SessionCookieConfig config = request.getServletContext().getSessionCookieConfig();
config.setHttpOnly(true);

Saturday, 1 June 2013

OS DEV

This might not be really for me but just in case I should want to read a gain a little bit about the subject there is a nice site with informations for OS development: http://wiki.osdev.org/.

I should try to keep that in mind