How to download PDF file from url on MVC controller

Posted in IT StuffTagged ,

To download a remote file (like a PDF) redirecting to response output, use these instructions to update a your Spring MVC controller: @RequestMapping(value="/viewAttach", method = RequestMethod.GET) public ModelAndView viewAttach(@RequestParam(value="article_id", required = true) String article_ref, HttpSession session, HttpServletResponse response) { /* *** Remember to check if Session still valid *** */ try {   URL url….

How to switch between different JVM in Ubuntu

Posted in IT StuffTagged ,

Sometime is needed to install different JVM on Ubuntu server due to application compatibility or software development purposes. To switch between different JVM in ubuntu from command line, use this command: sudo update-alternatives –config javasudo update-alternatives –config java and this menu will appear: There are 2 choices for the alternative java (providing /usr/bin/java).   Selection….

Put SQL result into a map

Posted in IT StuffTagged , ,

To extract two or more object (in this sample two Integer) from a DB and putting into a map, use this: final Map<Integer,Integer> topic = new HashMap<Integer,Integer>();   getJdbcTemplate().query(sqlCommand, new Object[] {query_parameter}, new RowMapper<Object>(){ public Object mapRow(ResultSet rs, int arg1) throws SQLException { topic.put(rs.getInt("integer1"), rs.getInt("integer2")); return null; } });final Map<Integer,Integer> topic = new HashMap<Integer,Integer>(); getJdbcTemplate().query(sqlCommand,….

Dynamic Web Module 3.0 requires Java 1.6 or newer

Posted in IT StuffTagged ,

I’m using STS and I configured my Web application to use Maven but, when I try to use Maven > Update project configuration, I’m getting this really annoying project error: Dynamic Web Module 3.0 requires Java 1.6 or newer. […] Maven WTP Configuration Problem One or more constraints have not been satisfied.Dynamic Web Module 3.0….

Resolving java.lang.OutOfMemoryError: PermGen

Posted in IT StuffTagged ,

Today our Alfresco doesn’t start due to this error: java.lang.OutOfMemoryError: PermGenjava.lang.OutOfMemoryError: PermGen The PermGen (permanent generation) holds data needed by the virtual machine to describe objects that do not have an equivalence at the Java language level like objects describing classes and methodse. So often large, complex apps will need lots of PermGen space. Similarly….

Download Alfresco content from Java using Spring

Posted in IT StuffTagged , ,

To download content stored on Alfresco repository using Java, this is one possible way: String url = "http://localhost:18080/alfresco/d/a/workspace/SpacesStore/" + attach.getNode_ref() + "/" + attach.getAttach_filename() + "?ticket=" + ticket; return new ModelAndView("redirect:" + url);String url = "http://localhost:18080/alfresco/d/a/workspace/SpacesStore/" + attach.getNode_ref() + "/" + attach.getAttach_filename() + "?ticket=" + ticket; return new ModelAndView("redirect:" + url); Where getNode_ref() is a….

Use of LIKE clause in sql prepared statement

Posted in IT StuffTagged , ,

Suppose you have a where condition with like clause: AND ( UPPER(C.ndg) LIKE UPPER(’%test%’) OR UPPER(C.ndg_name) LIKE UPPER(’%test%’) )and ( UPPER(C.ndg) like UPPER(‘%test%’) or UPPER(C.ndg_name) like UPPER(‘%test%’) ) on Java you should write something like that: AND ( UPPER(C.ndg) LIKE UPPER(’%?%’) OR UPPER(C.ndg_name) LIKE UPPER(’%?%’) )and ( UPPER(C.ndg) like UPPER(‘%?%’) or UPPER(C.ndg_name) like UPPER(‘%?%’) )….

Query Alfresco Web script using REST

Posted in IT StuffTagged , ,

With Spring 3 querying a REST-based service it’s easy. For first, you need to authenticate on Alfresco repository using an Alfresco Ticket instead of an explicit user name and password. A ticket represents a pre-authenticated user who has already performed the login process. To log in, the url is: http://localhost:8081/alfresco/service/api/login?u=admin&amp;pw=adminhttp://localhost:8081/alfresco/service/api/login?u=admin&amp;pw=admin Assuming the userid and password….