Tuesday, December 2, 2008

JBoss web service blocked

If you have a web service in JBoss of which you can access the WSDL but keep getting "connection refused" error when accessing the service, then the culprit is normally this:


C:\jboss-4.2.2.GA\bin\run.bat -b 0.0.0.0


or


C:\jboss-4.2.2.GA\bin\run.bat


A solution - at least what worked for me - was to use the actual IP of the machine like so:


C:\jboss-4.2.2.GA\bin\run.bat -b 192.168.1.11


Its funny how modifying JBoss startup scripts did not affect the "-b" option above. However specifying it on the command line works fine.

Monday, July 28, 2008

Using BETWEEN in an EJB3 query


Say if you have an EJB3 entity bean named Landmark which is mapped to a table called landmarks which has 2 columns longitude & latitude (amongst others). To query a given latitude & longitude, its a good idea to relax the query a bit by using BETWEEN.



An example is shown below where we allow a tolerance of 0.00003 for both latitude & longitude. The sample shown is an excerpt from an EJB3 entity bean, right before its class declaration.


@Entity
@Table(name = "landmarks")
@NamedQueries( {
@NamedQuery(
name = "Landmark.findByCoordinates",
query = "SELECT lgr FROM Landmark lgr " +
"WHERE lgr.latitude BETWEEN (?1 - 0.00003) AND (?1 + 0.00003) " +
"AND lgr.longitude BETWEEN (?2 - 0.00003) AND (?2 + 0.00003) ")
})
public class Landmark implements Serializable {

Convert NMEA latitude & longitude to decimal

Here's how you convert latitude & longitude obtained from NMEA's GPGGA to decimal:











 NMEADecimal
latitude0302.7846903 + (02.78469/60) = 3.046412
longitude10141.82531101 + 41.82531/60) = 101.6971


Notice that for latitude of 0302.78469,


03 ==> degress. counted as is


02.78469 ==> minutes. divide by 60 before adding to degrees above


Hence, the decimal equivalent is:


03 + (02.78469/60) = 3.046412