Archive
Validation using the builder pattern
I currently have a little crush in the builder pattern. This pattern and variations of it can solve common programming issues in a pretty straightforward way. I will give you an example of how you can use it in a validation context. A use case could be when you want to be able to perform different operations on the validation result. And you want a clean separation between the actual validation logic and the result of the validation. An advantage is that it is much less error prone e.g how to use the objects compared to letting a single class have all responsibility. Further it also makes it possible to have different “validation result objects” for the same validation logic, if needed.
Read more…
My Devoxx 2012 experience
Securing the client side: Building safe web applications with HTML5
It is more important than ever to think of security when developing HTML client functionality. People make mistakes, thats’it. We need more of a programming model that can help us making as few mistakes as possible, See Content security policy Content Security Policy An example is to divide functionality in different blocks, and just give each block as much privilegies as it needs and no more. For example, if one block won’t be executing any script, then we won’t let it. This way we can prevent malicious javascript code from executing in this block. Also consider that nowadays there is no reason not to communicate through HTTPS instead of HTTP. This way it’s so much harder, but not impossible to leak information, and also prevent information from beeing added to the response coming from the server using a “man in the middle attack”.
Behavoiur driven development on the JVM – a state of the union
I have been interested in BDD for a long time, but never really practiced it. In this talk, the presenters first ranted a little about the background of TDD and how the developing speed succeeds non testdriven development over time, but then they moved over to BDD. BDD has som interesting features like tests also becomes documentation for the system. Far better than let’s say Javadoc. This I think moves testing away from often beeing kind of a maintenace weak spot til actually really helping out in describing what the system should do. It’s also interesting in how it approaches testing, not only making unit test but focusing on testing bits and pieces togheter in a moderately predefined way using a tool of your choice. Also known as acceptance testing and/or integration testing.
Read more…
Some hibernate characteristics
Hibernate is a mature ORM tool for Java environments and is Free under LGPL. Hibernate lets you map your Java classes to database tables, and also provides data query and retrieval facilities. This article will focus on data query and retrieval facilities. I will not go into detail about how a query might be built and instead focus on some other things that a developer should have in mind.
The term session is a central part of the framework. The sessions lifecycle can span several database transactions and is the place where you create, read, update, delete instances of your mapped entity classes. Instances of your java classes can exist in three different states. Transient: An instance is transient when it at no point in time has been persisted with the session e.g when a new instance is made in your application. Persitent: An instance is persistent when it is associated with a session. Detached: The instance has previously been persisted but is currently not associated with a session.
RPC/Encoded webservice
When you need to consume a webservice and that service is using a deprecated rpc/encoded binding style, then you are faced with a problem that there is no real good solution to. In short, the problem is that all the JAX-WS implementations from a couple of years back have ommitted their support for this configuration. “The WS-I Basic Profile limits binding styles to either Document/literal or RPC/literal, and JAX-WS was designed to honor this limitation” I can think of a couple of options to work around this problem. Read more…
Publish JAX-WS services at runtime
One smooth way of testing your webservices is to use the lightweight HTTP server embedded into the JDK. This way you don’t have to deploy your services in a (tedious) JEE container, or servlet container for that matter. You can signifcantly improve your turnaround time between coding and deploying. Turns out all that is required is one line of code (at best).
import javax.xml.ws.Endpoint;
//..
{
Endpoint.publish("http://deploy/path/", new WebServiceImplementor());
}
Where the URI is the path to the location where you want your endpoint deployed and the second argument is your JAX-WS annotated endpoint implementation object. By the way, you will need at least Java SE 6.
Tomcat – EL – JSF 1.2 bugg
Ofta när man jobbar med numeriska värden tex Integer, vill man kunna persistera värdet som NULL för att symbolisera ett tomt värde. Jag märkte dock en lustig sak när jag jobbade med ett system som kör med JSF 1.2 under tomcat-6.0.20. När jag läste upp ett NULL numeriskt värde i en JSF component och sparade formuläret, så persisterades värdet som 0(noll) istället för NULL. Under tomcat-6.0.14 återfinns inte samma problem. Jag antar att de båda versionerna använder olika EL implementationer. Read more…
GOTO Aarhus
Här får ni en liten summering ifrån konferensen jag var på mellan den 10-12 oktober, GOTO Århus. Jag var även på denna konferens för 2 år sedan, då den hette JAOO. Konferensen är uppdelad på 3 training days och lika många teoretiska dagar. Jag var endast på de 3 teoretiska dagarna, där respektive dag är uppdelade i 6 olika spår. Om man jämför konferensen 2009 mot 2011 så tycker jag mig uppleva att den var något mindre teknisk i år. Eller så kan det också vara så att de tekniska dragningarna omedvetet inte lockade mig i samma utsträckning denna gång, och att jag därför upplevde konferensen som mindre teknisk. Många ämnen har jag stött på tidigare, och även fast det självklart kan göras nya intressanta upptäckter i talen så finns det ju en risk att det blir mycket upprepningar. Det är en svår avvägning att göra. Det enda ämne/spår som jag enkelt kan säga var helt nytt för mig var Devops. Den teorin handlar kortfattat om metoder och principer för att få bättre och ökad kollaboration mellan utvecklare och operations(drift osv). Målet är att få till en smidig process ifrån utveckling till och med leverens(deploy). Spåret handlade mycket om just continous delivery. Read more…
Generera Excelfiler på “nya” (xlsx) formatet med JasperReports
En litet inlägg som handlar om rapportgenerering av Excelfiler med hjälp av JasperReports på .xlsx formatet.
Jag skulle i ett system byta ut alla befintliga Excelrapporter som använder .xls formatet mot .xlsx formatet som kom i och med Excel 2007 (dvs ett inte särskilt nytt format). Låter inte särskilt svårt att göra just den biten och det är det inte heller. Här kommer likväl ett litet exempel som visar rapportgenerering av Excelfiler med hjälp av JasperReports på .xlsx formatet. By the way, xlsx bygger på Office Open XML(OOXML).
Så exporteringskoden skulle kunna se ut som något i stil med detta:
import net.sf.jasperreports.engine.export.ooxml.JRDocxExporterParameter;
import net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter;
...
...
JRXlsxExporter exporterXLSx = new JRXlsxExporter();
exporterXLSx.setParameter(JRDocxExporterParameter.JASPER_PRINT, jasperPrint);
exporterXLSx.setParameter(JRDocxExporterParameter.OUTPUT_STREAM, output);
exporterXLSx.exportReport();