I'm trying out Java coming over from .NET and want to make a simple page that does the following:
Implements RESTful API
Connects to a MySQL Database
Implements Role-based Security
I tried out Eclipse but wasn't met with much success, plus the code completion was very slow compared to VS2017. So I'm trying out IntelliJ Community. I've built a Maven project, but my URL is not running, also it looks like I'm not getting any code completion in my .java files. It did not build the app directories automatically.
My POM:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.johnnytest.webapp</groupId>
<artifactId>jerseyexample</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>jerseyexample Maven Webapp</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>snapshot-repository.java.net</id>
<name>Java.net Snapshot Repository for Maven</name>
<url>https://maven.java.net/content/repositories/snapshots/</url>
<layout>default</layout>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.26</version>
</dependency>
</dependencies>
<build>
<finalName>jerseyexample</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/</url>
<!--<username>joe</username>-->
<!--<password>joe</password>-->
</configuration>
</plugin>
</plugins>
</build>
</project>
My web.xml:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.johnnytest.app</param-value>
<load-on-startup>1</load-on-startup>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
My Java file:
package com.johnnytest.app;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
#Path("/test")
public class MainApp {
#GET
#Path("/{param}")
public Response getMessage(#PathParam("param") String message) {
String output = "Jersey says " + message;
return Response.status(200).entity(output).build();
}
}
Also it's running Tomcat 7, and I've installed 9 on my system. Is there any way to get it to run on my existing Tomcat install? When I go to any URL on localhost:8080 I just get a blank page in Safari. Running on OSX Sierra.
Launch at Command line
if you didn't do it already, download Apache Maven 3.5.0 and add the /bin directory to the system PATH variable.
Enter the directory where the pom.xml file is and run the following:
mvn clean package
mvn tomcat7:deploy
mvn tomcat7:start
The first command will build the code and produce a Java WAR archive in the subdirectory target/.
The second command will deploy the WAR archive to Tomcat application server.
The third command will start Tomcat and expose the server as per configuration (localhost:8080).
Don't worry about the command tomcat7, even if you're using Tomcat 9 it should be fine.
Launch within IntellJ
Maven management in IntelliJ is not really optimal, but on the right side you should see a Maven Projects pane (if you don't, select "Tools -> View tool buttons" menu). Click and expand.
Under Lifecycle you will find the standard Maven goals, so double clicking on clean and then package will produce the WAR file in a similar manner as explained in the previous section.
Under Plugins you will find the Maven goals ruled by the Tomcat plugin. Expand and double click tomcat7:deploy and tomcat7:start.
A quick parallel with ASP.NET
If you come from .NET, just think of Tomcat as the Java version of IISExpress that comes bundled with VisualStudio. It is a application server where you deploy the application code and which emulates a webserver service for development.
There are many parallels and also many discrepancies. In general, an application lifecycle in .NET is much more contained, you rarely need anything else beyond VisualStudio and MSBuild, I think. In Java, many things have been created and evolved through the decades thanks to the community: we have different build systems (Maven, Ant, Gradle), the best tooling is command line and there are multiple ways to achieve the same goal.
For example, you are using the Jersey REST library with an underlying app server below (Tomcat), but you could also deploy to a NIO server (Grizzly). If you use extended frameworks like Spring, you generally don't even worry about these things because switching from one way to the other is just a matter of importing a module in your pom.xml instead of another.
Hope this helped you and gave you some directions.
Related
I'm aware that there are plenty of similar questions on StackOverflow, but I guess I went through each of them and tried all the suggested ones, but none of them worked.
I am trying to migrate an application from struts 1 to struts 2, but for makes things easier I'm trying first to migrate the struts1 sample applications in order to get confident with the steps. The sample applications I'm talking about are the ones in the apps folder of this repository.
So, this is my current configuration:
maven
Java 8
Tomcat 9
Struts 1.4
Struts 2.5
The steps that I've done so far have been:
Add struts2-core and log4j2 dependencies in the pom.xml file, and install them through maven
Change the web.xml file to include struts 2, according to official documentation.
Create a struts.xml file in the classpath, currently that file doesn't contain any action but just the structure.
The above-mentioned files look like this:
web.xml (excerpt):
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
<constant name="struts.devMode" value="true"/>
<package name="default" namespace="/" extends="struts-default">
</package>
<!-- Add addition packages and configuration here. -->
</struts>
pom.xml (excerpt):
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.5.22</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.12.1</version>
</dependency>
In the end, the maven dependencies section looks like this:
While the WEB-INF/lib folder in the target folder looks like this:
So I'm sure that all the required dependencies are present in the target. Despite this, I keep getting the error:
org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter [struts2]
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
I'm sure that the class org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter exists, it's spelled correctly and it's correct for the version of struts2 that I'm using, since if I import the class in a Java file, it gets built succesfully.
I know that the problem is very common and my request can sound stupid, but I've checked literally any question that I found on the web about this problem and none of the solutions worked.
I hope that someone could give me a hint. Thank you
Your pom.xml entry for the Struts 2 lib:
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.5.22</version>
<scope>compile</scope>
</dependency>
If you're running via Maven (which you should) you'll need it beyond compile time.
I would leave dependency management up to Maven and not try to do it manually, even if the WEB-INF/lib image has been truncated (it's missing at least the XWork dependency).
Trying to deploy simple servlet to Tomcat server. After select Run Tomcat... I'm redirected to http://localhost:8080/hi_war_exploded/ with webpage with one word - $END$. Logfiles reports no error.
I was expecting to see hw folder with my application in tc9\webapps, but found nothing.
What does the $END$ means? Where is my application on TomCat server? How to put my servlet to TomCat server?
Servlet:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
// Extend HttpServlet class
public class hw extends HttpServlet {
private String message;
public void init() throws ServletException {
// Do required initialization
message = "Hello World";
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Set response content type
response.setContentType("text/html");
// Actual logic goes here.
PrintWriter out = response.getWriter();
out.println("<h1>" + message + "</h1>");
}
public void destroy() {
// do nothing.
}
}
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<servlet>
<servlet-name>hw</servlet-name>
<servlet-class>hw</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hw</servlet-name>
<url-pattern>/hw</url-pattern>
</servlet-mapping>
</web-app>
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Hello</groupId>
<artifactId>hw</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
IntelliJ IDEA doesn't copy the webapp files into TOMCAT\webapps.
It modifies Tomcat configuration in CATALINA_BASE and deploys the artifact directly from its output directory to avoid copying the files which can take a lot of extra time, especially for the large projects.
hi_war_exploded is the context configured in Tomcat Run/Debug configuration, Deployment tab.
In the root of this context you have the default index.jsp page generated by IntelliJ IDEA on project creation.
When you open http://localhost:8080/hi_war_exploded/ URL, Tomcat serves index.jsp from the Web Resource root of your application.
$END$ is a part of the the new JSP file template. When you create a new JSP file in a project, cursor is placed at this location.
When the project wizard generates the Web Application project and places index.jsp file from the template, it doesn't expand the $END$ macro, so it appears in the JSP file. It's actually a known bug in IntelliJ IDEA.
Your servlet is available at http://localhost:8080/hi_war_exploded/hw URL.
To make it available at http://localhost:8080/hw URL instead you need to change the Application context to / as shown on this screenshot:
I deployed keycloak in tomcat with eclipse Luna based on this tutorial: https://reachmnadeem.wordpress.com/2015/01/14/deploying-keycloak-in-tomcat/#comment-245
I have it running in my machine and have no problem. Now I have to edit the login form based on my company design. But I do not have local files .css and .htmls to do it.
This is the parent project and some war configuration.
<parent>
<artifactId>keycloak-parent</artifactId>
<groupId>org.keycloak</groupId>
<version>1.1.0.Final</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>keycloak-war</artifactId>
<packaging>war</packaging>
<name>Keycloak Server</name>
<description />
Do I have to donwload the war project, the parent project? I do not know where to start.
First of all please be informed that it is recommended to use standalone Keycloak server - http://keycloak.github.io/docs/userguide/keycloak-server/html/server-installation.html)
And here some details how you are able to customize themes - http://docs.jboss.org/keycloak/docs/1.0-alpha-3/userguide/html/themes.html
You can unzip the keycloak-forms-common-themes-1.1.0.Beta2.jar and under login you can change the css and images and redeploy it
This is my first foray into using JMS. I have a successfully created/deployed a war file that contains a servlet that I can use to upload files. When a file is uploaded it sends a message to a JMS queue. Next I wrote a listener to retrieve the uploaded messages from the queue, but when I try to deploy it, I get this error:
SEVERE: Invalid ejb jar [file-listener-ejb-1.0.jar]: it contains zero ejb.
Note:
1. A valid ejb jar requires at least one session, entity (1.x/2.x style), or message- driven bean.
2. EJB3+ entity beans (#Entity) are POJOs and please package them as library jar.
3. If the jar file contains valid EJBs which are annotated with EJB component level annotations (#Stateless, #Stateful, #MessageDriven, #Singleton), please check server.log to see whether the annotations were processed properly.
at com.sun.enterprise.deployment.util.EjbBundleValidator.accept(EjbBundleValidator.java:76)
...<snip>...
It's a very simple project with one class, built using Maven. The class looks like this:
package my.package;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
#MessageDriven(mappedName = "jms/FileUploadedQueue", activationConfig = {
#ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
#ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue") })
public class FileListener implements MessageListener
{
private static Logger log = LoggerFactory.getLogger(FileListener.class);
public FileListener()
{
// empty constructor
}
public void onMessage(Message message)
{
try
{
log.info("Received message: " + ((TextMessage)message).getText());
}
catch (JMSException ex)
{
String error = "Received error code '"
+ ex.getErrorCode()
+ "' retrieving message from queue jms/FileUploadedQueue.";
Exception linkedEx = ex.getLinkedException();
if (linkedEx != null)
{
log.error(error += "Linked exception: ", linkedEx);
}
else
{
log.error(error, linkedEx);
}
}
}
}
My pom.xml looks like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.package</groupId>
<artifactId>uploaded-file-listener</artifactId>
<version>1.0</version>
<packaging>ejb</packaging>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
<version>1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<bootclasspath>${settings.localRepository}/javax/javaee-endorsed-api/6.0/javaee-endorsed-api-6.0.jar${path.separator}${sun.boot.class.path}</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
This builds a jar file which when I try to deploy to my Glassfish 3.1 server (via the admin console) results in the above error.
Since I have the #MessageDriven annotation on my class, I'm not sure what I'm doing wrong. Unfortunately, the server.log file does not contain any more details about the error.
Should I be packaging the jar in an ear and deploying that?
----------EDIT----------
I created an ear which includes the ejb jar, and I get the same error when I deploy the ear to Glassfish. So, I think it must be something to do with the annotation. However, I've looked at multiple examples/tutorials and I can't see what's wrong.
Any insights/suggestions would be most welcome!!
----------EDIT TWO----------
Contents of MANIFEST.MF files:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: <name>
Build-Jdk: 1.6.0_24
Contents of application.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC
"-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
"http://java.sun.com/dtd/application_1_3.dtd">
<application>
<display-name>FileListener-ear</display-name>
<module>
<ejb>file-listener-ejb-1.0.jar</ejb>
</module>
</application>
----------EDIT THREE----------
Contents of ejb-jar file:
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
version="3.1">
<display-name>FileListener</display-name>
<enterprise-beans>
<message-driven>
<ejb-name>FileListener</ejb-name>
<ejb-class>my.package.FileListener</ejb-class>
<transaction-type>Container</transaction-type>
</message-driven>
</enterprise-beans>
</ejb-jar>
Does your jar file contain an ejb-jar.xml file? If it was missing, then it could explain why the whole thing explodes upon deploy
Deploying on GF 4.1 our EAR that consists of an EJB and WAR and several JAR projects suddenly needs an application.xml.
Many deploys before it was not necessary.
Did you try to check the compatibility check box while deployment and see if deploys fine. We also got such error preventing the deployment and was resolved by checking the compatibility check box while deployment.
I need to get WADL file for RESTful service. I know that in case using jersey it's available as http://localhost:8080/application.wadl. But I use RESTeasy.
Can I do the same in my framework case?
Latest versions:
Quoting Chapter 49. RESTEasy WADL Support:
Chapter 49. RESTEasy WADL Support
49.1. RESTEasy WADL Support for Servlet Container
49.2. RESTEasy WADL support for Sun JDK HTTP Server
49.3. RESTEasy WADL support for Netty Container
49.4. RESTEasy WADL Support for Undertow Container
RESTEasy has its own support to generate WADL for its resources, and it supports several different containers. The following text will show you how to use this feature in different containers.
49.1. RESTEasy WADL Support for Servlet Container
RESTEasy WADL uses ResteasyWadlServlet to support servlet container. It can be registered into web.xml to enable WADL feature. Here is an example to show the usages of ResteasyWadlServlet in web.xml:
<servlet>
<servlet-name>RESTEasy WADL</servlet-name>
<servlet-class>org.jboss.resteasy.wadl.ResteasyWadlServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RESTEasy WADL</servlet-name>
<url-pattern>/application.xml</url-pattern>
</servlet-mapping>
The preceding configuration in web.xml shows how to enable
ResteasyWadlServlet and mapped it to /application.xml. And then the
WADL can be accessed from the configured URL:
/application.xml
Workaround for Older versions
There is a workaround: a maven plugin called maven-wadl-plugin by the jersey folks that also works to generate WADL for services coded using RESTEasy.
Here's how to use it.
1. Add this to your pom.xml:
<build>
<plugins>
<plugin>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>maven-wadl-plugin</artifactId>
<version>1.17</version>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
<phase>${javadoc-phase}</phase>
</execution>
</executions>
<configuration>
<wadlFile>${project.build.outputDirectory}/application.wadl
</wadlFile>
<formatWadlFile>true</formatWadlFile>
<baseUri>http://example.com:8080/rest</baseUri>
<packagesResourceConfig>
<param>com.example.rs.resource</param>
</packagesResourceConfig>
<wadlGenerators>
<wadlGeneratorDescription>
<className>com.sun.jersey.server.wadl.generators.WadlGeneratorApplicationDoc
</className>
<properties>
<property>
<name>applicationDocsFile</name>
<value>${basedir}/src/main/doc/application-doc.xml</value>
</property>
</properties>
</wadlGeneratorDescription>
<wadlGeneratorDescription>
<className>com.sun.jersey.server.wadl.generators.WadlGeneratorGrammarsSupport
</className>
<properties>
<property>
<name>grammarsFile</name>
<value>${basedir}/src/main/doc/application-grammars.xml</value>
</property>
</properties>
</wadlGeneratorDescription>
</wadlGenerators>
</configuration>
</plugin>
</plugins>
</build>
Pay attention to the baseUri and packagesResourceConfig elements. You have to change them to reflect your project's configuration. You may also want to change the plugin's version (I used 1.17).
2. Create a /doc folder and add some files.
Create the src/main/doc/ folder and create the two files below.
File: application-doc.xml
Content:
<?xml version="1.0" encoding="UTF-8"?>
<applicationDocs targetNamespace="http://wadl.dev.java.net/2009/02">
<doc xml:lang="en" title="A message in the WADL">This is added to the start of the generated application.wadl</doc>
</applicationDocs>
File: application-grammars.xml
Content:
<?xml version="1.0" encoding="UTF-8" ?>
<grammars xmlns="http://wadl.dev.java.net/2009/02" />
3. Run the maven command.
Go to the project folder and run the following command:
$ mvn compile com.sun.jersey.contribs:maven-wadl-plugin:generate
The files \target\classes\application.wadl (the WADL itself) and \target\classes\xsd0.xsd (the schema of the resources - it's used by the application.wadl) should be generated.
Edit and use them as you wish.
PS.: Bear in mind that this is a very simple use of the maven-wadl-plugin. It can do a lot more. To know it better, please refer to the zip file in http://search.maven.org/remotecontent?filepath=com/sun/jersey/samples/generate-wadl/1.12/generate-wadl-1.12-project.zip
WADL generation in RESTeasy is a feature not yet implemented. If you want it go vote for it.
https://issues.jboss.org/browse/RESTEASY-166
See RESTEasy WADL Support (3.1.0). The snipped below is copied from there
<servlet>
<servlet-name>RESTEasy WADL</servlet-name>
<servlet-class>org.jboss.resteasy.wadl.ResteasyWadlServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RESTEasy WADL</servlet-name>
<url-pattern>/application.xml</url-pattern>
</servlet-mapping>
This uses the ResteasyWadlServlet and will make the WADL accessible at /application.xml.
Note:
Rex and Jaskirat have already mentioned previously that RESTEASY-166 was used to manage the implementation for this feature. It seems this was completed in 3.0.14.
we can generate a wadl with the help of maven project with POM.XML
https://issues.jboss.org/browse/RESTEASY-166 check the comments here..!!