Pages

Showing posts with label Struts 2. Show all posts
Showing posts with label Struts 2. Show all posts

Thursday, August 14, 2014

error c00c0240 - "Could not complete the operation due to error c00c0240." - AJAX request in Struts

I happened to encounter this error when I was attempting to debug an Ajax call to a Struts action. It made me feel miserable for a while as both firebug as well as eclipse debuggers with console showed no trace of the origins of the error. As usual I searched out for the error number and ended up with a lot of stack overflow posts. One of these posts were typically explaining me the same issue that I was facing and had a link to a blog post which contained a solution to the same. And to my relief, my companies network restrictions prevented that page from being loaded. Wait WTF!!! Yes... that’s how grateful I felt roflJ.

 

Enough of my story, the issue in my case was that the AJAX request that I framed and tested was

 

var x= new XMLHttpRequest();x.open("GET","http://localhost:7001/****/*************Action.do",false);x.send(null);x.responseText

 

This was giving me some un relevant message like the following and my debugging points never worked and neither the eclipse console had any logs printed in them through the log4j framework.

 

"
<html>
<head>
  <script type="text/javascript" src="/****/js/*****.js"></script>
   <script type="text/JavaScript">
           window.document.onkeydown=checkKeyCode;
   </script>
</head>
<body>
<table  width="100%" valign="top" height="100%">
<tr>
<td align="center"><font color="red"><h4>
There was a problem, please try again!</h4></font>
</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
</tr>
</table>
</body>
</html>"

 

And I found the “THE ISSAC NEWTON” in me like most of the times, as something stuck me and I tried “POST” instead of “GET”

 

And now, I see some positive results. My debugging points in the eclipse is working.. Hurray!!!!!

 

var x= new XMLHttpRequest();x.open("POST","http://localhost:7001/****/*************Action.do",false);x.send(null);x.responseText

 

Hurray!!!!! Again. But wait, WTF its just that my debugging points in eclipse are working. So wait my work is not done yet

 

L J

 

Thursday, May 8, 2014

Code change in eclipse not reflecting in IE - HttpWatch

Issue - "Code not reflecting properly on the browser - weblogic server"
 or  "Latest code not reflecting on the browser - weblogic server"
Clear Stage and temporary

Possible fix
----------------


1. If "Http watch" is installed in your machine, start you app on IE and press "Shift+F2" to start it. Go to tools menu and clear cache

2. Try clearing the browser cache in traditional methods Ctrl+shift+delete and clear cookies and temp files

3. Check the "AutoDeploy" directory and remove any existing war files corresponding to your application
In my case the AutoDeploy directory was in "D:\Oracle\Middleware\user_projects\domains\base_domain\autodeploy"

4. On the web logic server locate the following path. (relative to the oracle directory)
D:\Oracle\Middleware\user_projects\domains\base_domain\servers\AdminServer

 It contains the "stage" and "tmp" folders

Delete the contents inside the folder

5. Delete the Meta folder of your project in eclipse
In my case it was
D:\WorkSpace\iCADMay14\.metadata

For some reason this did not recreate it self so i created a new folder named ".metadata" in its place

6. Stopped the weblogic server and deleted the server cache in the following location
ORACLE_HOME/user_projects/domains/your_domain/servers/your_server/cache (optional)

In my case it was,
D:\Oracle\Middleware\user_projects\domains\base_domain\servers\AdminServer\cache

7. Take a look at the url on the browser and make sure it points to your project

In my case the url of the app on the browser said
http://server:port/appName/jsp/myJsp.jsp

 

So I had to make the changes in my property files
in my case it was present at "D:\PropFiles\icad.properties"

I went in and changed the line that said "APP_URL=****" as "APP_URL =http://hostname:7001/appName" and it worked

Now I face new environment related issues. At least its better that to be stuck like a fool in a place that didn't belong to be :)

 

 

Properties in Build.xml

Following is a part of the build config file of my app

  <property name="app.name"      value="ApplicationName"/>  <!-- rename to suit your project name-->
  <property name="app.version"   value="1.0"/>
  <property name="build.home"    value="build"/>
  <property name="catalina.home" value="D:\Oracle\Middleware\wlserver_12.1"/> <!-- UPDATE THIS! -->
  <property name="deploy.home"   value="D:\Oracle\Middleware\wlserver_12.1\${app.name}"/>
  <property name="dist.home"     value="D:\Oracle\Middleware\user_projects\domains\base_domain\autodeploy"/>
  <property name="src.home"      value="src"/>
  <property name="struts.home"   value="./web/WEB-INF/lib"/>

the property that says "property name="dist.home"  needs to be mapped to the auto deploy directory of you domain.

Unless this is done, the application cannot be opened on the browser as the weblogic server wont have any

handle/reference to the war files deployed any were else apart form the autodeploy directory


On the contrary if you are using a JBoss server, your auto deploy directory configuration can be some thing like

thie following

<!-- ===================== Property Definitions =========================== -->

<!--

  Each of the following properties are used in the build script.
  Values for these properties are set by the first place they are 
  defined, from the following list:
  * Definitions on the "ant" command line (ant -Dcatalina.home=xyz compile)
  * Definitions from a "build.properties" file in the top level
    source directory
  * Definitions from a "build.properties" file in the developer's
    home directory
  * Default definitions in this build.xml file

  You will note below that property values can be composed based on the
  contents of previously defined properties.  This is a powerful technique
  that helps you minimize the number of changes required when your development
  environment is modified.  Note that property composition is allowed within
  "build.properties" files as well as in the "build.xml" script.

-->

  <property file="build.properties"/>
  <property file="${user.home}/build.properties"/>


<!-- ==================== File and Directory Names ======================== -->

<!--

  These properties generally define file and directory names (or paths) that
  affect where the build process stores its outputs.

  app.name             Base name of this application, used to
                       construct filenames and directories.
                       Defaults to "myapp".

  app.version          Version identifier for this application.

  build.home           The directory into which the "prepare" and
                       "compile" targets will generate their output.
                       Defaults to "build".

  catalina.home        The directory in which you have installed
                       a binary distribution of Tomcat 4.  This will
                       be used by the "deploy" target.

  deploy.home          The name of the directory into which the
                       deployment hierarchy will be created, and into
                       which the build directory will be copied.
                       Defaults to "${catalina.home}/webapps/${app.name}".

  dist.home            The name of the base directory in which
                       distribution files are created.
                       Defaults to "dist".

-->

   <property name="app.name"      value="ApplicationName"/>  <!-- rename to suit your project name-->
   <property name="app.version"   value="1.0"/>
   <property name="build.home"    value="build"/>
   <property name="catalina.home" value="D:\jboss-4.2.2.GA\jboss-4.2.2.GA\jboss-4.2.2.GA"/> <!-- UPDATE

THIS! -->
   <property name="deploy.home"   value="D:\Oracle\Middleware\user_projects\domains\base_domain

\autodeploy\${app.name}"/>
   <property name="dist.home"     value="D:\Oracle\Middleware\user_projects\domains\base_domain

\autodeploy"/>
   <property name="src.home"      value="src"/>
   <property name="struts.home"   value="./web/WEB-INF/lib"/>

 

 

Wednesday, November 9, 2011

Interceptors with Struts 2


Well another mile stone to me and learning all by yourself is such a pain. Now I understand the interceptors better. After all I was having a lot of issues with them

An interceptor as the name signifies gets triggered when an action is invoked provided the action is associated with the interceptor

 First of all following is my action class

import com.opensymphony.xwork2.ActionSupport;

public class TestLoggerAction extends ActionSupport{

       public String execute()    {
      
              System.out.println("new Inside Action");
              return SUCCESS;
             
       }
}


Following is a my interceptor class. I have imported Action support class here as well in order to overrule the return value of the action. You would understand the same when you uncomment a specific code indicated in the following block of code

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class MyLoggingInterceptor extends ActionSupport implements Interceptor  {

       private static final long serialVersionUID = 1L;


       public String intercept(ActionInvocation invocation) throws Exception {
      
             
              System.out.println("Finishing execution stack for action //TestLogger");

                     //----------  Un comment this line and you will see the result of the prevention of action
                     //----------  from being executed

                     //if(true) return ERROR;  


                     //----------------------------------------------------------------------------------

              String result = invocation.invoke();
              // Post processing
      
              System.out.println("Finishing execution stack for action //TestLogger");
              return result;
       }

          //called during interceptor destruction
              public void destroy() {
                     System.out.println("CustomInterceptor2 destroy() is called...");
              }
        
              //called during interceptor initialization
              public void init() {
                     System.out.println("CustomInterceptor2 init() is called...");
              }

}

Finally my struts file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
       <package name="default" extends="struts-default">

              <interceptors>
                     <interceptor name="logger"
                           class="MyLoggingInterceptor">
                     </interceptor>

                     <interceptor-stack name="loggingStack">
                           <interceptor-ref name="logger" />
                           <interceptor-ref name="defaultStack" />
                     </interceptor-stack>

              </interceptors>

              <action name="TestLogger" class=" TestLoggerAction">
                     <interceptor-ref name="loggingStack" />
                     <result name="error">/InterceptorFailure.jsp</result>
                     <result name="success">/InterceptorSuccess.jsp</result>
              </action>

       </package>
</struts>
             
Be very very precise with the characters you type in. Case sensitivity is hell lot of issue for me. L

You will get the following page if you un comment the block of code I have indicated in the interceptor class



And the following line page if you proceed as such



And your console would contain the following info


Hope this helps  :)

Working with s:bean in Struts 2 - Beware Begineers


Well well... this simple silly stuff gave me a head ache for a while. Because I broke the rules and so paid the price.
I was wondering why s:bean won’t work for me while I was able to work with other stuffs like controls, context params, stream processing, Ajax etc….
My Eclipse IDE kept telling that it was not able to recognize what s:bean is. Neither did it realize s:param and s:property.

I was puzzled. Even a few java guys felt that it was a problem with the IDE. How demoralizing. I stopped toying with it for a while and later after a couple of days, I found the culprit.

It was so simple. I got a bit comfortable with basic JSPs and Struts that I did not notice this.

The following was my jsp page’s content

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Bean Tag Example</title>
</head>
<body>
<s:bean name="currencyConverter">
 <s:param name="dollars" value="100" />
 100 Dollars = <s:property value="rupees" /> Rupees
</s:bean>

</body>
</html>

And the issue was I did not add the following code to the top of that page

<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

God bless me…. I just want to cry now. How could I ever forget to miss it … bummer

Hope this saves some one else at least :)

Thursday, November 3, 2011

Configuring Struts.xml for Interceptors

Well learning curve is quite breath taking with java technologies. I got curious about the interceptors feature in Struts 2 and eventually I ended up trying to sample them out for my reference and understanding. I am not yet successful on it, but at least I have had some progress on the same.


The first wall I had to jump over was that whenever I added the interceptors tag in struts.xml, I was having a heap of issues and my page/ project wont load up on the browser.


I searched through out the innernet and all spoke about how to use them and what tags to add and I was so puzzeled that I followed them exactly as per my understanding and it wouldn’t work.


Gosh…. I found the culprit at last. It was the way in which these  tags needs to be ordered in the xml file.


The interceptors tag needs to be present on top of all other action tags. So much to my observation !!!!!  It was always there and yet it took me an hour to find it. L So much to experience with the RAD technology I am associated with, for the past 4 yrs… I never had to think about these silly stuffs


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
             
       <package name="default" extends="struts-default">
             
             
              <interceptors>
                     <interceptor name="logger" class="interceptor.MyLoggingInterceptor">
                     </interceptor>
                     <interceptor-stack name="loggingStack">
                           <interceptor-ref name="logger" />
                           <interceptor-ref name="defaultStack" />
                     </interceptor-stack>
                    
              </interceptors>           
             
              <!-- <constant name="struts.devMode" value="true" /> -->
             
              <action name….>
                     <result ….">/index.jsp</result>
              </action>

              <action name….>
                     <result ….>
                           ……
                     </result>
              </action>

              <action name="TestLogger" class="TestLoggerAction">
                     <interceptor-ref name="loggingStack" />
                     <result name="success">/InterceptorSuccess.jsp</result>
              </action>
             
       </package>   
</struts>
             
       Hope this xml interpretation gives you an idea of how to configure em…

Hope this helps some one J
      

Tuesday, November 1, 2011

Ajax in Strut 2 using XmlHTTPRequest


Ajax with Struts 2, I think I have had a good start with Struts 2. I was just toying around with what was provided in vaannila. It’s a real good stuff and in no time I got this idea of trying AJAX with Struts 2.


It took me some time though to understand how stuffs work with Struts.


Following is the fragment of struts.xml file that did the trick for me at last


            <action name="AjaxTest"  class="AjaxTest">
                     <result type="stream">
                           <param name="contentType">text/html</param>
                           <param name="inputName">inputStream</param>
                     </result>
              </action>


The class I Used to output the response is as follows


import java.io.InputStream;
import java.io.StringBufferInputStream;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("deprecation")
public class AjaxTest extends ActionSupport  {
    private InputStream inputStream;
    public InputStream getInputStream() {
        return inputStream;
    }

    public String execute() throws Exception {
        inputStream = new StringBufferInputStream("Hello World! This is a text string response from a Struts 2 Action.");
        return SUCCESS;
    }
}


The javascript I used to perform the AjaxRequest is as follows
function triggerAjaxForExperiment()      {
       xmlHttp=new AjaxProcess("http://localhost:8080/myNewHelloWorld/AjaxTest.action",false);
       //initiate and asynchronous request to check whether the current reporthas any open chid documents
       xmlHttp.initiate();

       //this results in a boolean object isChildActive which is either true or false
       alert(xmlHttp.getHtmlFilteredResponseText())
}

About the AjaxProcess function that I have used here, it is a custom API I have created and can be found in the following location

And to your jsp file add the following line of html code to perform the test

       <input type="button" value="Ajax Experiment" onclick="triggerAjaxForExperiment()"/>

In the end what I got was as follows

It feels good to me J

Hope this helps you as well J