Monday, February 22, 2010

JAX-WS issues with Netbeans

I was adding a web service reference to one of my web applications when I tried to refresh and regenerate the Java classes from WSDL I received the following error:-

init:
wsimport-init:
C:\Projects\proj_name\nbproject\jaxws-build.xml:22: taskdef class com.sun.tools.ws.ant.WsImport cannot be found
BUILD FAILED (total time: 0 seconds)


If I include the library JAX-WS 2.2, I get the following error:-

wsimport-client-clean-NiceLabel:
init:
wsimport-init:
wsimport-client-NiceLabel:
Created dir: C:\Projects\proj_name\build\generated\jax-wsCache\NiceLabel
C:\Projects\proj_name\nbproject\jaxws-build.xml:31: You are running on JDK6 which comes with JAX-WS 2.1 API, but this tool requires JAX-WS 2.2 API. Use the endorsed standards override mechanism (http://java.sun.com/javase/6/docs/technotes/guides/standards/), or set xendorsed="true" on .
BUILD FAILED (total time: 0 seconds)

The way I solved it was the download an older version of JAX-WS ie 2.0. The jar files you will need are:-
1. Download jaxws-tools-2.0.jar
2. Download jaxws-rt-2.0.jar
3. Download jaxws-rt-2.0.jar
4. Download jaxb-xjc.jar

Sunday, February 21, 2010

reCAPTCHA on Rails [Installing Rails plugin on Windows]

1. Register at recaptcha.net. Add your domain and get two keys (one public, one private). I created two sites once registered, one for my development environment (localhost), and one for production.
2. Install recaptcha plugin for Rails. (GitHub).
$ ./script/plugin install git://github.com/ambethia/recaptcha.git
------------------------------------------------------------
This might be PITA for the Windows users. I wasted 3-4 hrs figuring this out. The links I used are :-
a. http://allaboutruby.wordpress.com/2009/07/20/installing-rails-on-windows-3-years-later/
b. http://rails.webintellix.com/index.php/2009/05/installing-rails-plugins-from-github-on-windows/
c. http://groups.google.ca/group/rubyonrails-talk/browse_thread/thread/0983f0dabbe3b9e7/6499ff5e9f80156a?#6499ff5e9f80156a
Check if these links work for you since they are relatively simple and worked for some users. But I always faced the issue :-
C:\Projects\rajdhani>ruby script/plugin install http://github.com/ambethia/recaptcha.git/
Plugin not found: [http://github.com/ambethia/recaptcha.git/]
Solution to installing Rails plugin on Windows
1. Install git for Windows : http://code.google.com/p/msysgit/downloads/list [All default options. Do not change any options]. You might want to restart your computer.
2. Start Git GUI->Clone repository->Source:git://github.com/ambethia/recaptcha.git->Destination: C:\<project_name>\vendor\plugins\recaptcha [needs to be a new folder]
3. Restart the Rails server
------------------------------------------------------------
3. Take the public and private reCAPTCHA keys and save to environment.rb or your environment file. I added the following to the bottom of my development.rb, replacing the ‘MY_PUBLIC_KEY’ and ‘MY_PRIVATE_KEY’ with the keys from recaptcha.net (include single quotes):

ENV['RECAPTCHA_PUBLIC_KEY'] = 'MY_PUBLIC_KEY'
ENV['RECAPTCHA_PRIVATE_KEY'] = 'MY_PRIVATE_KEY'
4. Edit views where you want the reCAPTCHA box to appear. The plugin defines a special view helper named recaptcha_tags. Here’s a basic example:
<label for="project_is_sac">Is a SAC project? </label> &nbsp;&nbsp; <%=f.check_box :is_sac><br/><br/>
    Human Test: <%= recaptcha_tags %>
  <p>
    <%= f.submit 'Create' %>
  </p>
And here’s what it that basic html looks like:
image
Each page load will embed code that pings the reCAPTCHA API and generates a new captcha. Note that there are some extra options on recaptcha_tags if you need to handle ssl or want to by default not use javascript (uses an iframe instead).
5. Add verification in the controller:


if verify_recaptcha() and @project.save
        flash[:notice] = 'Project was successfully created.'
        format.html { redirect_to(@project) }
else
        format.html { render :action => "new" }
end

The verify_recaptcha() method will take params from the POST request, ping recaptcha.net, and then return true or false. Then you can handle it however you want (here in the same block as model validation). If the captcha fails, it’ll render the new page again.
image

Monday, February 15, 2010

Revealing The Secrets – Fonts Of Famous Logos

If you ever wonder what font is used in Google or IBM or Ferrari logo you come to the right place. You’ve seen these fonts so many times and now it’s time get to know their names and their authors.

in reference to: Revealing The Secrets – Fonts Of Famous Logos | webexpedition18 (view on Google Sidewiki)

Saturday, February 13, 2010

The Problem with the Apple iPad

The iPad is a beautiful device but the real problem is, as a power user, you don't have enough control .. brilliantly put by Adam Pash

in reference to: The Problem with the Apple iPad - apple ipad - Lifehacker (view on Google Sidewiki)

Friday, February 12, 2010

What is AOP and IoC?

In a nutshell, IoC allows an external force to determine what implementation will be used by code rather than the code determining the implementation. The "external force" might be a configuration file, a unit test, other different code, etc.

AOP allows cross-cutting concerns to be implemented outside of the code affected by those concerns.

The "purpose" of Spring includes IoC and AOP, but goes quite a ways beyond that in its scope.

in reference to: What is AOP and IOC in spring? (Spring forum at JavaRanch) (view on Google Sidewiki)

Wednesday, February 10, 2010

Free PDF Printer novaPDF

novaPDF is a PDF printer driver that allows you create PDF documents from virtually any Windows program. You may use the software to convert web pages, emails, Office documents and any other file into the PDF format by simply selecting the “Print” command from the associated application.

in reference to: Free PDF Printer Driver for Digital Inspiration Readers (view on Google Sidewiki)

Sunday, February 07, 2010

Where is "session" stored? Is it in the browser or at the server?

Session itself is stored on the server side. Each browser accessing the server will get from the server unique Session ID. This Session ID browser sends to each page requested to the same server. So on client (browser) side, only Session ID is stored in the browser cookie (this is default behavior, when session cookies are enabled in the browser settings... there is also a technique called "URL rewriting" to embed SessionID as URL query parameter, each time the server is called, enabling the application to work even if browser session cookies are disabled - but, it is not so important for the basic session understanding)


So, in order that session for a browser works, the browser sends Session ID to each page being accessed on the same web site. Application server (web site server) finds the saved objects related to that Session ID in the session store (memory/disk/database...) on the server side and could work with those objects when processing the JSP page. Meaning - session objects data is stored on the server side.


The behavior you have experienced by executing "test1.jsp" after application restart is related to some other thing: The application servers (e.g. Apache Tomcat) have a possibility to persist the sessions after the server goes for restart and bring them back when the server is restarted again. The server actually serializes session objects from memory to disk (when going to restart) and deserializes them back from disk to memory afterwards (when restarting again).


If you stop the server and than start it again (not restart), those session objects will be most probably lost, and by executing "test1.jsp" in the same browser window again will give you null.

Session (Computer Science) on Wikipedia

Wednesday, February 03, 2010

Contexts And Dependency Injection in Java EE

Contexts and Dependency Injection for the Java EE Platform introduces a standard set of component management services to the Java EE platform. This Refcard will be useful for anyone interested in getting a better understanding of Contexts and Dependency Injection so that they can get the most out of the Java EE Platform.

RefCard: http://refcardz.dzone.com/refcardz/contexts-and-depencency

in reference to: Q&A with Norman Richards: Contexts And Dependency Injection in Java EE | Javalobby (view on Google Sidewiki)

Monday, February 01, 2010

Why C++ when Java!

I am capturing a part of discussion we had on JavaRanch about C++ especially C++ 2008 which is bundled with .NET Studio 2008 (upgrade 2010 version is available now)

My question to the community and author of book Murach's C++ 2008 was:-

Why would you want to go back to C++ when there are other free and equally powerful languages like Java? I work with machines and manufacturing and still I can take the performance hit of Java and make it work.
Why do people still code in C++ and esp C++ in .NET which is a commercial license? There are so many tools/plugins/IDEs/components available in other languages to get up and started with.

Some of the replies were :-

  1. It's what the individuals are used to.
  2. Language is suitable for the purpose.
  3. Too lazy
  4. Bit Handling
  5. Interfacing with lower-level protocols
  6. Device and OS drivers / management
  7. Embedded work

Now I develop in Unix C++ and Java and we have successfully implemented Bit Handling, Interfacing with lower-level protocols, device and OS drivers/management.

We are updating our repository from C++ to Java since we have better ways to handle and enhance code. We have successfully achieved the tasks listed above as well.
Also, we get more and more developers well-versed with Java as compared to their C++ skills I would love not to waste time updating our legacy code but I do not see any C++ training sessions or skills distributed around us. So maintenance is a big issue.

Henry Wong’s use case :
A few years ago, I had to make a call to .NET from java. With JNI, it was possible to get from Java to C/C++, but that isn't enough. Unmanaged C/C++ can't use .NET services in most cases. The only thing that it can do is call static methods.
So, I had two options...
1. Make another wrapper to get to Managed C++ -- meaning Java to C/C++ to managed C++.
2. Make another wrapper to get to C# -- meaning Java to C/C++ to C#.
In the end, I chose the first case. Why? My reasoning was that unmanaged C++ and managed C++ can be in the same file. There was no need to have a separate file to compile. A stronger (and probably better) reason was probably that three languages at the same time (although I do that often today) tend to get really confusing.

One big reason is not everyone has the luxury of choosing between either Java and C++. For many, it is not a choice. For many, it could even be both. You have to code based on the underlying libraries, frameworks, managerial decisions. etc.
Good programmers must work within the restrictions of the project. And in my opinion, someone that quits or refuse to join a project, because it isn't pure java, is someone that I don't want on a project. The last thing that I need is someone whose understanding of other languages is whether it is legacy or not.

This came from the author Pren:
One unique factor offered by C++ 2008 is its backward compatibility to native (unmanaged) C++ and legacy C. This offers the programmer the ability of using proven and tested code written more than 30 years ago. The world's first Hello World program illustrated in the 1978 first edition of The C Programming Language (called Hello, Earth on page 527) still runs without change, as does the same program in The C++ Programming Language (called Hello, Mars on page 529).

Language is influenced by factors like:
1. Language that all your team members are comfortable with.
2. Existing technology that the company is using.
3. Easy for developing prototypes
4. Mandatory language for the targeted platform

Don't forget the maintenance issues, although it can be seen as related with the existing technology that the company is using. You know, the main cost of every software development project resides in its maintenance, so besides the documentation, a well ordered and structured programming, etc., the availability of good programmers in a specific programming language far beyond the end of the project "development", it should also be a key for choosing the right language. Some examples regarding the difficulty in the availability of C++ programmers has been mentioned here. And concerning the easy for developing prototypes you also mentioned, yes, this could be a reason if your project and or development methodology is mainly based on prototyping.

Humans are lazy by nature and if their needs can be accomplished by one language, don't expect they learn another (there are always exceptions), thus the answer should bypass this natural human behavior and then respond that C++ may be used when Java doesn't fit well enough to our purposes, and vice versa. For instance, C++ best fits in programming embedded devices, but Java in web development.