java
Nov 04, 2011
Say hi to Android
A brief introduction to Android for developers
In the last months, I have been looking for an opportunity to get into the Android world.
Finally, after a while I got the right one: porting an iPhone app to Android platform.
The application is quite simple because it doesn't involve anything far from a common web application: it just retrieves information about events from a web service.
If you make a list of performed tasks, it would look like this:
- retrieving the xml content
- parsing the xml
- storing a few configuration files
- loading images
- building a couple of data structures
- showing everything using the specific views and widgets
Thanks to the reference documents and materials found in the Internet, I got a demo app smiling on my device in a couple of days (not a proper relase, but it could run smoothly).
If you are familiar with Eclipse, you will appreciate the effort made by Google, in order to provide a confortable developement environment. Let's see why.
From the official site you can download:
- Android SDK (JDK required)
- Android Development Tools (ADT) Plugin
You just need to set your SDK. And that's all! Ready to start.
As you can easily guess, the default API provided by Google is Java-based.
I know that some of you can argue "Java is not the best choice", but it's solid and well known by most programmers. It is also well documented and it comes with tons of libraries.
The Android application layout is done by a bunch of xml files. The ADT provides a nice interface to manage them.
All the Java code needed for your app can be taken from your personal toolset or grabbed from the net.
What I love most, is that you can easily connect your device and directly deploy the application on it. Moreover, for those who make use of remote debugging in Java, Android (DDMS) is faster and simpler then ever: just press the debug button and your code will be ready for debugging from your android device. Nothing new to the world, but as I said easier then I thought.
A small disadvantage if you use the virtual device (AVD), because it is really slow, especially in loading.
Just a small consideration: because the hardware behind a mobile device is usually less powerful then a standard pc, you have to be careful.
In a few days the release of AppEventi for Android will be ready. http://www.ferraraterraeacqua.it/
Here is the iPhone app: http://itunes.apple.com/en/app/ferrara-eventi/id449817238?mt=8
Oct 28, 2011
Using JavaMail with TLS
Snippets about sending mail though Java with TLS support
Here is an example to show you how to use JavaMail API method to send an email, using both TLS and SSL connection.
If you are using TLS, remember to disable this property:
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.starttls.enable","true")
props.put("mail.smtp.host", server);
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
props.put("mail.debug","false");
props.put("mail.smtp.port",port);
props.put("mail.smtp.ssl.enable","true");
props.put("mail.smtp.socketFactory.port", port);
props.put("mail.smtp.socketFactory.fallback", "false");
Remember that, when you set Authentication to server with PasswordAuthentication class, you could experience this error:
"javax.mail.AuthenticationFailedException: 535-5.7.1 Username and Password not accepted."
Send by server if user or password used for authentication failed. Usually means that server requires full user name (user@server.com) to be used.
Jul 19, 2011
Problems with charset in 8.5.1 environment
Strange behaviour managing XML file in Java agent
In this scenario, i've experienced some problems with UTF-8 charset in strings. In 6.5 environment everithing works fine.
This is my code in a Java agent:
org.w3c.dom.Document docXML = attachSegnatura.parseXML(false); XSLTResultTarget out = new XSLTResultTarget(); out.setFileName(path + "SegnaturaRT.xml"); attachSegnatura.transformXML(xsl, out); DOMParser parser = new DOMParser(); parser.parse(path + "SegnaturaRT.xml"); org.w3c.dom.Document docRT = ((DOMParser)parser).getDocument();
tFactory = TransformerFactory.newInstance(); StreamSource xslSS = new StreamSource(pathFile+"Segnatura.xsl"); StreamSource xslRT= new StreamSource(pathFile + "Segnatura.xml"); FileOutputStream fos = new FileOutputStream(pathFile + "SegnaturaRT.xml"); transformer = tFactory.newTransformer(xslSS); transformer.transform(xslRT, new StreamResult(fos)); transformer.reset(); fos.close(); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); docRT = dBuilder.parse(new File(pathFile + "SegnaturaRT.xml"));
Anybody experienced something like this?
Apr 06, 2011
DIIOP?? No more...
I'm porting servlet code running on 6.5 Domino Server in XPages.
Servlet comunicate with Domino through DIIOP, and need DIIOP to istantiate Session object:
lotus.Domino.session = NotesFactory.createSession(server,login, password);
Thanks to Karsten Lehmann for its great library:
http://www.mindoo.com/web/blog.nsf/dx/18.07.2009191738KLENAL.htm?opendocument&comments
Now i can initialize a session using:
lotus.Domino.session = DominoAccess.getCurrentSession();
No more DIIOP needed!!
Oct 13, 2010
Oracle and IBM Collaborate to Accelerate Java Innovation Through OpenJDK
Oracle and IBM today announced that the companies will collaborate to allow developers and customers to build and innovate based on existing Java investments and the OpenJDK reference implementation. Specifically, the companies will collaborate in the OpenJDK community to develop the leading open source Java environment.
Jun 26, 2010
System.getProperty() returns null
How to avoid a null pointer using System.getProperty() within a java agent.
Sometimes, for some reason, you have to do it. I'm talking about the use of System.setProperty() method within a java agent. If you don't pay attention it's easy to get a null pointer as result. Infact I got it.
After a quick search I found out a way to solve the issue:
I will use "jna.library.path" as example.
First of all add the following line in "java.policy" file (in the "jvm\lib\security" folder below the Domino program folder).
permission java.util.PropertyPermission "jna.library.path", "read,write";
After that, add the java code to your agent :
String jnaProperty = "jna.library.path";
if(System.getProperty(jnaProperty) == null) {
System.setProperty(jnaProperty,"your path");
}

