Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

2017-12-19

Encoding/Decoding in Java 9 using javax.xml.bind or not

DatatypeConverter and Java 9

If you used to do conversions, like

import javax.xml.bind.DatatypeConverter;
...

byte[] bin = DatatypeConverter.parseHexBinary("0769cc");


With Java 9 you will get errors, since javax.xml.bind is no longer in the module path, it is considered part of Java Enterprise. With Java 10 it may even be removed from the JRE.

It is a known problem:

There are many solutions: Rewriting the function or Using command line option to load the library at runtime ...  But the most robust and long term one seems to be adding the dependency to your project.

Here I will focus on adding the dependency:

Java Enterprise library 

As a Maven dependency:
<dependency>
     <groupId>javax.xml.bind</groupId>
     <artifactId>jaxb-api</artifactId>
     <version>2.3.0</version>
</dependency>

Directly in IntelliJ (Community edition):


Guava

Guava also provides conversion methods, but you will have to adapt your code:
https://github.com/google/guava/wiki/PrimitivesExplained#byte-conversion-methods

Apache Common

Same for Apache Commons. It is a matter of taste.
http://commons.apache.org/proper/commons-codec/

org.apache.commons.codec.binary.Hex(str.toCharArray())



2012-07-11

From XML Firewall to API Server

It is very interesting to see the development of Vordel products. More precisely how they are marketing their products.

The "XML Firewall" was like a "Layer 7 Firewall", focusing on the application level.

Then it evolved to XML Gateway, SOA Gateway and now: here is how they define their "API Server": http://www.soatothecloud.com/2012/06/vordel-introduces-api-server.html.

As a side note, I can't resist a little quote against SOAP: http://www.soatothecloud.com/2012/07/what-scales-better-internet-or-esb.html

2012-07-05

TLS: Disabling legacy cipher suites

First: "A cipher suite is a named combination of authentication, encryption, and message authentication code (MAC) algorithms".

If you are using TLS (for HTTPS typicaly) you may want to remove some Cipher Suites.

You maybe a little bit less compatible, but also a bit more secure. Things will be better when TLS1.2 is implemented everywhere.

You can also claim to be FIPS 140 compliant: http://csrc.nist.gov/publications/nistpubs/800-52/SP800-52.pdf !

How to do it:

If someone knows how to do it on the IBM J9 via configuration, I am interested.

2011-06-29

Lower barrier to entry eases community engagement ...

... and I experienced at least 3 way JBoss made some good step in this direction:

  • Application Server 7 (JBoss AS7) is lightweigth and start in about 2 seconds on an 5 years old laptop
  • Wiki are open: you just have to login and you can edit. (and you don't need multiple accounts).
  • GitHub makes it easy to submit change request from your browser (my small contribution)

So things evolved from the time where Application Server where heavy beast which needed a strong and long commitment just to step in.

More progress is still possible by reducing the amount of information you have to digest and filter to get things done, but no doubt that some semantic web stuff will cover this need.

In the mean time, you can download JBoss AS7 CR1 (released today): http://www.jboss.org/jbossas/downloads.html

There are sample applications: 

Give it a shot

 

2010-09-09

Sequence Diagram: DSL or not DSL ?

I had to produce some UML Sequence Diagram and I tested some Graphical and command line tools.
With UML tools there are 3 possibilities (sometimes mixed in a single application):

  • Draw your diagram (UMLet, ArgoUML, Violet ...)
  • Reverse engineer your code. It can work for Class Diagram, but the result for Sequence Diagram is generally unusable. (ArgoUML ...)
  • Describe your diagram in a DSL (PlantUML, UMLGraph, ...)
There is no "Best Option" since it depends on your use case:
  • for quickly puting an idea on paper, I like UMLet very much for Class, Component ... But I have to admit that VioletUML is way better for Sequences ! 
  • When I want to keep my diagram in sync with the code and documentation. The DSL/Reverse Engineering approach allow me to put the diagram description in the JavaDoc. The setup in the Maven POM file (with UMLGraph, should be possible with PlantUML too).
  • I never have the case where a DSL would be that useful. But you just got all the benefits of text files obviously: diff, grep ... and some tools allow you to embed your description in Wiki, LaTex, Word ... (PlantUML).


I tested several DSL:

I have to admit that I am a bit deceived with the current state of DSL for Sequence Diagram.

  • They are not that obvious. The easiest is "Client -> Server : HTTP request" with PlantUML. But with SDEdit you would read: "Client:Server.HTTP request" !?
  • They could do more (like automatically activating the lifeline upon message reception). With PlantUML you pollute your description with numerous "Activate Server" ; "Deactivate Client" ...
  • They quickly becomes hard to read and maintain. Two main problems:
    • If you send a message at the beginning and got the response at the end. The message/response link is lost in the distance introduced by all the dialogs in between. You can use indentation, but it is up to you, not a DSL feature.
    • When you have parallel executions or interlinked messages, even the indentation won't be a solution. I don't even see how it could be solved.
  • You really need to see the resulting diagram as you type, if you don't want to end with a lot of rework.
  • The tools I used didn't show you the result "out of the box". You have to setup some schell scripts or other tools. (SDEdit being the exception.)
I think that it is not an inherent problem with DSL. But we didn't find a suitable DSL for Sequence Diagrams and an intelligent application that would really understand Sequence Diagram, and not just describe lines with labels. This would introduce more constraints. There are certainly things that we wouldn't be able to describe as we want, but it should solve 80% of the cases hopefully.

2010-03-22

Sonar & Maven

Sonar is a very nice tool. One of the few that will show how your metrics evolve over time.
But the cooperation between Sonar and Maven isn't that obvious:

2009-10-04

The Guava library: a Google lesson in API design

When I first read an article about a new library to do String manipulation, I wondered what could be so interesting in there ? Isn't such a basic topic already well addressed in the standard library ?
But since I am a bit concerned in API design and really wanted to know what would justify to create a new library, because the class String looks OK to me, so ... I gave it a look.
No regrets. Indeed the API is clean, consistent and simple to use.
The guava library.
I wouldn't care for trivial String manipulation, but if I have anything just a bit less than trivial, I will definitively use it !
More importantly, I know I have to look more and more to these "praised" project : google collections being next

2009-09-20

Scala and idioms

From the article : Is Scala really more complicated than Java? The same program can be written in Scala with different idioms:

Easy way:

val name = "Dick Wall"
println("""
Happy Birthday to you
Happy Birthday to you
Happy Birthday dear """ + name + """
Happy Birthday do you
""")


Procedural:
for (n <- 1 to 4) {   
print("Happy Birthday")
if (n == 3)
print(" dear XXX")
else
print(" to you")
println
}


Mixed:

(1 to 4).map {
i => "Happy Birthday %s".format(if (i == 3) "Dear XXX" else "To You")
}.foreach println


Functional:

(List.make(4, "Happy birthday ")
zip (List.tabulate(4, {
case 2 => "dear friend"
case _ => "to you"}))
) map (Function.tupled(_+_)) mkString ("\n")


More freedom ? hope Scala will avoid to be like Perl ! Not everybody will be able to maintain a Scala program. But that is also true with Java or anything. The complexity can be everywhere anyway, it is just more or less visible.

Read also: It's not the languages, but their idioms that matter.

2009-09-07

MDSD: UML or DSL ?

This blog is a lot about Linux, because I use it as a reminder. I want to remember how I solved some problems or some great applications or short cut.
But it doesn't reflect my main interest that is development, design and creation. My Google Reader Shared post gives a better view of this part.
Also how I shifted my interest from Semantic web to Model Driven Development and DSL.
So I will just notice that I didn't realize how UML and DSL can be antagonist.

2009-07-30

Java GUI application in Awesome Window Manager

There is a known problem with Java and the non-reparenting Window Managers like for example Awesome.
Java applications which use the XToolkit/XAWT backend may draw gray windows only. The XToolkit/XAWT backend breaks ICCCM-compliance in JDK 5 and 6 because it assumes a reparenting window manager.


There are a number of places where this is described:

To sum up:
  • it doesn't affect version Java 1.4.2 and before.

  • it doesn't affect version Java 1.7 and hopefully after.

  • the best workaround by far, is to set a name to the Window Manager, so it is recognise by Java as a non-reparenting Window Manager. A simple utility allow to set this name. Just add 'wmname LG3D' to your .xinitrc or simply run it.

  • Here are other workarounds left here for reference:

    • launch another X server, like Xephyr

    • set the following environment variable (to use the older Motif back-end instead): AWT_TOOLKIT=MToolkit. But this won't work in the following cases :
      • OpenJDK/IcedTea doesn't include the Motif toolkit.

      • doesn't work for x86_64 Java, for whatever reason.


2009-07-29

DSL and Meta Programing System

As a regular Software Engineering Radio listener, JetBrains MPS 1.0 release came to my attention.
I read articles, watched the screen-casts and downloaded the beast to put my hands on.

I have a mixed feeling: on one hand, it is a step towards higher abstractions. From bare metal to assembly to C to C++ to Java, this is where we are doomed to go.
But on the other hand, the tool and the concepts are really complex. It is not the kind of tool that you download and play with before digging the manual ! With MPS, I have been following the tutorial carefully, step by step. It won't be mainstream yet.

Nonetheless, it opens a whole new landscape. I guess that there will be DSL users, DSL developers and of course DSL architect !? The tool is already very powerful. The samples with complex numbers and mathematical notation are impressive: the readability is way better.

It remind me the idea that code isn't meant only to compile, but its most important purpose is to communicate its intent to other developers and designers. I could not find back the reference to the specific article where this idea was exposed, but anyway, this concept concern all DSL.

It remind me of the JBoss approach to BPML: they didn't try to do everything with the "graphical designer". They kept it simple and provided a way for the developer to deal with the implementation details. So "Graphical DSL" is more a collaboration tool between the analyst and the developers, than a bloated UML/OCL do it all thing. (Note: I like UML.)

No doubt that there is a strong need to reduce the gap between functional/business analysts and developers. Even worse with offshore developments. Agile is mostly about getting developers closer to the client, DSL are coming along. Will linguistic be the next buzz ?

2009-07-21

UMLgraph and Maven

Just a quick note on how to setup UML Graph in Maven.
{plugin}
{groupId>org.apache.maven.plugins{/groupId}
{artifactId>maven-javadoc-plugin{/artifactId}
{configuration}
{excludePackageNames>com.comp.proj.internal.stuf{/excludePackageNames}
{doclet>org.umlgraph.doclet.UmlGraphDoc{/doclet}
{docletArtifact}
{groupId>org.umlgraph{/groupId}
{artifactId>doclet{/artifactId}
{version>5.1{/version}
{/docletArtifact}
{additionalparam>-attributes -enumconstants -enumerations -operations -types -visibility -inferrel -inferdep -hide java.*{/additionalparam}
{destDir>withUML{/destDir}
{show>public{/show}
{/configuration}
{/plugin}

The only trick is that all the additional parameters must be set on one line ! This doesn't appear in the documentation nor on the web. Quite the contrary, I found a lot of bad examples on the web !
This POM configuration simply works great. I noticed a new UMLGraph version 5.2. I didn't try but it should work also.

There is a tiny example in the Maven documentation about Using Alternate Doclet.
There is a dead project to create a plugin for Maven: DotUML. No updates since 2007.

Maven how to set the Main-Class in the Manifest

In Java, for a jar to be executed, the easiest way is to set its entry point. This is done by setting the Main-Class in the Manifest. Easy.
Now let's do it with Maven !

First you use your jar, in Maven, you can to configure it this way:
project/build/plugins/plugin
artifactId maven-jar-plugin
version 2.2
configuration
archive
manifestEntries
Main-Class com.comp.proj.main

Now you would like your jar to contain all the dependencies, then you use the maven-assembly-plugin. But it won't take the configuration set in the jar plugin. You have to reconfigure the exact same main-class again. It is redundant OK, but why should it have a different syntax !?!
project/build/plugins/plugin
artifactId maven-assembly-plugin
configuration
archive
manifest
mainClass com.corial.cosma.apptest.apptest

OK, the point is that there are at least two way to configure the Manifest. Either with a free key/value syntax, with Manifest Entries. Or with the class Manifest which has a mainClass element. So it is up to you to be consistent in your POM and not copy everything found on the net ...

Notes:

2009-05-09

Sun's JVM has an HTTP server embedded: com.sun.net.httpserver

Very useful ! Sun's Java Standard Edition has a simple HTTP Server: com.sun.net.httpserver.

It simplifies dependencies since you don't have to add a new library. It is straightforward to use it with Jersey to publish Restful Services. But it isn't a standard feature !

Eclipse users might see compile errors saying Access restriction: The type ... is not accessible due to restriction on required library ...
The problem is that the HTTP server is part of the Sun JRE6 but not part of standardized Java.
Eclipse therefore blocks access to it.
This can be fixed by going to the Window->Preferences window, selecting Java->Compiler->Errors/Warnings, selecting Deprecated and Restricted API and then changing the setting for Forbidden Reference and Discouraged Reference to Warning instead of Error.

Jersey client, Jax-rs, Jaxb, RESTFUL client in Java

RESTFUL web-services, in Java, concern mostly server side developments. The client is generally the browser.
Now I am in the process of developing a Java client for web-service. I searched Java solutions in this space and found that Jersey was also a good client. I already known Jersey, for being the reference implementation for Jax-rs (Restful Services ?) and even saw Paul Sandoz himself in Grenoble. But I never imagined that there could be another consumer than the browser.
Well obviously, they needed to test Jersey, hence ad-hoc code, then a framework and a finally a jersey-client for everyone's pleasure.
The funny parts is that I am using jersey-server to test jersey-client: the other way around ... That is not pure Unit Test, in the sense that I prefer functional or integration test than testing every tiny development chunk and mocking everything around.
Point is that implementing Restful Services in java with Jersey and Jasxb is really easy. overall, I stumbled on a problem with Jaxb and the way it doesn't handle immutable objects, but I will make another post about this.

2009-02-27

My first JavaFX tutorial completed under Linux

I was eager to start using JavaFX, because Linux isn't yet fully supported as a development platform. So I used this tips on how to install Netbeans with JavaFX on Linux. And I have been able to follow this tutorial.
Nothing fancy, but I have a good feeling about JavaFX : the code is clean, powerful and very readable. Not cluttered with legacy stuff.
I hope I will be able to do more with it.

2009-01-22

Java on Linux, So Many Free Choices

Or should we say too many choices ?
This post is essentially to cleanup some bookmarks I tagged "To Read".
There is an article in Fedora Weekly Issue 133 about Java.
I like to have a clean Linux install and having Sun's Java, GCJ, IcedTea and others gives me a bad feeling.
Hopefully the road map toward OpenJDK is clear.

2008-10-03

Java browser plugin on 64 bit Fedora and more

It's been a long time. So just to say that :
- Fedora 10 should be there soon

- There is some hope for a good java plugin on 64-bits browsers. For now just install java-1.6.0-openjdk-plugin. Or better, just yum install java-1.6.0-openjdk-*

- being on a project with a lot of JMS, Tibco RendezVous, Complex Event Processing, Event Driven Architecture and the likes, It is the kind of paradigm change that bring some fun to the job ! So no more HTTP request nor function calls : just send events and hopefully someone else will write the code to react to them. We are so used to HTTP and the firewall censorship that we don't even consider JMS ! But there are plenty of cases where it makes perfect sense to use events and messages : a lot of them !

Festival de la Cooperative OASIS - 2026

 https://Cooperative-OASIS.org/ Abonnement la revue Passerelle Eco    Papier . Mais les annonces sont dispo:  Revue trimestrielle de l’ Ecov...