Posts

Showing posts from 2012

RESTful WebService Tutorial

Representational State Transfer  ( REST ) is a style of  software architecture  for  distributed  systems such as the  World Wide Web . REST has emerged as a predominant  Web service  design model. We will be building a REST application using Apache tomcat , Jersey , Eclipse . Below is the code for making a dummy application for Restful WebService using Jersey. To begin with first set up all the jars required for the application.  Click the below link to download all the jars. https://sites.google.com/site/balonideepak/lib.zip?attredirects=0&d=1 After that  create a client for making a hit to the app. Create a class like JerseyGetClient.java and paste the below code inside it : import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.WebResource.Builder; public class JerseyGetClient { public static void main(String arg[]

JDBC versus ODBC and other APIs

At this point, Microsoft's ODBC (Open DataBase Connectivity) API is probably the most widely used programming interface for accessing relational databases. It offers the ability to connect to almost all databases on almost all platforms. So why not just use ODBC from Java? The answer is that you  can  use ODBC from Java, but this is best done with the help of JDBC in the form of the JDBC-ODBC Bridge, which we will cover shortly. The question now becomes, "Why do you need JDBC?" There are several answers to this question: ODBC is not appropriate for direct use from Java because it uses a C interface. Calls from Java to native C code have a number of drawbacks in the security, implementation, robustness, and automatic portability of applications. A literal translation of the ODBC C API into a Java API would not be desirable. For example, Java has no pointers, and ODBC makes copious use of them, including the notoriously error-prone generic pointer "void *"

Thin & OCI Drivers

Oracle provides two main types of drivers. The OCI driver. The OCI (type 2) driver consists of java wrappers to the low-level Oracle Call Interface (OCI) libraries used by utilities like SQL*Plus to access the database server. The OCI driver offers potentially better performance that the thin driver. It however requires the OCI libraries to be installed on the local machine. The "thin" driver. Also referred to as type 4 driver, the thin driver is a pure Java implementation of Oracle's networking protocol (Net8). Being self-contained, it may be used on any machine with--or without Oracle installed--or even distributed with application classes in an applet.

ClientAbortException java.net.SocketException Broken Pipe

Symptoms: The following error appears in the logs: WARNING : Exception Processing ErrorPage[errorCode=500, location=/500page.jsp] ClientAbortException: java.net.SocketException: Broken pipe   WARNING : Exception Processing ErrorPage[errorCode=404, location=/fourohfour.action] ClientAbortException: java.net.SocketException: Broken pipe Cause: The warning log basically means that the connection to the client browser is  aborted before the response is fully transferred. It is a harmless warning as  it can be due to transient network problems or the browser aborts/refreshes the  page before it loaded.

java.lang.UnsupportedClassVersionError: Bad version number in .class file? (Eclipse)

Image
Before hitting the solution let's get to know why this error occurs in java.So when JVM tries to load a class   and found that class version is not supported it throws  UnSupportedClassVersionError   and it generally  occurs if a higher JDK version is used to compile the source file and a lower JDK version is used to run the program. For example: if you have written your program using Java 1.6 and compiled also and now you run that program in 1.5 you will get the error   "java.lang.UnsupportedClassVersionError: Bad version number in .class file  [at java.lang.ClassLoader.defineClass1(Native Method)]". So now we come to how to resolve this issue in Eclipse. Right click on the project in Eclipse and click on Properties menu.After that click on Java Compiler menu. In right hand side uncheck use compliance check box and from the drop-down menu click the version you need .For me i have to select 1.6.After that click ok and clean your project.If again problem comes then o

Firefox search bar plugin

Image
Hi Guys, We can do a little fun with Firefox search bar .We can create our own search engine there. Here i am creating a simple example of how you can create your own plugin. Go to the installed directory of Firefox and locate the folder "searchplugins" .Open this folder ,here you will see all the search engines xml listed there. You can copy paste the below code and restart Firefox to see your search engine in the drop down of search bar list. <SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/"> <ShortName>MySearch</ShortName> <Description>Demo search by google.. < /Description> <InputEncoding>UTF-8 < /InputEncoding> <Url type="text/html" method="GET" template="https://www.google.com/search"> <Param name="q" value="{searchTerms}"/> </Url> <SearchForm > https://www.google.com/ < /SearchForm> </SearchPlugin> an

Ant build file to compile and clean resources

Hi, Below is a example for showing how to compile ,clean and make jar file of a project. Here i have given just a brief introduction of the tags how to use them. Advance build file structure i will include in coming post. Example: <?xml version="1.0"?> <project name="classroom" basedir="."> <property name="projectname" value="classroom" /> <property name="srcprop.dir" value="conf" /> <property name="build.dir" value="./compiled" /> <property name="src.dir" value="src"> </property> <target name="usage"> <echo message="------------" /> <echo message="Building ${projectname} project..." /> </target> <!--Create  directory --> <target name="init"> <mkdir dir="${build.dir}" /> <echo message="Compiled Dir

Running all targets in ant through command prompt

Suppose you have an ant script build.xml to build the project which contains multiple targets inside it.If you are running the script through eclipse then you can enable or disable the targets by right clicking on build.xml and click on  " Run As " and in the popup window opened check or uncheck the targets. But how to do the same thing in command prompt. I have one little solution that worked for me. Suppose your build.xml contains some target like this :    <target name="init">   <tstamp>   <mkdir dir="${build}">   </mkdir></tstamp></target>   <target depends="init" description="compile the source " name="compile">   <javac destdir="${build}" srcdir="${src}">   </javac></target>   <target depends="compile" description="generate the distribution" name="dist"  >   <mkdir dir="${dist}/lib"  &g

Difference between Apache Server and Apache Tomcat

Apache is an HTTP server and Tomcat is a container . So Apache server can serve the  requests which are static in nature while Tomcat can serve the request which are dynamic. So if the pages are served in JSP/SERVLET then we have to use Tomcat container to interpret them. Similarly, if you will be using PHP then you need to add its support in Webserver. Webserver is used to just respond to the requests with feature such as load balancing, whereas containers( such as Tomcat) are used to manage the lifecycle of the pages generated using  JSP  and servlet.

Calling a URL with the help of HttpClient

Hi , You can call your jsp pages through HTTPClient .For that you just have to have commons-httpclient-*.jar. Any version of this jar will work. For the below code i was having commons-httpclient-3.1.jar. You can try the following lines to call your jsp page.. URL url = new URL("http://localhost/mywebapp/test.jsp")); HttpClient client = new HttpClient(); GetMethod get = new GetMethod(url.toString()); client.executeMethod(get); Other way is to make some timeout settings in Connection.For that you have to modify some connection properties like this: URL url = new URL("http://localhost/mywebapp/test.jsp"); HostConfiguration hcfg = new HostConfiguration(); hcfg.setHost(url.getHost(), url.getPort()); SimpleHttpConnectionManager connectionManager = new SimpleHttpConnectionManager(); HttpConnection connection = connectionManager.getConnection(hcfg); HttpConnectionParams conparams = connection.getParams(); conparams.setSoTimeout(timeout); conparams.setConnectionTime

org.xml.sax. SAXParseException: Element type "web-app" must be declared.

Sometime you will notice these kinds of error messsges while deploying your web application to Tomcat.  org.apache.commons.digester.Digester - Parse Error at line 22 column 18: Element type "web-app" must be declared. org.xml.sax.SAXParseException: Element type "web-app" must be declared. at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1213) at org.apache.xerces.validators.common.XMLValidator.reportRecoverableXMLError(XMLValidator.java:1807) at org.apache.xerces.validators.common.XMLValidator.validateElementAndAttributes(XMLValidator.java:3633) at org.apache.xerces.validators.common.XMLValidator.callStartElement(XMLValidator.java:1229) at org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumentScanner.java:1806) at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:949) at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381) at org

Getting back the dropped table back in ORACLE

You can get back the dropped table in ORACLE . To do so checkout FLASHBACK command. Here is a example below : First of all create a table.I am creating  a table with name First_Table. " CREATE  table First_Table(name varchar(20),id varchar(10)) " Then DROP the table using DROP command like this: DROP table First_Table And here comes the magic command to get back the dropped table: FLASHBACK TABLE  First_Table TO BEFORE DROP ;

Project facet Java 6.0 is not supported by target runtime JBoss

This problem will come due to a mismatch over the JDK version defined in the Project Facet for that particular project and the version ,the runtime server is having. This thing worked for me  . I am having Eclipse Helios and JDK 1.5 installed .Right click on the project in Eclipse ,click the properties menu, click the Project Facets.After clicking you will see in right side some listing will come and among them one entry will be for java.So click on the java property and you will be see a drop-down box .Change the version accordingly.I have changed it to 1.5 and it worked for me. Clean the project. Hope the solution works for you.....

WAP (Wireless Application Protocol)

Wireless Application Protocol  ( WAP ) is a  technical standard  for accessing information over a mobile  wireless network .U sers can  access information instantly via  handheld wireless devices  such as mobile phones, pagers, two-way radios, smartphone and communicators.  WAP supports most wireless networks. These include CDPD, CDMA, GSM, PDC, PHS, TDMA, FLEX, ReFLEX, iDEN, TETRA, DECT, DataTAC, and Mobitex. The WAP Architecture:   Any WAP enable system consists of : a) WAP Gateway b) the HTTP Web Server c) the WAP Device Birth of  WAP :  The Wireless Application Protocol (WAP) is a result of joint efforts taken by companies teaming up in an industry group called WAP Forum. On June 26 1997 Ericsson, Motorola, Nokia, and Unwired Planet took the initiative to start a rapid creation of a standard for making advanced services within the wireless domain a reality. In December 1997 WAP Forum was formally created, and after the release of the WAP 1.0 specifications i

Unable to start Eclipse — can't open \Java\jre6\lib\i386\jvm.cfg

Uninstall your current running jre version and install higher one. I was using jre1.6 when i had this problem so i have uninstalled it and installed 1.7 it and the problem was solved.