Calendar
QuicksearchBookmarksMy del.icio.us
ArchivesCategoriesSyndicate This BlogBlog Administration |
Saturday, January 19. 2008Last entry ...
Welcome to the last entry of this blog. No I am not quitting, I am just moving. I just installed a new blog software framework. I was starting to dislike the way to interact and I wanted something that contained more out of the box. I am in the middle of moving to wordpress software. There is a very good reason to do this. I had found a great tool on the mac called MarsEdit. And again this could not be used with serendipity. I hope I did make a good choice. Since there is a lot of information in the old blog, I did not take this blog offline. It will stay to exist, but I will not make changes there anymore.
I hope to see you at the new version of the blog (check the page at http://www.gridshore.nl). You can attach you feedreader to the following url: feed://www.gridshore.nl/feed/
Posted by Jettro Coenradie
in acegi, ajax, Announcements, Books, gridshore, Java, News, spring-osgi, Springframework, Technology, Webservices, Websites&products
at
20:58
| Comments (0)
| Trackbacks (0)
Saturday, November 11. 2006Using vmware and apache http server as a proxy
Currently I am working with vmware. I want to be flexible in reconfiguring my server without constantly having to re-install. Next to that I like it that I can configure my complete server and then move it to the production server. I am also looking into virtualization for the production server. Some of my collegues are also looking at it, and it looks very promising.
Ofcourse when using a new technique, you will be facing some problems. Within this blog I will explain my idea and the solution that I created. Demand I want an environment where I am able to install new servers on demand. I want to be able to have a continuous intergation server, a test server, a quality assureance server and of course a production server. If I go to my management and tell them I need 4 servers to start with they will not like it. It is better to ask for one big server and use vmware. Next to that I am very flexible in moving around servers. I can configure the server locally and put it on the host server if I am done. In the end there will be almost no downtime for testers etc. Oke, that point should be clear now. There is another thing. I do not want to expose all virtual servers to the clients. This could lead to a lot of firewall rules, ip addresses to remember or dns entries. I want to be flexible. That is why I want a proxy in front of the virtual machines. This proxy is installed on the host machine and redirects to virtual machines. Solution The following image shows the complete picture in a deployment diagram ![]() Deployment diagram showing the host server and the virtual machines. This diagram shows the host server that is running windows 2003 server edition. This server can be reached using a vpn and remote terminal client. Within this server we have vmware running with two images. One image for continuous integration and the maven reports, the second image contains apache tomcat with our deployed application. First we install the linux virtual machines. I took a pre configured ubuntu installation: http://www.thoughtpolice.co.uk/vmware/ After that I needed to install java, tomcat,continuum,apache2, ssh. It surprised my how easy this is nowadays. As an example, the next command downloads and configures ssh on the server.
It cannot get more easy than this. Simular steps were necessary for the other components. One other I want to mention is downloading the continuum jar. This is done with a command called wget.
Again, very easy. If you want to have more information, these websites helped me figuring out the right commands: http://www.kintespace.com/rasxlog/?p=468 http://www.spaceprogram.com/knowledge/2006/05/installing-java-5-jdk-and-tomcat-on.html Now you want to install and configure the apache 2 http server. Installation is not that difficult on most systems. You need to include the proxy module for apache. This can be done with the command
The final part is configuring the proxy, therefore you must add the following lines of code to the file /etc/apache2/mods-enabled/proxy.conf
It is not the best step-by-step approach I have created, still I thing this will do. If you are have questions, use the comments. If you want more information about the mod_proxy module have a look at this website: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html Sunday, October 15. 2006Centralized or distributed SCM
For a project I did a while ago we were thinking about using a branch for each developer while working on large changes/additions. Why, you ask? Well I'll try to explain, believe me I know there are alternatives but think about it before you judge.
Scenario We want to deliver version 3.0 of our application but we also want to continue creating some new usecases. Since we use test driven development, we create a test, implement functionality and run the test. After this we want to check in the stuff and let the integration test run by our continuous build. One possible obvious solution could be to use a branche for the 3.0 release and continuo working on the head. This all sounds clear, we use subversion as an scm (Source Control Management) system. I do have one problem though. The repository is on a server of a friend of mine, I need to use an scm which I cannot use everywhere due to firewall settings. Therefore I cannot checkin code, which makes I cannot separate the different features I implement. Last week I listened to the javaposse podcast. There was an item about distributed scm. I got interested and desided to investigate further. I had a look at Mercurial and I am still curious. I copied the following piece of text from their wiki: A distributed SCM tool is designed to support a model in which each Repository is loosely coupled to many others. Each Repository contains a complete set of metadata describing one or more projects. These repositories may be located almost anywhere. Individual developers only need access to their own repositories, not to a central one, in order to Commit changes. Distributed SCMs provide mechanisms for propagating changes between repositories. I installed the stuff (very easy, good manual, only 2.5 Mb or so download). There is a nice tutorial giving you the basics of using mercurial. Next steps I am not convinced I need a distributed scm. I like the idea of having a local repository. I think this can help you when working in a gridshore project. I want to have a better look at a good workflow for such a system. How are you going to configure your continuous integration? The first thing I did was looking for a mercurial maven scm plugin. There is a very current thread in jira about maven and mercurial. I want to start an experiment with this, so if you are reading this and you have experience or good articles please post a comment or send an email. Friday, February 3. 2006Luntbuild and Maven 2, the ideal couple?
After playing around with continuum I am back on my luntbuild feet. I really tried continuum, good community by the way, but the maven site integration is not really possible. That is at least a little bit strange. The same is valid for labelling builds. Why this introduction for a luntbuild maven story, well, with luntbuild it is possible. Maybe not perfect but possible.
Let me explain, luntbuild does have maven 2 integration, I wanted to be able to copy the results of the site target to the luntbuild artifacts directory. This is not possible out of the box. But with a small experiment I created a maven mojo that does the trick. First disadvantage, you need to provide an extra part to the pom that is only needed for copying the site. I do want to do some more research whether this was really necessary, but for now it works. So what is in this blog item? I will give you some details on creating a plugin for maven. Then Ill present you with the configuration of luntbuild to pass parameters to maven by using environment variables. In the end just a screenshot with the artifacts of the different maven projects. Creating the maven plugin, or mojoThere is a guide available on the maven website. Read this first, then come back for the step by step approach. Use the appropriate archetype to create the project with maven:
Compile the project, create the eclipse project space and start up eclipse
An example for a plugin is allready available in the generated project. We will create our own by subclassing the AbstractPlugin class. I do not want to teach java specifics in this blog item. Therefore just the code:
If you have read the guide I mentioned, you now the javadoc attributes are important. These are used to set the parameter values and the name of the goal that is created. Having done that, we can package and install the new goal and test it.
You probalby get an error message, that is because you are missing a part in the pom. You need to define the outputDirectory for the move goal.
Running the command again should result into the following:
Actually that is all there is to it. In order to shorten the amount of typing needed on the command line, you will need to add your plugin's group ID to the list of group IDs searched by default. To do this, you need to add the following to your settings.xml file:
Now you can run the following command and the result should be the same.
Integrating maven 2 with luntbuildThere a re two important screens in luntbuild with respect to maven: ![]() ![]() Finally you have to prepare you pom(s):
If you are having problems, the sample is available at: http://svn.javaforge.com/svn/Equinox_Student_Registration_Sample/trunk/registrations Beware that browsing source code from the javaforge website does not work very well, it does not refresh. Hope this helps, please drop me a comment if it does help or if you are heving problems. Sunday, January 29. 2006Cobertura and maven
Today I was experimenting with maven. I wanted to add code coverage. Ofcourse I start thinking about cobertura immediately. So I dived into cobertura and maven integration. It became kind of an experience. I know a lot more about maven now. I have to figure out some stuff, but for now it is good enough. This entry gives some steps to help you get up to speed with cobertura.
1. Install maven 2 quick start guide maven 2. Create an application that knows how to handle the goals package and site. see the quick start guide 3. The fun part begins : compile and install your own cobertura plugin. Download the sources from the codehaus subversion repository. You can use the following url to download them anonymously with a tool like tortoisesvn https://svn.codehaus.org/mojo/trunk/mojo/mojo-sandbox/cobertura-maven-plugin Then you have the sources. Now you need to alter the pom of that project to be able to check for latest versions. See the guide on the plugins website.
Issue the following command for the cobertura-maven-plugin project you have just downloaded and altered.
Now you are ready for the next step 4. Configure the pom.xml of your project to create the cobertura report. There are two aspects, first you need to add the plugin to the build part, then to the reports part. See the usage page of the plugin home page
5. Run the site goal and start browsing your coverage files. This is where I am having problems, it does work but you must do some parts alone. First I will give you what works, then I will give you what I am having problems with.
The first thing that gives problems is doing the code coverage on the top project that does not have sources itself. An error due to the fact that target/classes is missing is thrown. The second problem I have is that I cannot do the two commands at once, there is a class loading issue. I want to emphasize that this is a beginners perspective. The issues I am having might not be the complete truth. If you now more, or if I find out more, I will revise this part. You can find the sources at my sample project at javaforge. resources http://mojo.codehaus.org/source-repository.html http://cobertura.sf.net http://mojo.codehaus.org/cobertura-maven-plugin Monday, January 9. 2006ExtremeComponents: a nice taglibrary
A few years ago I was using the DisplayTag library, a very nice library I must add. When doing some coding for a project I had to many records to be in the table. Therefore I used the pagination, that is the moment I ran into problems. I wanted to do the paginations via the hibernate dataaccess layer. The current DisplayTag library does not support that. There are some samples with the HEAD version, I could not get the building process with maven to work. Therefore I started to look around and found a very nice component:
http://extremecomponents.org/extremesite/welcome.jsp This library includes a very nice view, good paginations backed by server components you can easily write yourself. Therefore I am writing this item, just to show you all how easy it is to do pagination and filtering of your objects in a nicely formatted table. The jsp
Actually, I think this is a lot of code, so let's step through it. Lines 9-11 take care of using an external pagination, filtering and sorting. The LimitCallback is used for that purpose. Line 8 shows you the name that can be used as the current item. Have a look at line 19, here you can see we use the order property to obtain the current value for the field order.id. Other interesting stuff, you can switch off filtering and sorting for each column, you can easily format a date field, and you can create your own cell formatters as well. Line 22 shows you how to define them in the jsp. We will show you the code for the formatter as well. But first we'll show you the spring controller that calls the appropriate service. The spring controller
I am having problems getting this to work, the second instance of DEFAULT_ROWS_DISPLAYED should be the value from the drop down list that lets you choose the number of items to display.
The Jakarta Bean-Utils package is used to set the values from the filters into the object that is send to the search service. If you enter a value in the lastname box, the searchOrder object will receive this value for lastname so that you can use it in your data access component. The next part of source code does something simular for the ordering.
We created a special object called QueryResultsOrder to hold the field for sorting and the direction in one object. Now you have all the data to call your service and put back the following to items in the request.
The last part I promised is the formatting of the cell. There is a BaseCell class that you can extend. The only method you need to overwiter is the html() method. There are a lot of utility methods. This method could look like this. StatusCellView extends BaseCell
The HtmlBuilder object is used to append all html elements to. Line 4 obtains the style sheet class for the span element to create. Line 6 adds the span element and sets the style attribute class. The span element is also closed in line 6, this way the next text is added after the opening span element. This is done in line 7, and in line 8 the closing span element is added. Actually that is all there is to it. Sounds fun doesn't it? Hope this helps some of you to get a quick start into the eXtremeComponents Tuesday, November 29. 2005Google analytics
A few weeks a go I started using google analytics. What a cool tool. You can gather a lot of information about the usage of your website. Some very nice graphs are produced as well. Have a look at their website for more info. At the moment you cannot start using your own statistics. There were to many request, so they had to stop new requests from coming in for a while. Some of the statistics for my website.
Browsers used : Firefox 57%, ie 37%, Safari 4%, Opera 4% Platform : windows 85%, linux 12% Screen resolution : 1024x768 34%, 1280x1024 33% Other interesting information is that most people find my website via google, some of the words most people search for are : acegi spring ajax Other good referers are the forum of springframework and the websites of the products that I use: Serendipity, Pmwiki, and MiniBB Most of you reed the blog, I guess this information changes the most. Reminds me that I want to start using the wiki for more thorough articles. But time is also limited for me Interesting stuff, Google analytics, next time I will show you some of the graphs.
Posted by Jettro Coenradie
in Technology, Websites&products
at
09:16
| Comments (0)
| Trackbacks (0)
Tuesday, November 22. 2005Using springframework to send an email with streaming attachment
For a customer of mine I had another fine problem to resolve. He must send an email with a csv file as an attachment to his transport partner. The content for the csv file come from the database. Creating a string that has the contents for the file is easy, it would also be fairly easy to create a file, store it on the file system and add the file as an attachment. There is however one problem; I do not need the file after it has been attached to the email and send.
I started lookin at the api's of springframework related to email. It is not that hard to find some code that looks like the following to create the email to be sent: 1. MimeMessage message = getJavaMailSender().createMimeMessage(); 2. MimeMessageHelper helper = new MimeMessageHelper(message,true); 3. helper.setFrom("from@gridshore.nl"); 4. helper.setTo("to@gridshore.nl"); 5. helper.setText("Text of the email"); 6. helper.setSubject("attachment mail sample"); Now for the fun part, how can we attach a generated csv file to the email without storing it on th efile system first. 7. InputStream attach = new ByteArrayInputStream(mailMessage.getBytes()); 8. StreamAttachmentDataSource datasource = new StreamAttachmentDataSource(attach,"attachment", "txt/plain"); 9. helper.addAttachment(attachmentName,datasource); 10.getJavaMailSender().send(message); The fun part is in line 8, you must create a custom implementation for the org.springframework.core.io.AbstractResource. This resource must convert an inputstream to an attachment. The code for this class looks like this: public class StreamAttachmentDataSource extends AbstractResource { private final static Log logger = LogFactory.getLog(StreamAttachmentDataSource.class); private ByteArrayOutputStream outputStream; private String name; private String contentType; public StreamAttachmentDataSource(InputStream inputStream, String name, String contentType) { this.outputStream = new ByteArrayOutputStream(); this.name = name; this.contentType = contentType; int read; byte[] buffer = new byte[256]; try { while((read = inputStream.read(buffer)) != -1) { getOutputStream().write(buffer, 0, read); } } catch (IOException e) { logger.error("Cannot create inputstream for mail attachment"); throw new AddAttachmentMailException("error.technical.mail.attachment"); } } public String getDescription() { return "Stream resource used for attachments"; } public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(this.outputStream.toByteArray()); } public String getContentType() { return contentType; } public String getName() { return name; } public ByteArrayOutputStream getOutputStream() { return outputStream; } } The hard part is not in the code, it is in finding the right code MimeMessageHelper - helps you with creating the mail message, a lot of try catch blocks less than with the standard way. AbstractResource - This is a convenience class for creating your custom resources JavaMailSender - Used to send messages that cannot be send as a SimpleMailMessage, implementation of th MailSender interface. Monday, November 21. 2005problems while upgrading sample from acegi 0.8.3 to 0.9.0
Today I did an upgrade of acegi for my sample application. Ofcourse there are a lot of resources about upgrading. There is an entry on the homepage of acegi and the blog from Matt Raible. These are my findings.
I have a CustomJdbcDaoImpl class, I used to obtain the granted authorities with the following lines of code: PersonDetails person = (PersonDetails) users.get(0); List dbAuths = getAuthoritiesByUsernameMapping().execute(person.getUsername()); if (dbAuths.size() == 0) { throw new UsernameNotFoundException("User has no GrantedAuthority"); } GrantedAuthority[] arrayAuths = {}; addCustomAuthorities(person.getUsername(), dbAuths); There is however a problem with the method ' getAuthoritiesByUsernameMapping()', this does not exist anymore in the 0.9.0 acegi version. To be continued The following change is getting a secure context. With the new version we use the following code to obtain a secure context: SecurityContextHolder.getContext() There is an issue with the events as well, there are now two main events, one for authentication and one for authorization: <bean id="authenticationLoggerListener" class="net.sf.acegisecurity.event.authentication.LoggerListener"/> <bean id="authorizationLoggerListener" class="net.sf.acegisecurity.event.authorization.LoggerListener"/> I also had to change my SecurityEventListener, the names of the events are changed, the code now looks like this: public void onApplicationEvent(ApplicationEvent event) { if (event instanceof AuthenticationFailureBadCredentialsEvent) { AuthenticationFailureBadCredentialsEvent authEvent = (AuthenticationFailureBadCredentialsEvent) event; securityManager.disablePerson(((User)authEvent.getAuthentication().getPrincipal()).getUsername()); } if (event instanceof AuthenticationSuccessEvent) { AuthenticationSuccessEvent authEvent = (AuthenticationSuccessEvent) event; securityManager.savePersonLastLoggedOn(((User)authEvent.getAuthentication().getPrincipal()).getUsername()); } } And finally, since my tag for authentication is now within the project I removed all the customized code for my custom taglibrary. See earliar posts if you want to know what I am talking about. Tuesday, November 8. 2005Doing ajax with ajaxtags and springframework
Today I created a nice autocomplete box with ajax and springframework. In my backoffice application I want to be able to select a product for an orderline. The moment I start typing valid options should be retreived from the database. Since I am creating a spring mvc application, so the ajax stuff must be incorporated into the spring application.
What did I use?I used the ajaxtag project libraries and spring framework to do the ajax stuff. There are a few things to do, I am not going to give a lot of detais, have a look at the samples for a more thorough sample. jsp to show formThe code is just like the example, do have a look at line 7, this is a work around to make the enter key work. Actually this is all there is to it to make the ajax part work at the client. Pretty cool stuff. This image shows the webpage this autocomplete is on. ![]() Where does spring come in?From the line number 19 in the previous code sample we can see that the view 'autocompleteProduct.html' is used to get the ajax popup. We use an abstract controller that gathers the products from the service layer. Then it returns a ModelAndView to the following class: Interesting lines in this source code are:
Actually that is all there is to it.
(Page 1 of 2, totaling 16 entries)
» next page
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||

