Mark Hughes

Ranch Hand
+ Follow
since Jul 14, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
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 Mark Hughes

Hi,
Hope everyone is well, quick question to see if anyone has any feedback.

I was experimenting with both JaxB and Xstream over last two days. I was basically using the XML libraries to marshal and unmarshal XML to / from Java objects. Now this was a very simple task which I got working very quickly. However, the XML I want to unmarshal into a list of Java objects is very long and contains many child elements that could be ignored and not put into the list of java objects.
For example the xml would look similar to:

So I would like the library to iterate through all the xml elements and unmarshal into a list of java objects which so far works, however as it iterates I would like to add additional functionality to check the Type and Flag element values, if TYPE value equals Test2 and or if Flag value equals False to ignore this child element all together and not include it in the finished list of Java objects. Does anyone know if this is possible with either JaxB or Xstream? Alternatively, can anyone suggest maybe a better approach to accomplish this which requires minimum code and manual parsing.

I have been looking at ValidationEventHandler and XmlAdapter in JaxB but I do not think these will allow me do what I want. I got close with the Xmldapter however the unmarshal has to return either null or an object for each xml child element it processes, it also changed the xml syntax to attribute form i.e TYPE = "Test1" etc which I did not see any way of altering.

Xstream allows you to implement a Converter which has a canConvert method, however this only works on Class type, and not child element type which I weant to check for each child element. Had a look at MapperWrapper wrapMapper method which can be overloaded in Xstream, but it only shows element attribute name, i.e FLAG and does not show value, also if it did show value I do not see anyway of telling the function to ignore child root element and all attributes for said child.

Anyway, that's my two cent. Any advice?

Best,
Mark
Hi Guys, Sorry i got it working, it was a problem on the server side and not with my code at all.

Best
Mark
14 years ago
Hi Eveyone,

Im using HttpURLConnection to do simple HTTP post and get, I know i can add parameters to the connection using DataOutputStream.writeBytes() for the post but this does not work if i try and send JSON type text. What can i use in java to send JSON HTTP post's.

Best
Mark Hughes
14 years ago
Thanks Paul i did not think of that, very good. Ill give it a go.

Best
Mark Hughes
Hi all,

Is it possible to get a time stamp in SQL in the format of a long datatype similar to the java Method System.currentTimeMillis() .

I know sql has functions similar to SELECT NOW(); which return something like "2009-06-05 16:10:09" , but i would like to hava a method to return it as a long number. As i have saved alot of my time instances in the database as long numbers and now i have the need to do a select based on the current time and instance of a saved long number. I dont think a SELECT statement would work if i tried something like SELECT .... WHERE (SELECT NOW()) < column.TimeMillisAsLong.

Best
Mark Hughes
cool thanks guys, that makes sense.

Best
Mark Hughes
14 years ago
Hey Guys,

Any takers on this?
14 years ago
Hi Guys,

Ive been doing some research and i discovered that the following code put in a web.xml will force Tomcat to redirect to a https connection for certain wildcard matches, or in the below case all pages in the domain.
My question is though if only a few pages below were added to the filter such as login page and account page, https is invoked when those pages are requested, but then tomcat keeps a https connection from that point on.
Is it possible to also have filters that force tomcat to redirect to a non ssl port for some pages that do not need securing.

So based on the url pattern, Tomcat will redirect to https and then back to http?




Best
Mark Hughes
14 years ago
Hi Chris,

Thanks for your reply, i downloaded the latest dll and the message is gone now.

Previously with version 1.1.9.0 i got this log message in the normal catalina log file:

"21-May-2009 15:03:29 org.apache.catalina.core.AprLifecycleListener init
INFO: An older version 1.1.9 of the APR based Apache Tomcat Native library is installed, while Tomcat recommends version greater then 1.1.10
21-May-2009 15:03:29 org.apache.catalina.core.AprLifecycleListener init"

Do you use ssl connections with your setup by any chance chris, Its just i noticed when i have ssl turned on and Tomcat redirects to use https it is very slow when being accessed by an external machine (Up to a minute to load page).
On the other hand if accessed via localhost there is no delay. Alternativley a normal http page is loaded very fast from either external source or localhost. I thought maybe the older version of APR was the prob but it is still happening with the newer version.

The ssl certificate is unsigned, i dont think that would cause a big delay in response times though, also the machine already has OPENSSL installed perhaps there is a conflict between the one included in tcnative-1 and the one installed. Any suggestions?

Best
Mark
14 years ago
Any takers on advice setting up Apache APR with Tomcat 6 on Windows??
14 years ago
Hi Everyone,

Hope all are well, Have a quick question regarding setting up APR with Tomcat 6.

Ok story so far, I found this link http://tomcat.apache.org/tomcat-5.5-doc/apr.html which is for Tomcat 5.5 (came across the same page for Tomcat 6 as well), the page provides a link (windows section) to a single binary file called tcnatice-1.dll which can be dropped into the Tomcat install directory under the bin folder which allows tomcat to pick up the APR librarys and use them. Works grand but the logs do say that the library used is old (1.1.9) and a newer version should be used (over 1.1.10).

So then i went to the following url, http://apache.mirrors.esat.net/apr/binaries/win32/ and downloaded apr-all-1.2.12-win32-x86-msvcrt60.zip which seems to be the latest binaries available. I then unzipped the zip file and had various folders and files, i found 3 dlls in the bin folder called libapr-1.dll, libapriconv-1.dll, libaprutil-1.dll which i again coped into Tomcat/bin but this time Tomcat does not pick up the APR files and does not load them. I also tried to copy the entire zip contents into the Tomcat install directory and bin dir but so far i cant get the latest APR to work.

Can some one explain to me how to use these binary files so Tomcat loads APR again.

Best
Mark

14 years ago
Hi Paul,

Cool, i just needed to understand how it worked, i have figured it out now based on what you suggested.



I will now be able to create XML that looks similar to what is defined in the dtd. All though i must say im still a bit unsure of how to use the DTD to confirm this programmatically, any suggestions?

Best
Mark Hughes
I have tried that, Creating more parameters seems to mess up the tree structure, and would not work great when trying to dynamically add new parameters when working with a for loop or another iterator function.

I was hoping some kind of function for adding attributes or children existed.
Ok i have decided to manually create the XML in the format i want. Now i juest have a question about adding elements.

My test main code below outputs xml, in the format i want, but all the data is not being outputted. The setAttribute method only allows one value to be set, while i want more than one line of xml to have attributes set.

for example my outputted xml is:
<?xml version="1.0" encoding="UTF-8"?>
<problem>
<parameters>
<parameter name="3" value="3" />
</parameters>
</problem>

when i really want it to look like:
<?xml version="1.0" encoding="UTF-8"?>
<problem>
<parameters>
<parameter name="1" value="1" />
<parameter name="2" value="2" />
<parameter name="3" value="3" />
</parameters>
</problem>

My code is as follows, all help appreciated.


Best
Mark Hughes