This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!

Pete Long

Greenhorn
+ Follow
since Feb 13, 2015
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
2
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 Pete Long

I am trying to a create a single instance of a JAXBContext based that would facilitate marshalling many type of classes that all implement
a common interface. I have some success with my current approach.

Below is a snippet of my code as is currently and which works.



Elephant elephant = new Elephant();
Tiger tiger = new Tiger ();

// Marshalling of both the Elephant and Tiger objects work fine as shown below :-

String elephantString = marshallAnimalObject ( elephant );

String tigerString = marshallAnimalObject ( tiger );


My proposed change is to use a static instance of JAXBContext which would be created once only and not everytime the marshallAnimalObject() is invoked.
This instance of JAXBContext would cater for all classes that implement the Animal interface.

However, I am encountering a compiler error when creating the JAXBContext which would cater for all classes that implement the Animal interface.





The problem line is


Clearly, what I am doing is syntax incorrect but can anyone please suggest how I would be able create one JAXBContext instance which I can use to marshall all classes that implement the animal interface.

Would very much appreciate for suggestion to overcome this compiler error please.

Thank you in advance for your help.
Pete
Gents

Much appreciated all the suggestions.

As the requirement for me to extract out the various snippets of string from a well defined format and I don't have an in depth of Regex, I will going with Bill suggestion on this occasion.

Going forward, well I need to up skill on RegEx - actually re up skill because it was a topic I had to understand for my SCJP 1.5 ... yes that was a few years ago and so have had plenty of time to forget.

Regards
Pete
5 years ago
Hi Ritchie

Will look into regular expression.

As you have mentioned, it is not a straight forward subject matter.

In the off chance, if you or any one else can help me further I would very much appreciate it.

Regards
Pete
5 years ago
Hi Ritchie

Thank you for the reply.

As regards to the String specification .. it will be as per my example ie

"Resp Message - Component[Component Name] Server[Server Name] DataBase[Database Name] Status[Current Status]"

The only thing that will vary is the content between [] for each of the items of interest. Below are further examples

// different messages for Server, Database and Status
"Resp Message - Component[Component Name] Server[Short Name] DataBase[Much Longer Database Name] Status[Long Current Status]"

// Component is an empty message
"Resp Message - Component[] Server[Server Name] DataBase[Database Name] Status[Current Status]"

I hope this is clear.

Yes Regular Expression and Pattern Matchers .. I have been looking at these but can't get my head round these.

Just would appreciate an example on how I can apply these to hopefully kick start me.

Thank you again.

Pete

5 years ago
Hi

I have a Java string which is composed of several bits of information that I need to extract out.
It has 4 bits of information - Component, Server, Database and Status.
The information of each is provided after the name and is enclosed in [].
The [] is to define the start and end of the message and not part of the message.
Below is an example :-


"Resp Message - Component[Component Name] Server[Server Name] DataBase[Database Name] Status[Current Status]"

Now I would like to be able to extract out the 4 bits of information into seprate String for
each specific type eg

String component = "Component Name";
String server = "Server Name";
String database = "Database Name";
String status = "Current Status";

I would very much appreciate any help with how I can do this please.

Thank you.
Pete
5 years ago

Hi

see link https://coderanch.com/forums/posts/reqResolved/650611 to my not so good work around to get access to the external file.

Pete
5 years ago
Hi

Sharing my workaround for this issue incase anybody else encounters similar :

org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.type=JKS
# windows environment
# org.apache.ws.security.crypto.merlin.keystore.file=C:/temp/server.jks
# linux environment
org.apache.ws.security.crypto.merlin.keystore.file=/tmp/server.jks
org.apache.ws.security.crypto.merlin.keystore.password=password
org.apache.ws.security.crypto.merlin.keystore.alias=server

I have had to use explicit path ( for windows and linux ) to keystore file.

Need to ensure that the correct line is commented for the windows/linux enviorment.

Yes not a nice solution but it is the only one working for me.

Pete

5 years ago
Hi

Applogises in advance for creating a new thread for this query which is related to https://coderanch.com/t/650152/JBoss/keystore-format

In essence, i need an example of how under Wildfly I can define a JNDI resource to point to an external file.

Reference to the external file ( server.jks ) is in a properties file eg

org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.type=JKS
org.apache.ws.security.crypto.merlin.keystore.file=server.jks
org.apache.ws.security.crypto.merlin.keystore.password=password
org.apache.ws.security.crypto.merlin.keystore.alias=server


Any help suggestions would be very much appreciated.

Thank you

Pete
5 years ago
Hi Tim,


I too have almost the same set up as you - " Windows for development and Linux for deployment,"

As to your suggestion of "define a JNDI resource containing the filesystem absolute location of the external file",

would you be able to give an example of how this can be done on WildFly please.

I must admit, it has been quite an interesting problem to look into.

Again very much appreicated your help.

Regards
Pete
5 years ago

Hi

I have done a little more investigation and this is what I have determined.

I am putting the JKS file ( valid ) in the WEB-INF directory. So in effect, when the war is created, the JKS file is in the war file.

When I deploy the application, the war file gets exploded into a temporary directory. I determined the location of this directory
by stepping through via the debugger.
If I goto the WEB-INF directory where the war file has been exploded and perform the command

keytool -list -v -keystore keystore.jks

I get a "java.io.IOException: Invalid keystore format" repoprted.

So it seems like the JKS file is getting corrupted when the war is exploded into a temporary directory.

Incidently, if I perform

keytool -list -v -keystore keystore.jks

in the WEB-INF of my src code, no errors reported.

Tim, you are correct that the JKS file is invalid but it is invalid because it appears to be corrupted.

I have put the JKS file in the "configuration" directory under standalone but the application is not picking the JKS file.


Any suggestions as to how I put the JKS file outside of the war file and application can still pick the JKS file up ?
I presume this is possible but just need help with what the configuration settings requred to acheive this.

Any help will be appreicated. Thank you.

Pete



5 years ago
Hi

Possibly a Wildfly configuration issue, hence posting on this forum.

I am using Apache WSS4J (Web Services Security) through CXF and Spring to sign and encrypt a message request.
The application is deployed in Wildfly.

However, at the start of the sign and encryption process, I am getting the "Invalid keystore format" error.


org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:958)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: Invalid keystore format
at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:650)
at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:55)
at java.security.KeyStore.load(KeyStore.java:1214)
at org.apache.ws.security.components.crypto.Merlin.load(Merlin.java:365)
... 30 more
2015-05-18 14:23:33,791 DEBUG org.apache.ws.security.components.crypto.Merlin 369 Invalid keystore format
java.io.IOException: Invalid keystore format
at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:650)
at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:55)
at java.security.KeyStore.load(KeyStore.java:1214)
at org.apache.ws.security.components.crypto.Merlin.load(Merlin.java:365)
at org.apache.ws.security.components.crypto.Merlin.loadProperties(Merlin.java:190)
at org.apache.ws.security.components.crypto.Merlin.<init>(Merlin.java:140)
at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:117)
at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:187)



When I looked the source code for sun.security.provider.JavaKeyStore.engineLoad line 650, this what I found

645 int xMagic = dis.readInt();
646 int xVersion = dis.readInt();
647
648 if (xMagic!=MAGIC ||
649 (xVersion!=VERSION_1 && xVersion!=VERSION_2)) {
650 throw new IOException("Invalid keystore format");
651 }


http://www.docjar.com/html/api/sun/security/provider/JavaKeyStore.java.html

where

68 private static final int MAGIC = 0xfeedfeed;
69 private static final int VERSION_1 = 0x01;
70 private static final int VERSION_2 = 0x02


It seems the cause is due to the failure of the check on line 648/649.

Any suggestion as to :-
what this check is all about ?
How I can overcome this ?


Also could this be due to a Wildfly configuration setting that I may have missed out ?

Thank you for your help.

Pete
5 years ago
Hi
I happened to look at this link
https://coderanch.com/t/648612/JBoss/JBoss-eap-standalone-full-xml

This was interesting as it highlighted the need for me to add my postgres driver detail under the <drivers> element in standalone-full.xml.

Adding this detail seems to have fixed this issue.

Pete
5 years ago
Hi Jaikiran,

Below is an example of my codebase which I hope will give you an idea of my implementation and more hopefully you
maybe able to provide a suggestion/explantion as to why the "My_TABLE" database table is not visible.

I am pretty sure dao,domain, spring beans are all good.

My concerns are :-
  • Around steps to create the database and its table.
    MY_TABLE is created is under testdb -> Schemas -> public -> tables... is this correct ?


  • There is some WildFly configuration file which is needed that I am not aware of and not setting.
    Do you think I have missed to set/configure something ?



  • In the stacktrace shown in my original post, it shows "org.h2...." package which would be WildFly's in memory database.
    Is my understanding correct and if so, why would this be the case, as I am using postgres.


  • Will very much appreciate any help you can provide me.

    Many Thanks
    Pete


    Hibernate Configuration File





    Spring Datasource



    Define the session factory



    Define the DAO bean



    DAO Class



    Domain Class




    Hibernate Mapping file - MyDetail.hbm.xml




    Reading the Database table




    WildFly - standalone-full.xml - configure datasource




    Creating database and table in Postgres



    This creates a testdb database in local postgres installation under "Databases".

    The table appears under testdb -> Schemas -> public -> tables

    Owner of database is "postgres"

    5 years ago
    Hi Rob

    Yes , it is picked up via the JNDI name defined in the standalone-full.xml file.

    Pete

    5 years ago
    Hi

    My application is using Spring/Hibernate with Postgres on WildFly.

    I have configured a datasource which is pointing to a test (testdb) database in Postgres.
    Verified that the configuration is good by performing a "Test Connection"
    from Datasource details under the "Configuration" tab.


    I have also created a few tables and populated them. Granted all privileges to the postgres user.

    When I ran up the application, I am getting the error


    My understanding was that the "org.h2...." package is used when using the WildFly's in memory database.

    In my mind, it seems I have not correctly configured WildFly to use my local instance of Postgres and
    hence not finding "MyTable".

    So looking for advice as to configuration that I may have missed and/or other suggestions that will help me overcome
    the table not found error.

    I am using Wildfly 8.2.0.

    Many thanks for any help
    Pete
    5 years ago