Showing posts with label development. Show all posts
Showing posts with label development. 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-10-18

VirtualBox, CentOS, Network and Template

I have been working with VirtualBox and CentOS recently, here are some notes about this experience.

I used VirtualBox 4.2 and CentOS 6.3, but most of this should work with other products too. I created the first headless, minimal CentOS via NetInstall.
I cover two points: create a template machine and configure the Network.

Configure the Network

We want Internet access and a LAN local to the host.
For background information read: Networking in VirtualBox by Fat Bloke on June 2012.

The easiest is to enable two Network Adapters: One will be "Host-only" and the second "Nat". In the "Preference" menu you can see the DHCP server range for the Host-only Network. So you may set fixed addresses outside this range.
Next: start the guest. There may be various results at first, depending on a lot of things. Some problem might be solved by rm -f /etc/udev/rules.d/70-persistent-net.rules and a reboot.

Anyway, configure the two interfaces (set your own IP and MAC addresses) :

/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO=none
IPADDR="192.168.56.12"
HWADDR="08:00:27:30:60:68"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="d22a3e0a-5e0d-4185-9aaa-7295e3547224"

/etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE="eth1"
BOOTPROTO="dhcp"
HWADDR="08:00:27:02:A8:46"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"

I am not sure about the UUID and HWADDR usefulness. Be careful to first check that your configuration is not inverse eth0 ~ eth1. An ifconfig -a should give an indication.

Configure /etc/hosts to add the fixed IP: 192.168.56.12 web-serv1.my-domain.

Restart the Network: /etc/init.d/network restart. Quick test: ping $(hostname). You should have Internet access try with elinks google.com or yum update. You should also be able to access from your host via SSH. On Windows you may add the host name and IP to C:\WINDOWS\system32\drivers\etc\hosts.

Prepare the machine to be a template from which other will be cloned

When cloning don't forget to set new Mac address.

This script may ease the process. You need to adapt them!
# See: http://www.cyberciti.biz/tips/vmware-linux-lost-eth0-after-cloning-image.html
rm -f /etc/udev/rules.d/70-persistent-net.rules

# Remove MAC Address
ifcfg="/etc/sysconfig/network-scripts/ifcfg-eth0"
content=$( grep -v HWADDR $ifcfg )
echo "$content"> $ifcfg

# Remove SSH keys (they will be recreated at startup)
rm -f /etc/ssh/*_host_*
After cloning, don't forget to change the hostname and fixed IP.
This script may ease the process. You may need to adapt them!
ifcfg="/etc/sysconfig/network-scripts/ifcfg-eth0"

content=$( grep -v HWADDR $ifcfg )
if [ -z "$content" ] ; then
    echo "Problem $ifcfg maybe empty !?" ;  exit 1
fi

mac=$( ifconfig eth0 | grep eth0 | awk '{print $5}' )
if [ -z "$mac" ] ; then
    echo "Problem eth0 maybe down !?" ;  exit 1
fi

echo "$content" > $ifcfg
echo "HWADDR=\"$mac\"" >> $ifcfg

Next step ...

I should have use some Puppet or Chef automation, but since I already tried without success some time ago, I was not so keen to reiterate the experience.

I also wonder if NFS mounts would allow to keep a system up-to-date. The idea would be to have a common "kernel" base re-used by all the VM via NFS. The VM would have only user space variations. But I am not so sure if it would be reliable or even considered "good practice".

2012-08-27

Linux images for Virtualization

Some notes about Linux images for Virtualization.

To test some network tools or configuration, it can be useful to use multiple virtual linux machine. They can run with as little as 256Mo RAM and even less, 64Mo have been reported to work.

There are mainly two solutions:  https://www.virtualbox.org/ (free and opensource) and VMWare Player (free but less open). Also, there are free cloud services available (Amazon EC2 is free for one year for tiny configurations).

They each have "virtual appliances" ready to use (http://virtualboxes.org/ ; VMWare-Store ...) but there are no useful way to select one interesting. I took one from http://www.thoughtpolice.co.uk/vmware/.

Here I use Ubuntu 12.04 / VMWare Player 5,  

  • Set the f## french keyboard. Run: sudo dpkg-reconfigure console-setup or sudo dpkg-reconfigure keyboard-configuration, depending on the Ubuntu version.
  • Set the f## proxy with authentication.
    • If Gnome is installed:
      • gsettings set org.gnome.system.proxy.socks host 'fckng.proxy.enterprise.com'
      • gsettings set org.gnome.system.proxy.socks port 8080
      • gsettings set org.gnome.system.proxy mode 'manual'
      • gsettings set org.gnome.system.proxy.http authentication-user 'silly'
      • gsettings set org.gnome.system.proxy.http authentication-password 'dumb'
    • Otherwise (See this forum)
      • Generally: vi /etc/environment and add http_proxy="...", https_proxy="...", no_proxy="..." ...
      • For APT: sudo gedit /etc/apt/apt.conf.d/02proxy and add the line:  Acquire::http::Proxy “http://username:password@yourproxy:yourport″;
      • For wget: use .wgetrc ...
  • Update Linux: sudo apt-get update ; sudo apt-get upgrade ; sudo apt-get install linux;
  • Install the VMWare tools:    
    • There are some dependencies: sudo apt-get install build-essential linux linux-headers-$(uname -r)
    • In the VMWare window, there is a "Virtual Machine" menu to install a CDRom with the right tool version. Mount the CDrom and launch the installation
    • Re-run  vmware-config-tools.pl each time the kernel is upgraded.
    • Ref:  https://help.ubuntu.com/community/VMware/Tools

That it.

2012-07-05

TLS: Disabling legacy cipher suites

First: "cipher suite is a named combination of authenticationencryption, 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.

2012-01-04

Scala, Typesafe, SBT, IntelliJ IDEA, Specs2, Play, Tests ...

Scala has a great ecosystem evolving from developers needs. 

Everything is not "IDE integrated", but I kind of hope that it will stay this way. I don't like menus that fill up the screen.

As a reminder, here is the path I followed:

  1. Go to Typesafe:
    1. Download Scala (the "Typesafe Stack").
    2. Play with the REPL (the console)
    3. Read the free e-book
  2. Download SBT, if not already done
    1. Create a project (you just have to follow the quick start)
    2. Configure the SBT project to use the sbt-idea plugin
    3. Run gen-idea to create the IDEA project files.
  3. Launch IntelliJ IDEA 
    1. Get the plugins: Scala (and optionnaly SBT, it will only display the SBT console in IntelliJ.)
    2. Open the created SBT project
  4. You are already TypeSafe, go to Test or Spec safety also
    1. There is no one true path like JUnit here, you will have to choose
    2. SBT integrates with 3 main players.
    3. I choose to go with Spec2. Simply configure SBT to use it.
  5. As for the Web frameworks, Lift and Play are kind of associated with Scala
    1. I choose Play 2.0. It is very early and lacking functinonality ! Depending on what you want to do, Play 1 has a more mature Scala Module.

So it is not obvious, but nicely incremental. The starting points are SBT and REPL. From here you choose a IDE and a testing framework.

The rest really depends on your specific needs.

2011-10-27

Virtualization, a Vagrant 0.8 try

It has been a long time since I wanted to dive in virtualization. I always feared that my PC would not have enough RAM and end up only loosing time.

But I have been using VirtualBox and a bit of VMWare recently ... it looks good.

So next step to really get some benefits is to automate with Vagrant, Chef and Puppet ...

So far the setup is not as smoove as they say it would be ...

From here, this post turns into a rant :-)

First: Ruby. As far as I know, you have no choice here: Vagrant, Chef and Puppet are build on Ruby. I didn't even try to search for Python or whatelse based automations (but I would be glad to know Ruby alternatives).

So, Ruby, there is a Windows installer, click click, OK. Done. 

gem install vagrant

"Error: cannot access the Net". Ruby doesn't use the system proxy. You have to set an Environment variable: HTTP_PROXY=http://user:pwd@proxydemerde.com:1234/

gem install vagrant

"Error: you need the SDK". Vagrant uses particular modules that require local compilation (à la Gentoo). So you have to install Ruby SDK. (Why isn't it installed by default ?). Back to the Ruby web site. The SDK is a zip file, no installer this time. and be careful the zip doesn't contains its parent folder: you have to create a folder and uncompress the zip into this folder. Then run a script in the uncompressed folder that will find your Ruby installations and then run another script that will update theses installations so they are aware of the SDK presence.

gem install vagrant

"Error: cannot compile some ffi stuff". Vagrant uses some modules that uses some version of ffi.h and dependencies got messed up somehow. Google and find that you have to "gem install fii --version='1.0.9'" ... Dependency management ...

gem install vagrant

"Success". Nice. Next step install a machine. The examples feature "Ubuntu Lucid", I looked for one of the 3 more recents versions, but there are not a lot of choice here. So anyway it is a LongTermSupport, let not be too picky.

vagrant box add ludic64 http://files.vagrantup.com/lucid64.box

"Error: No space left on device ...." Well, the installer didn't ask for a workspace or project folder. It supposed there was plenty of space in "home". Back to Google, many solutions, some seems to not work for everyone. I edited the gem script to specify the "HOME" variable. Removed the ~/.gem and ~/.Vagrant folders.

vagrant box add ludic64 http://files.vagrantup.com/lucid64.box

"Error: No space left on device ...." Well, ".gem" is created in the floder I specified. But I have to set the variable in the vagrant script also ... Why is there no config file of global environement variable ?

vagrant box add ludic64 http://files.vagrantup.com/lucid64.box

"Success". I am close ! Just two commands left:

vagrant init ludic64

"Success" Just one more:

vagrant up

"Error: method missing in OLE ..." 

I tried with the "lucid32", same error. Some Google search, looks like the bug is being worked on.

Well Vagrant is in Beta after all. Sometimes, you are just out of luck. I hope it may help some other poor Windows / proxy users.

I will get back to Vagrant later. Next post may be about Chef or Puppet.

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-08

Web-Based Software Project Portals trends

Good article in Dr. Dobb's : Tools for Teams: A Survey of Web-Based Software Project Portals
It was pointed by the Modeling Languages Blog. Usually the blog is about UML, DSL, MDSD and such. But they personally participated to the study, so ...

It is well written. They take objectivity very seriously. and I would like to highlight some points:
  • "project portals would merge or integrate with social networking tools such as LinkedIn and personal life management tools such as Google Calendar." I strongly believe that it will happen. I see many trends to put everything (the code, the IDE ...) on-line and then search, connect and socialize. I wouldn't be surprised if someone came with a catchy name for this trend.
  • "we now wonder about the real importance of requirements elicitation and structured development process in the success of a development project". A direct result of Agile : Requirements are managed more efficiently and teams structure their processes to what fit them best.
  • "One clear trend in the portals ... was providing a hosted service." It will take some time, but enterprises will realize that their data are more secure and reliable within a well maintained application than behind their dumb firewall.
  • "...the portals were built ... to allow ... teams to scale up and ... spread out geographically. We believe this explains why they emphasize asynchronous communication (e.g., bulletin boards) over synchronous (e.g., chat)." I have a mixed feeling about this point. Some believe that teams could be just the temporary collaboration of highly specialized and efficient individuals. I doubt that it really works. Certainly the goal is to remove frontiers for developers. But face to face communication is still crucial for a team.
  • they "mainly target agile teams" and "none explicitly encouraged more traditional development processes". Looks like Agile has no competitors, but changing is hard. (By the way listen to all Linda Rising episodes : her voice is perfect for radio.)

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-08-17

LUA, commun point for VLC, Awesome, SciTE ...

It is amazing to see that most of the software I like and use embed LUA, the "powerful, fast, lightweight, embeddable scripting language" :
It is good to know that you can invest into it.

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.

2025 Summary

Trying to see if I can manage to complete a few projects this year. Sold my 10 years old Squier Stratocaster, bought a Strandberg Standard N...