Author Archives: mee

JSP Error : Attribute qualified names must be unique within an element

Today I updated an old Spring MVC application to Apache Tomcat 7 and some other newer jars and, when I started it, I get this error:

SEVERE: Servlet.service() for servlet [mvc-dispatcher] in context with path [/CG] threw exception [/WEB-INF/view/main.jsp (line: 2, column: 0) /WEB-INF/view/include.jsp (line: 3, column: 75) Attribute qualified names must be unique within an element] with root cause
org.apache.jasper.JasperException: /WEB-INF/view/main.jsp (line: 2, column: 0) /WEB-INF/view/include.jsp (line: 3, column: 75) Attribute qualified names must be unique within an element

After some search i find out that using single attribute multiple time in a single tag throw this error(it works with no problem in previous version!!!)

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

I removed the duplicated “prefix” tag and everything worked fine! (…ehm… everything? Of course not… but this exception has been fixed)

Tagged ,

The most motivational video I’ve ever seen

Today I found this article on LinkedIn web site: The 15 Most Inspiring Videos of All Time. That’s really amazing collections of inspiration videos. In my opinion, there top of the list should be this one:

The Last Lecture – Randy Pausch

The most motivational video I’ve ever seen.

Debug content model in Alfresco

When you need to customize Alfresco content model, not always everything works fine so, it’s necessary to find a way to check if your model is correct or not. It’s possible to use the built-in Get Class Definitions webscript to debug. Basically, you can use this webscript to see if an expected content type exists on Alfresco or not. You can also use this webscript to see if an expected content type exists on Alfresco or not. All you have to do is to call the webscript with your class name which in this case myroot:mycontent for me.

http://localhost:8086/alfresco/service/api/classes/myroot_mycontent

Or you can call the same webscript without a class name, in this case webscript will dump every content type that exists on Alfresco.

The response will be something like that:

 
   {
      "name": "labtest:Labtest_content",
      "isAspect": false,
      "isContainer": false,
      "title": "Labtest content model",
      "description": "",
      "parent":
      {
         "name": "cm:content",
         "title": "content",
         "url": "/api/classes/cm_content"
      },
      "defaultAspects":
      {
         "sys:referenceable":
         {
            "name": "sys:referenceable",
            "title": "Referenceable",
            "url": "/api/classes/labtest_Labtest_content/property/sys_referenceable"
         },
         "sys:localized":
         {
            "name": "sys:localized",
            "title": "Translation",
            "url": "/api/classes/labtest_Labtest_content/property/sys_localized"
         },
         "cm:auditable":
         {
            "name": "cm:auditable",
            "title": "Auditable",
            "url": "/api/classes/labtest_Labtest_content/property/cm_auditable"
         }
      },
      "properties":
      {
         "cm:name":
         {
            "name": "cm:name",
            "title": "Name",
            "description": "Name",
            "dataType": "d:text",
            "defaultValue": null,
            "multiValued": false,
            "mandatory": true,
            "enforced": true,
            "protected": false,
            "indexed": true,
            "url": "/api/classes/labtest_Labtest_content/property/cm_name"
         },
         "labtest:Labtest_result_name":
         {
            "name": "labtest:Labtest_result_name",
            "title": "Labtest result name [java uses to get this content]",
            "description": "",
            "dataType": "d:text",
            "defaultValue": null,
            "multiValued": false,
            "mandatory": false,
            "enforced": false,
            "protected": false,
            "indexed": true,
            "url": "/api/classes/labtest_Labtest_content/property/labtest_Labtest_result_name"
         },
         "cm:content":
         {
            "name": "cm:content",
            "title": "Content",
            "description": "Content",
            "dataType": "d:content",
            "defaultValue": null,
            "multiValued": false,
            "mandatory": false,
            "enforced": false,
            "protected": false,
            "indexed": true,
            "url": "/api/classes/labtest_Labtest_content/property/cm_content"
         }
      },
      "associations":
      {
 
         "labtest:labtest_static_components":
         {
            "name": "labtest:labtest_static_components",
            "title": "Labtest static components",
            "url": "/api/classes/labtest_Labtest_content/association/labtest_labtest_static_components",
            "source":
            {
               "class": "labtest:Labtest_content",
 
               "mandatory": true,
               "many": true
            },
            "target":
            {
               "class": "labtest:Labtest_static_component",
 
               "mandatory": false,
               "many": true
            }
         }
         ,
         "labtest:labtest_dynamic_components":
         {
            "name": "labtest:labtest_dynamic_components",
            "title": "Labtest dynamic components",
            "url": "/api/classes/labtest_Labtest_content/association/labtest_labtest_dynamic_components",
            "source":
            {
               "class": "labtest:Labtest_content",
 
               "mandatory": true,
               "many": true
            },
            "target":
            {
               "class": "labtest:Labtest_dynamic_component",
 
               "mandatory": false,
               "many": true
            }
         }
      },
      "childassociations":
      {
 
 
      },
      "url": "/api/classes/labtest_Labtest_content"
   }
Tagged

Analyzie MS Exchange log

Sometime happens to receive some interesting requests from the business like “Hey man, take a look if there are some strange access to our web mail”. This tool it’s really useful for this kind of task: Log Parser Studio

It requires (in this case) a IISW3CLOG and a simple query like that:

SELECT TOP 20 cs-username AS UserID, 
	cs(User-Agent) AS Application, 
	cs-uri-stem AS Vdir,
	c-ip AS CLIENT,
	cs-method,
	COUNT(*)
FROM '[LOGFILEPATH]'
WHERE cs-uri-stem LIKE '%OWA%'
GROUP BY UserID, Application, Vdir, Client, cs-method
ORDER BY COUNT(*) DESC

That’s all!

Tagged ,

How to download PDF file from url on MVC controller

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 = new URL(remoteURL);        	
		response.setHeader("Content-disposition", "attachment;filename=" + filename);
 
		//Set the mime type for the response
		response.setContentType("application/pdf");
 
		// URLConnection connection = url.openConnection();
		InputStream is = url.openStream();
 
		BufferedOutputStream outs = new BufferedOutputStream(response.getOutputStream());
		int len;
		byte[] buf = new byte[1024];
		while ( (len = is.read(buf)) &gt; 0 ) {
			outs.write(buf, 0, len);
		}
		outs.close();
 
	} catch (MalformedURLException e) {
		logger.error("Error ModelAndView.viewMain - MalformedURLException : " + e.toString() + " -- " + e.getStackTrace()[0].toString());
		return null;
	} catch (IOException e) {
		logger.error("Error ModelAndView.viewMain - IOException : " + e.toString() + " -- " + e.getStackTrace()[0].toString());
		return null;
	}
 
	return null;
 
}
Tagged ,

Import oracle expdata file to different user

To import an Oracle exported file with *nix command line, use this command:

imp \'/ as sysdba\'  file=expdat.dmp fromuser=ORIGINALUSER touser=DESTINATIONUSER
Tagged

Understanding Credit crunches

Credit crunches are usually considered to be an extension of recessions. A credit crunch makes it nearly impossible for companies to borrow because lenders are scared of bankruptcies or defaults, which results in higher rates. The consequence is a prolonged recession (or slower recovery), which occurs as a result of the shrinking credit supply.

Read more: http://www.investopedia.com/terms/c/creditcrunch.asp#ixzz2M09MeA6H

Tagged

Route a message to MongoDB

The requirement is very simple. Route an XML message from rabbitMQ to MongoDB. MongoDB BSON as the data storage and network transfer format for “documents”. BSON is a binary-encoded serialization of JSON-like documents. So, the source message is in a XML format, after getting it from rabbitMQ is necessary to translate into a JSON format compatible with MongoDB.

To translate a message from XML to JSON is possible to use Marshalling function available in Camel extension XmlJson. The pom.xml file needs this new entry:

<dependency>
	<groupId>org.apache.camel</groupId>
	<artifactId>camel-xmljson</artifactId>
	<version>${org.camel.version}</version>
</dependency>

Of course, to send communicate with MongoDB another entry has to be added to pom.xml:

<dependency>
	<groupId>org.apache.camel</groupId>
	<artifactId>camel-mongodb</artifactId>
	<version>${org.camel.version}</version>
</dependency>

Now, is possible to change the route on camel ApplicationContext file:

<!-- Camel route -->    
<camelContext xmlns="http://camel.apache.org/schema/spring">
	<dataFormats>
		<xmljson id="xmljson"/>
	</dataFormats>
	<route> 
		<from uri="spring-amqp:TPDirect:TPQueue:TPRouting?type=direct&amp;autodelete=true&amp;durable=true" />
		<marshal ref="xmljson"/>
		<log message="From XML to Json: DONE!" />
		<convertBodyTo type="java.lang.String"/>
		<to uri="mongodb:myDb?database=flights&amp;collection=tickets&amp;operation=save" />
	</route>                                 
</camelContext>
 
 
<!-- Mongo DB -->
<bean id="myDb" class="com.mongodb.Mongo">
	<constructor-arg index="0" value="localhost"/>
</bean>

Bean myDB contains the information to reach MongoDB. It’s also possible to define it using the full url:

<bean id="myDb" class="com.mongodb.Mongo"> 
    <constructor-arg index="0"> 
        <bean class="com.mongodb.MongoURI"> 
            <constructor-arg index="0" value="mongodb://username:password@host:port/db" /> 
        </bean> 
    </constructor-arg> 
</bean>

To avoid this exception:

Caused by: No type converter available to convert from type: byte[] to the required type: org.apache.camel.component.mongodb.converters.MongoDbBasicConverters with value

The JSON translated message has to be converted into String.

That’s all!

[AdSense-A]

Tagged , , ,