This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!

Sverre Moe

Ranch Hand
+ Follow
since Jul 10, 2007
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sverre Moe

Having multiple proto files with multiple messages within each. Using protobuf-java version 2.5.0.

My processor class gets a String from a socket connection. This string I need to convert to a Message and forward it to a listener.
I need to create a message without knowing which message type/class I have. Trying my luck to find out witch of my 20 or so messages class I have received seems like a poor solution.

Must be a better way than this?
8 years ago
Why don't you just update your XML schema?

I don't think JAXB can handle unknow xml elements since it does not have any JAXB defined POJO class to map it to.
I reckon most people uses the default JAXB implementation. Lately I have been checking to see what else is out there and if these other implementations are any better or worse.
The information is scarce, but what I did find is Eclipse MOXy and Apache Camel.

One can choose which implementation to use by indicating the context factory within a jaxb.properties file in each java package containing JAXB files.

Both Oracle JDK and OpenJDK are using the same Sun JAXB implementation. This is actually the default one and does not require a jaxb.properties file.
javax.xml.bind.context.factory=com.sun.xml.internal.bind.v2.ContextFactory

Eclipse MOXy
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

Apache Camel
javax.xml.bind.context.factory=org.apache.camel.converter.jaxb.JaxbDataFormat

Spring OXM
Spring does not use the JAXBContext to retrieve Marshalling and Unmarshalling. Instead one configures Jaxb2Marshaller and Jaxb2Unmarshaller directly. Though I'm not quite sure if Spring is compatible with JAXB own marshalling and unmarshalling interfaces, becuase Spring oxm brings its own interfaces for those.


I could not find any information of pros and cons of each of these over the others. Neither could I find any other JAXB implementation.

Does anyone have experience in using either Eclipse MOXy or Apache Camel for JAXB?
Anyone know of other JAXB implementations which offer benefits over the default one supplied by the JDK?

Peter Johnson wrote:I'm confused, did you still have a question?



Not any more. I provided an edit section explaining what I found out.

Also, I click the Resolved button. I was not aware of it before now.
9 years ago
I am using maven-jar-plugin and maven archiver to specify manifest entries.
However it will not add neither classpath nor implementation entries.


In order for the jar file to have Class-Path within its manifest file I had to override it. Would hate to do the same with implementation entries.Seems waste to add extra configuration when archiver could do it.


Edit: The problem with the missing classpath has to do with the fact that I am using system scope dependencies.
When it comes to adding default implementation entries. This doesn't work , but this does .
9 years ago
While marshalling XML to file using the option JAXB formatting, the output is still not completely formatted.
Some lines does not have right indentation.

Example

I'm rewriting an application which is using DOM to parse XML and replacing it with JAXB.

However the application is making use of the get/setUserData(String) on org.w3c.dom.Element to associate a Java object to the XML element.


Object org.w3c.dom.Node.setUserData(String key, Object data, UserDataHandler handler)

Associate an object to a key on this node. The object can later be retrieved from this node by calling getUserData with the same key.



Is there a solution to do this with JAXB?

Example:
JAXBElement<Widget>
Attribute:class
The userdata associated with the XML DOM element is the class defined in this attribute for this XML element.

My JAXB objects are generated from XML Schema. Perhaps I could modify the JAXBElement Widget to contain the base class for the class defined in the attribute.
I'm building a XML Schema to be used with JAXB and are faced with a problem with the schema.

Take the myElementType for example. It has two attributes that are requeired, but not both of them. Either of them is required if the other is omitted.




In order for JAXB to validate this properly how can I arrange the XML Schema for this element for these 2 attributes?
I guess one of the two must have precedence over the other. If class is defined, the presence of url is invalid or vice versa.
If neither is defined it must validate that it must have either class or url.


For what I have read it seems like it is not possible to have attributes like a choice.
http://stackoverflow.com/questions/763072/xsd-one-of-2-attributes-is-required
Trying to change rpm relocate option with new prefix. When building it still uses the default value.
In RPM configuration %_prefix is default to /usr and I want to change it to /opt/company.

I have been writing in maven support for RPM where a previous RPM specification file was used:

Defined in the RPM specification file:
%define _prefix /opt/company
...
Prefix: %{_prefix}

After checking the created RPM specification file made by rpm-maven-plugin it does have these 2 values defined in it.



When I configure the mappings, I use the RPM defined values, %{_datadir}, %{_javadir} and %{_bindir}. When %{_prefix} is not defined it is default to /usr/.


When building with maven it does not find the files under /target/rpm/***/buildroot/opt/company/, but only under /target/rpm/***/buildroot/usr/
According to the specification I have done what is necessary in order to change from /usr to /opt/company, but it does not work. Any suggestions?


Seems rpm-maven-plugin creates the buildroot using the default %{_prefix} before it creates the spec-file. So the specfile is correct, but since the plugin creates the buildroot under /usr it cannot find the files under /opt/company.


[INFO] Creating directory /home/username/workspace2/myapp/target/rpm/myapp
[INFO] Creating directory /home/username/workspace2/myapp/target/rpm/myapp/BUILD
[INFO] Creating directory /home/username/workspace2/myapp/target/rpm/myapp/RPMS
[INFO] Creating directory /home/username/workspace2/myapp/target/rpm/myapp/SOURCES
[INFO] Creating directory /home/username/workspace2/myapp/target/rpm/myapp/SPECS
[INFO] Creating directory /home/username/workspace2/myapp/target/rpm/myapp/SRPMS
[INFO] Creating directory /home/username/workspace2/myapp/target/rpm/myapp/tmp-buildroot
[INFO] Creating directory /home/username/workspace2/myapp/target/rpm/myapp/buildroot
[INFO] Copying files to /home/username/workspace2/myapp/target/rpm/myapp/tmp-buildroot/usr/bin
[INFO] Copying files to /home/username/workspace2/myapp/target/rpm/myapp/tmp-buildroot/usr/share/java
[INFO] Copying files to /home/username/workspace2/myapp/target/rpm/myapp/tmp-buildroot/usr/share/myapp
[INFO] Copying files to /home/username/workspace2/myapp/target/rpm/myapp/tmp-buildroot/usr/share/myapp
[INFO] Copying files to /home/username/workspace2/myapp/target/rpm/myapp/tmp-buildroot/usr/share/myapp
[INFO] Copying files to /home/username/workspace2/myapp/target/rpm/myapp/tmp-buildroot/usr/share/myapp
[INFO] Creating spec file /home/username/workspace2/myapp/target/rpm/myapp/SPECS/myapp.spec

9 years ago
I was thinking about the assembly plugin. However, using maven-dependency-plugin along with maven-jar-plugin works fine also.
The dependency plugin is run with the goal unpack-dependencies and all dependencies are unpacked into target/classes. Then the jar plugin makes a runnable jar file from the content within target/classes.
9 years ago
I'm trying to migrate a project from Ant over to Maven. While building the application in a jar-file I need to include some 3rd party libraries.

Trying with the following Maven Jar Plugin configuration, but it doesn't work. Only the content within target/classes are includes.


The Ant jar target has an additional configuration that takes any of these 3rd party dependencies and unpack them and include them in the jar file. I need the Maven Jar Plugin to do the same because we bundle these 3rd party libraries within the application (there are only 3 of them).


I tried to use the Maven Dependency plugin to unpack all my dependencies and place them in the target/classes.However this was not included in the jar file. Wonder if the jar file was created before the dependencies where unpacked. Perhaps I need to change to a different phase for this plugin?
9 years ago
I am trying to understand and use Glibmm Main Event Loop. I find it difficult to understand what it actually do.
A program that wants to use the Main Event Loop first defines it like this:
Glib::RefPtr<Glib::MainLoop> _mainloop;

Then the constructor creates it like this:
Application::Application () :
_mainloop (Glib::MainLoop::create())
{...}

The application must implement a run function where it calls on mainloop->run().
void
Application::run()
{
_mainloop->run();
}

Now: What exactly is it its doing?
I have read http://en.wikipedia.org/wiki/Event_loop, but I am still lost, don't know why. Maybe I need a dumbed down explanation...
I have also tried to understand the following example: http://developer.gnome.org/glibmm/unstable/thread_2dispatcher_8cc-example.html#a15
From Java I am familiar with event listeners that listens for specific events. Don't know if this is similar.

Anyway from this code I cannot see what the mainloop actually does for this Application...
9 years ago
I have a java.security.cert.X509Certificate object that I want to send via e-mail.
How do I wrap this object in an e-mail attachment?

Would this work:


Most examples I have seen uses the following attachment method, but I do not have a regular file.



I found that Spring offers some JavaMail implementations:
Using Spring I have devised the following two solutions:

Using MimeMessagePreparator


Using MimeMessageHelper and ByteArrayResource:
10 years ago
It seems like JDK7 haven't gotten rid of all the classes in sun.security. BouncyCastle is still using some of its classes.
Just the X500Signer class is gone from JDK7.

The following code is working fine to create a Certificate Signing Request:


This I have tried to replace with the following BouncyCastle code:

But it gives the following complaint: java.security.NoSuchProviderException: no such provider: BC
I can specify a provider in PKCS10CertificationRequest, but I am unsure what this is supposed to be.

Edit: I found the solution to this: When passing null for provider it creates a Signature that same way as my first solution without provider.
10 years ago
Using Sun/Oracle JDK 1.6 I have access to and are using the following imports from the JDK.
import sun.security.pkcs.PKCS10;
import sun.security.x509.X500Name;
import sun.security.x509.X500Signer;

As of Sun/Oracle JDK 1.7 these are no longer available. What can I use instead of these? Are there any alternatives in either JDK or some other API?

I am using these to generate a Certificate Signing Request (PKCS#10) in Java. I want to do this programmatic and not via a seperate running tool like OpenSSL or Java Keytool.
10 years ago