Bernard's Technocratic Blog


PHP – Why is your image rendering the PHP file name?
May 5, 2011, 3:29 am
Filed under: PHP, Web Development

Don’t be like me racking my brain for hours trying to figure out why my xxx.php file outputs http://localhost/xxx.php as a one line response.

Why?

Most likely, you have either:

1. white spaces before or after the php tags
2. need to set header(‘Content-type: image/jpeg’);
3. if you have required files…be sure nothing is outputted…no test print statements because page expects image information
4.  there is an error in your code

In my case, it was 4.  There is a reason why the function call base64decode does not work…

It’s actually: base64_decode()

By the way, other ways to validate your image encoded in base64 is to use the following tag:

echo ‘<img src=”data:image/jpeg;base64,’.$row['IMAGE'].’” alt=”photo”>’;

I was pulling a blob encoded base 64 data from mysql database and trying to render it on a page

I hope this helps someone.



To ESB or not to ESB?
April 23, 2011, 11:05 pm
Filed under: Enterprise Service Bus, Web Services

ESB stands for enterprise service bus.  It’s basically a layer that acts as a provider for many other services.  Supposedly, it’s lightweight and robust.

Upon my research for Mule (ESB candidate), I found out that it adds a medium learning curve in implementation.  Imagine mapping endpoints and services in a configuration file that will inevitably grow as more consumers are integrated into this layer.  -1 for maintenance  (It reminds me of the spring configuration file.)

Also, the binary file provides a self-contained server that runs Mule.  There are no instructions on how to integrate the mule jar file with an existing application server – tomcat, jboss, or weblogic server

As a blog writer states clearly:  It’s an architect’s dream, but a developer’s nightmare. (http://erik.doernenburg.com/2009/07/making-esb-pain-visible/)

The developer’s question that first comes to mind is:  Why?

Why should one insert a services layer in front of another framework such as struts?

Why can’t APIs be opened via different urls mapped to a servlet? How does that NOT work?

All valid questions.  But to support ESBs, here is a blog and checklist for those thinking about using a ESB:

http://blogs.mulesoft.org/to-esb-or-not-to-esb/


Struts 2 & Weblogic 7001 Listening Port Issues
April 23, 2011, 11:03 pm
Filed under: struts 2, Web Development

So if you are seeing 7001 listening port issues like me when I try to deploy my war file to Weblogic 11g, then this may as well resolve your issue.

Option 1

You need to manually place the freemarker.jar and javaassist.jar in the lib directory of your weblogic domain.

For some reason, Weblogic doesn’t pick it up from the WEB-INF/lib from your war/ear file.

Thanks to sbweitzman :  http://www.experts-exchange.com/Programming/Languages/Java/Q_26609564.html

Option 2

If you are integrated with the Eclipse environment, you may see errors such as listening ports are already used.

I tried deleting the server and re-configuring a new one.  If that doesn’t work, it might have to do with your JRE.

Click on properties of the project, go to Java Class Path.  sometimes, I see the JRE for my Mac OS is “unbounded”.

If I remove it and search for the JRE library again and re-add it back, then re-build and deploy the project…everything seems to work fine.

Hope this helps someone out there.



Struts 2: The Beginning
April 23, 2011, 10:58 pm
Filed under: struts 2, Web Development

It’s not so often that  I get to play around with new frameworks.  But since there is a project that will live as an independent system, I have decided to make the leap to Struts 2.  Yes, it’s been out there for quite a few years, but if you work in a corporate environment like I do, there isn’t an opportunity for an upgrade until … well… never.

So since I am the architect on the project, I choose to go with Struts 2. You would think downloading the full distribution would work fine:

http://struts.apache.org/download.cgi#struts2211

But learning the hard way, it doesn’t.

I copied the HelloWorld sample from:

http://code.google.com/p/struts2-examples/downloads/list

and attempted to deploy and run it in my Eclipse setup.  But then I see multiple stack trace issues.

After searching in forums for a few hours, I still didn’t find any good leads.  As a last attempt, I decided to register to the mailing list:

user@struts.apache.org

Dave Newton (I think he’s a Struts 2 master) responded that if I didn’t need any jar plugins, then I should remove them.

This doesn’t make sense to me because if I want to run a full distribution version, then it should run out-of-the-box, shouldn’t it?

Maybe it’s because i’m running Tomcat 5.5.?  Whatever the reason, I felt I wasted my time trying to debug something that doesn’t work out-of-the box.

So I went back to the downloads page and downloaded the essential dependencies bundle:

http://struts.apache.org/download.cgi#struts2211

You would think this would work, but it doesn’t.

I had to debug exception errors and stacktrace errors  by looking at various forums.  Here is the list of plugins and jars that I needed to remove from my lib directory so that I can get the Hello World application to work:

struts2-jsf-*
struts2-osgi-*
struts2-portlet-*
struts2-codebehind-*

No more stack trace issues.

But when I hit the url, that screen throws a NoMethodFound Exception on HelloWorldAction.index() error.

Back to the forums…

Someone in the mailing list recommended that I remove the:

struts2-rest-plugin-2.2.1.1.jar

This did the trick.

Finally, I see my HelloWorld app working fine.

Whew!!!

P.S. Be sure to place the struts.xml in the /WEB-INF/classes directory.  In eclipse, just put it on the top level of your src directory for eclipse deployment



Another Cool HTML 5 Site
August 30, 2010, 12:02 pm
Filed under: HTML 5

My coworker sent me this.  I think it can be played in Chrome.  But it’s pretty artistic file integrating google maps:

http://www.thewildernessdowntown.com/



The type java.lang.Enum cannot be resolved. It is indirectly referenced from required .class files
August 28, 2010, 3:11 am
Filed under: Eclipse, Java, JVM, Mac OS

Are you having these types of Eclipse-related errors???

The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Enum. Fix the build path then try building this project

The type java.lang.Enum cannot be resolved. It is indirectly referenced from required .class files    XXX.java

So this issue took me a few hours to resolve.  I’ve looked at other blogs and people say that you should check if your eclipse is pointing to the wrong JVM. e.g. 1.6 vs 1.5

But this wasn’t the cause of the issue for me.  So I work on MBP.  With the latest OS updates, the JVM directories are overridden.  This is a pain especially if you are working with legacy applications using JVM 1.5.

I tried to download a 1.5 JDK/JVM version, but that copy appears to be incomplete or corrupted.  So the best thing to do and you may not have been doing this, is to restore the java directories using time machine.  On my machine, I would go to:

/System/Library/Frameworks/JavaVM.framework/Versions/

Then enter time machine, and replace all the directories with that past version that worked.  BTW, don’t delete the A directory.  You would think it’s some junk directory, but it’s not.  It’s a required directory that some engineer did not think to name properly.

In eclipse, I went to Preferences -> Java -> Installed JREs and selected the JVM 1.5. If it’s not there, click on the Search button. This will search your system for all installed JREs.

Next, go to Project -> Properties -> Java Build Path and make sure the JVM 1.5 JRE System Library is added to the list.  If not, you should click on the Add Library button , select JRE System Library and select workspace default JRE (JVM 1.5).

This took me 3 hours to debug!!!  And it’s 3 am…



PHP, MySQL, PHPAdmin, PEAR – Manual Installation
August 21, 2010, 9:18 pm
Filed under: Apache, Mac OS, MySQL, PEAR, PHP

I got through part of the installation on my own and then I came across this blog:

http://www.klauskomenda.com/archives/2008/10/07/installing-apache-mysql-and-php-on-leopard/

PEAR is awesome.  It’s like the Java API, but it’s open source for PHP.



improving Page Download Speeds via Javascript
August 20, 2010, 11:39 am
Filed under: JavaScript, Web Performance

I was reading another blog about page performance and I thought it would be a good read for you.

This blog touches upon more improvement considerations depending on the web application:

http://encosia.com/2010/08/18/dont-let-jquerys-document-ready-slow-you-down/

The gist is that one doesn’t need to register event handlers on document load. It’s a common practice; however, it may slow down the page if the page has numerous assets.

If one registers the event handlers in the head tag section, it will speed up the page a little faster because the registration of the events is dynamic – when the element is read by the browser and inserted into the DOM, the browser registers the event handler to that element. This will speed the registration of event handlers as the page load as opposed to waiting for the page to load and then traverse the DOM to search for the elements for event handler registration.

Another point is something intuitive. If one was to make an AJAX request using JSONP, that request should also be inserted early in the page as opposed to when the document loads. This will help the page retrieve the data faster as the JSONP is a asynchronous request.

All in all, it was a good read whether it refreshes your memory or is something new.



Setting up SVN Server and Making your Server Secure
August 11, 2010, 4:53 pm
Filed under: SVN

This is really cool!!!

http://www.sonzea.com/articles/subversion-trac.html



Having problems deploying your WAR file after upgrading to Snow Leopard?
April 28, 2010, 5:18 pm
Filed under: Java, Mac OS, Tomcat, Uncategorized

Although I have upgraded a few months back, I felt compelled to re-visit the issue I faced when upgrading from Leopard to Snow Leopard.  For some odd reason, my code was throwing errors of java version incompatibilities.

It took me a while to realize that I wanted to use Java 1.5 and my environment variable was pointing to the 1.5 directory:

/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0

However, the actual java files inside this directory were overridden during the upgrade to be 1.6.0.  They were either overridden or the symbolic link created was pointing to 1.6.

I’m still trying to get a grasp why there are symbolic links in this directory and why can’t the system just reference that particular directory explicitly.

But in any case, this led to a few hours of debugging when I realized 1.5 did not exist.  So I had to reinstall JDK 1.5 from Sun (now Oracle) site.  It fixed the issue. But recently, I had to install a corporate software on my machine.  It kept on crashing and I raised a ticket to the appropriate team.

There were a lot of back and forth correspondence indicating that Snow Leopard works with 1.6 only.  This is contrary to what I have been running the last few months.  Everything works fine except for this one software install.

So I had to remove Java 1.5 so that the software can be installed correctly.  Then, I reintroduced Java 1.5 back into the system.  It really is some weird thing going on.

I was referred to this url:  http://wiki.oneswarm.org/index.php/OS_X_10.6_Snow_Leopard

The directions are very good.  The part about setting up 1.5 is odd as you have to create a few symbolic links in order to tell the OS that this directory is in fact 1.5.  It’s not intuitive at all.

In fact, if you execute:  ls -al

You see the java versions have many different symbolic links pointing to actual java versions, or CurrentJDK, or Current.  Then I found another article where it would be ideal to set your $JAVA_HOME environment var to be:  /System/Library/Frameworks/JavaVM.framework/Home

Guess what?  This is yet ANOTHER symbolic link pointing to the …/CurrentJDK/Home

I understand that this helps in changing JDK version across the whole system, but I find it difficult to discover this without research and testing.  Why was it done this way, I do not know.

Do you?




Follow

Get every new post delivered to your Inbox.