Thursday 6 December 2007

Mapped Drive and .NET FullTrust

Recently I came across a problem where my .NET project does not work when my source code is on my mapped drive. In order to give the mapped drive a FullTrust permission, this is what I did:
c:\>caspol -q -machine -addgroup 1 -url file://j:/* FullTrust -name "J Drive"
Have a look at this article for more detail.

Saturday 10 November 2007

.NET and Java Integration

Here are the things you need to watch out when trying to integrate web services via HTTPS (.NET as the client)
  • Certificate trust issue
    DOT NET client needs to trust the certificate by adding this class which accepts all certificates. public class TrustAllCertificatePolicy : System.Net.ICertificatePolicy {
    public TrustAllCertificatePolicy() {}
    public bool CheckValidationResult(ServicePoint sp, X509Certificate cert,WebRequest req, int problem) {
    return true;
    }
    }
    To use this CertificatePolicy?, tell the ServicePointManager? to use it before making a call to the webservice: System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
    Refer to: http://weblogs.asp.net/jan/archive/2003/12/04/41154.aspx
  • Expect 100-Continue issue
    I spent a significant amount of time trying to solve this issue! I finally ended up using tcpmon, an open source Java utility to monitor and capture data through TCP connection. Apparently, the problem is quite prevalent because some web servers do not implement this properly. We are hosting web services in our server in the office using Apache Tomcat, and the web service client is written in .NET framework. Both systems talk to each other using SOAP requests via the web. .NET client by default sends the header without the form data. The web server should respond with 100 (continue). Not all webservers handle this correctly, and to avoid this problem, the Expect100Continue flag needs to be set to false. Before making a call to the webservice, add this code: System.Net.ServicePointManager.Expect100Continue = false;
    Refer to: http://haacked.com/archive/2004/05/15/449.aspx
  • Arrays
    Coming up..

Sunday 22 April 2007

Enterprise JavaBeans 3.0


As well as covering EJB 3.0 in depth, this book is also a good introduction for Java programmers developing server side programming. I use this book as a reference for the project that I'm currently working on.

Wednesday 14 February 2007

JBoss Transaction Rollback

When creating your own Exception in JBoss, it is important to remember that the default @ApplicationException's rollback field is FALSE. You don't want to assume that it is true, and sometime down the road you find out that transactions are not rolled back when this Exception is thrown. See: "Transaction rollback" section on http://trailblazer.demo.jboss.com/EJB3Trail/services/transaction/

Friday 2 February 2007

Oracle, Java 5, and BigDecimal

Be careful when you are using Oracle and Java 5: http://www.javalobby.org/java/forums/t88158.html
BigDecimal toString() difference in Java 1.4 and Java 5: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6298816

Friday 12 January 2007

Spring, Hibernate, Lazy Loading, and Sessions

Recently I've developed a Spring application to notify users based on certain conditions on data extracted from an ERP system using Hibernate. I had a LazyInitializationException problem when looping through some hibernate objects, because the connection had already been closed i.e. The service layer had finished it's job and therefore closed the connection. The hibernate object became detached, and since I specified lazy to true, I got the LazyInitializationException.


Since it is not a web app, I cannot use OpenInSessionViewInterceptor or OpenInSessionViewFilter, so I figured out that I had to use some manual code to keep the session open. Here is the code to solve the issue:


private static SessionFactory sessionFactory;
private static ApplicationContext init() {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
sessionFactory = (SessionFactory) context.getBean("sessionFactory");
Session session = SessionFactoryUtils.getSession(sessionFactory, true);
TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
return context;
}

private static void end() {
if (sessionFactory != null) {
SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.unbindResource(sessionFactory);
SessionFactoryUtils.closeSession(sessionHolder.getSession());
}
}

Share |