Latest Entries »

Showing posts with label Tomcat. Show all posts
Showing posts with label Tomcat. Show all posts

Wednesday, June 10, 2009

Creating Apache Axis2 Web Services on MyEclipse IDE (eclipse) , Tomcat

To follow this tutorial, you need the following software and resources.
Software or Resource
Version Required
Download bundle
version 6 or
version 5
Apache Axis 2
Java EE-compliant web or application server
Tomcat web server 6.0

Downloading the Apache Axis2 WAR file
Apache Axis2 can be downloaded here. Download the WAR (Web Archive) distribution, so you do not have to build the WAR file yourself. The download is in the form of an archive file. Later you unpack the archive to your server.
Creating an Axis2 Web Service
With MyEclipse IDE (eclipse), you can create an Axis2 web service from a Java class. You can only do this from a Dynamic Web project. In this tutorial, create an Axis2 web service in that project (creating the Java class at the same time) and deploy the Axis2 web service to a server.
Testing an Axis2 Web Service
Goto ServiceWSSoapBindingImpl.java Class and put SOP(System.out.println("Testing Web Service");) inside your method.
Navigate to wsdl file "ServiceWS.wsdl" Right-click select Web Serives-->> Test With Web Service Explorer. Expand to method level and type input value. Click on Go, MyEclipse IDE (eclipse) will display output on console.
To create an Axis2 web service:
  1. Click the New Project icon or File -> New Project. The New Project wizard opens, select show All Wizards. From the Web category, select a Dynamic Web project. Click Next.
  2. Name the project AxisWS. Check that you are using the project folder name and location that you want. It is up to you whether to share the project.
  3. Select the Target Runtime as Tomcat, if not available in dropdown then click New button and select Tomcat 6x from New Server Runtime wizard. Provide the Tomcat installation directory path and also apecify the installed JRE. Click Finish, and the MyEclipse IDE (eclipse) creates the Target Runtime for Tomcat.
  4. Click on Next and continue with the Default options. Click Next to fill Context Root, Content Directory and Java Source Directory. Click Finish, and the MyEclipse IDE (eclipse) creates the Dynamic Web Project.
  5. Right-click the src node. The context menu opens. In the context menu, choose New -> Class. The New Java Class opens. Provide the package name and java class name. Click Finish, and the MyEclipse IDE (eclipse) creates the Java Class under the provided package name.
  6. Create a method with the qualified name and provide the parameters as per the requirement. Here I'm creating a method call getRequestParamFromWS() with the method signature String and the arguments as a String parameter "value".
  7. Double check the Axis, as mentioned earler it should be deployed on Tomcat which we have configured while creating the Dynamic Web Project.

  8.  
  9. Right-click on the Java Class, goto Web Services option and select Create Web Service. The Create Web Service will open a New wizard with more options. Web Service type should be "Bottom up Java bean Web Service" Service Implementation "com.sravan.ServiceWS Client type "Java Proxy" click on Next. The next screen display's the wsdl file name and the methods available under the Java Class.
  10. Select the appropriate method and Click Next. If your Tomcat server is not running, the MyEclipse IDE (eclipse) will prompt for Start server. Click for Start server, MyEclipse IDE (eclipse) will start your Tomcat server. Click Finish to complete the WSDL file creation process.
  11. Navigate to wsdl file location. Project-->> WebContent-->>wsdl-->>ServiceWS.wsdl. Right-click on wsdl file and goto Web Service option, select Generate Java Bean Skeleton option.
  12. Web Service wizard will open, Web Service type should be "Top down Java Bean Web Service", Service definitation /AxisWS/WebContent/wsdl/ServiceWS.wsdl Client type "Java Proxy". Click Next to choose skeleton folder. Click Next will lead to the auto generated code. Click Finish to complete the process.
  13. Similarly you can generate the Web Service Client code as well, by choosing the Generate Client option displayed under Web Service Java Bean Skeleton option.

  14.  
  15. Web Service is completed, you can Add Web Capabilities for this project. While adding the Web capabilities to your peoject choose Web Content folder, or you can name it as a Web Root while creating the Dynamic Project.
  16. Create an ANT file build.xml to deploy your web application on Tomcat, after deployment type http://yourip:port/AxisWS/services/AxisWS your browser will show a message like "Hi there, this is an AXIS service!".

Sunday, May 24, 2009

How To Set Java Heap Size In Tomcat

Stop Tomcat server, set environment variable CATALINA_OPTS, and then restart Tomcat.

set CATALINA_OPTS="-Xms512m -Xmx512m" (Windows)
export CATALINA_OPTS="-Xms512m -Xmx512m" (ksh/bash)
setenv CATALINA_OPTS "-Xms512m -Xmx512m" (tcsh/csh)









In catalina.bat or catallina.sh, you may have noticed CATALINA_OPTS, JAVA_OPTS, or both can be used to specify Tomcat JVM options. What is the difference between CATALINA_OPTS and JAVA_OPTS? The name CATALINA_OPTS is specific for Tomcat servlet container, whereas JAVA_OPTS may be used by other java applications (e.g., JBoss). Since environment variables are shared by all applications, we don't want Tomcat to inadvertently pick up the JVM options intended for other apps. I prefer to use CATALINA_OPTS.

Tuesday, April 28, 2009

javax.naming.NameNotFoundException: Name java:comp is not bound in this Context


To resolve this exception, need to cross check context.xml, web.xml and jar files.

Creation of context.xml in your META-INF auto generates the xml file with the project name in TOMCAT/conf/ ( C:\Program Files\Apache Software Foundation\apache-tomcat-6.0.18\conf\Catalina\localhost ) cross check this file.

compare context.xml and web.xml with the reference files posted in my previous posting.









No need to create an entry in TOMCAT context.xml and server.xml files.

Finally you need to check your lib folders, both tomcat and project lib.

If you have the following jar's in your lib folder, then remove those

a) naming-common.jar
b) naming-factory.jar
c) naming-resources.jar

clean and rebuild your project and then deploy it, before starting tomcat delete xml file from C:\Program Files\Apache Software Foundation\apache-tomcat-6.0.18\conf\Catalina\localhost

Stack Trace:

javax.naming.NameNotFoundException: Name java:comp is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:765)
at org.apache.naming.NamingContext.lookup(NamingContext.java:147)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at com.sravan.As400Connection.getConnection(As400Connection.java:47)
at com.sravan.GetValuesFromDB.getViolationCodeQM(GetValuesFromDB.java:1054)
at com.sravan.InsertintoDB.insertFromIntofiles(InsertintoDB.java:746)
at com.parseWEB.Services.ProjectNameSoapBindingImpl.getRequest(ProjectNameSoapBindingImpl.java:545)
at com.parseWEB.Services.ProjectNameSoapBindingSkeleton.getRequest(ProjectNameSoapBindingSkeleton.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)
at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)
at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)

Stack Trace of TOMCAT:

May 31, 2009 10:01:39 AM org.apache.tomcat.util.modeler.Registry registerComponent
SEVERE: Null component Catalina:type=DataSource,path=/ProjectName,host=localhost,class=javax.sql.DataSource,name="jdbc/DataSourceAS400"
May 31, 2009 10:01:39 AM org.apache.tomcat.util.modeler.Registry registerComponent
SEVERE: Null component Catalina:type=DataSource,path=/ProjectName,host=localhost,class=javax.sql.DataSource,name="jdbc/DataSource"

Thursday, March 5, 2009

Apache Tomcat 6.0 JNDI Datasource

Configuration of JNDI

1. Create context.xml file in META-INF folder.











2. Create an entry for resource-ref in web.xml.











3. Make sure that the following JAR's added in your TOMCAT/lib
( C:\Program Files\Apache Software Foundation\apache-tomcat-6.0.18\lib )
a. commons-collections-3.2.jar
b. commons-dbcp-1.2.2.jar
c. commons-pool-1.4.jar




















Note: for mysql add mysql-connector-java-5.1.5-bin.jar in TOMCAT/lib and for as400 add jt400.jar etc...









Java Code:
/*===========================================================================+
| Copyright (c) 2009 Sravan Modugula, |
| All rights reserved. |
+===========================================================================+
| HISTORY
| Created By : Sravan Modugula
| Date : 12-10-2008
| Description: class represents As400Connection
|
+===========================================================================*/

package com.sravan.modugula.as400database;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

import org.apache.log4j.Logger;

public class As400Connection {

/**
* logger instance
*/
private static final Logger log = Logger.getLogger(As400Connection.class);

public static Connection getConnection() {
log.info(" Starting establish as400 connection");

Connection as400Connection = null;
try {
Context ctx = new InitialContext();
DataSource dataSource = (DataSource) ctx
.lookup("java:comp/env/jdbc/databaseAS400");
if (dataSource != null) {
as400Connection = dataSource.getConnection();
return as400Connection;
}
} catch (Exception e) {
e.printStackTrace();
log.fatal("Got Exception when getting as400 connection");
log.fatal("Exception is ", e);
}
// log.info(" ConnectionPtest Ending"+System.currentTimeMillis()/1000);
return as400Connection;
}

public static void closeConnection(Connection as400Connection) {
try {
if (as400Connection != null) {
as400Connection.close();
as400Connection = null;
}
} catch (SQLException e) {
log.error(e.getMessage(), e);
} finally {
if (as400Connection != null)
try {
as400Connection.close();
log.info("Closed connection");
} catch (SQLException e) {
log.error(e.getMessage(), e);
}
}
}

}