Skip to content

Commit

Permalink
Fix Ajax submits when deploying as servlet; Add ERXServletApplication…
Browse files Browse the repository at this point in the history
… class
  • Loading branch information
johnthuss committed Jul 7, 2014
1 parent 1027548 commit ad6a032
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package er.extensions.appserver;

import javax.servlet.ServletContext;

import com.webobjects.appserver.WORequest;
import com.webobjects.appserver.WOResponse;

/**
* <p>If you are deploying in a servlet container like Tomcat, this application class
* allows you automatically serve static resources from the "static" directory using
* the static resource servlet that is built into Tomcat and Jetty.
* <p>
* When building you need to copy the static resources into the "static" folder by
* adding some lines to the end of the "ssdd" target in build.xml:
* <ul>
* <li>1) Change the WOAppMode to Deployment</li>
* <li>2) Copy "WebServerResources/" to "/static/YourApp.woa/Contents/WebServerResources/" directly inside the root of the .war file</li>
* <li>3) Copy "*.Framework/WebServerResources/" to "/static/Frameworks/*.Framework/WebServerResources/"</li>
* </ul>
*
* @see <a href="http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/servlets/DefaultServlet.html">Tomcat 7.0 DefaultServlet Docs</a>
*
* @author john
*
*/
public class ERXServletApplication extends ERXApplication {

private boolean didSetBaseUrl = false;

@Override
public WOResponse dispatchRequest(WORequest request) {
if (!didSetBaseUrl) {
didSetBaseUrl = true;
ServletContext servletContext = (ServletContext) request.userInfo().get("ServletContext");
if (servletContext != null) {
setApplicationBaseURL(servletContext.getContextPath() + "/static/"); // "static" is the built-in static resource servlet for Tomcat and Jetty

This comment has been minimized.

Copy link
@paulhoadley

paulhoadley Aug 13, 2014

Contributor

John, Eclipse is flagging this line (and the next) as errors for me, claiming ServletContext.getContextPath() is undefined. I'm using Java 6. Should this compile under Java 6?

This comment has been minimized.

Copy link
@johnthuss

johnthuss via email Aug 13, 2014

Author Member
setFrameworksBaseURL(servletContext.getContextPath() + "/static/Frameworks/");
}
}

return super.dispatchRequest(request);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import com.webobjects.appserver.WORequest;
import com.webobjects.foundation.NSMutableDictionary;
import com.webobjects.jspservlet.WOServletContext;

import er.extensions.appserver.ajax.ERXAjaxServletContext;
import er.extensions.foundation.ERXMutableUserInfoHolderInterface;

/**
* Replacement of WOServletContext.
* This subclass is installed when the frameworks loads.
*/
public class ERXWOServletContext extends WOServletContext implements ERXMutableUserInfoHolderInterface {
public class ERXWOServletContext extends ERXAjaxServletContext implements ERXMutableUserInfoHolderInterface {
public ERXWOServletContext(WORequest worequest) {
super(worequest);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public boolean wasFormSubmitted() {
return _wasFormSubmitted();
}

/*
* NOTE: ERXAjaxServletContext is a direct copy of this class. Keep it in sync with this.
*/
@Override
@Deprecated
public boolean _wasFormSubmitted() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// ERXAjaxContext.java
// Project armehaut
//
// Created by ak on Mon Apr 01 2002
//
package er.extensions.appserver.ajax;

import com.webobjects.appserver.WOContext;
import com.webobjects.appserver.WORequest;
import com.webobjects.jspservlet.WOServletContext;

/**
* <span class="en">
* ERXAjaxContext provides the overrides necessary methods for partial form
* submits to work. If you want to use the Ajax framework without using other
* parts of Project Wonder (i.e. ERXSession or ERXApplication), you should steal
* all of the code in ERXAjaxSession, ERXAjaxApplication, and ERXAjaxContext.
* </span>
*
* <span class="ja">
* ERXAjaxContext は部分的なフォーム・サブミットの機能を提供します。
* </span>
*
* @author mschrag
*/
public class ERXAjaxServletContext extends WOServletContext {

public ERXAjaxServletContext(WORequest request) {
super(request);
}

/*
* NOTE: This class was copied directly from ERXAjaxContext. Keep it in sync with that.
*/
@Override
public boolean wasFormSubmitted() {
boolean wasFormSubmitted = super.wasFormSubmitted();
if (wasFormSubmitted) {
WORequest request = request();
String partialSubmitSenderID = ERXAjaxApplication.partialFormSenderID(request);
if (partialSubmitSenderID != null) {
// TODO When explicitly setting the "name" binding on an input,
// the following will fail in the takeValuesFromRequest phase.
String elementID = elementID();
if (!partialSubmitSenderID.equals(elementID)
&& !partialSubmitSenderID.startsWith(elementID + ",")
&& !partialSubmitSenderID.endsWith("," + elementID)
&& !partialSubmitSenderID.contains("," + elementID + ",")) {
String ajaxSubmitButtonID = ERXAjaxApplication.ajaxSubmitButtonName(request);
if (ajaxSubmitButtonID == null || !ajaxSubmitButtonID.equals(elementID)) {
wasFormSubmitted = false;
}
}
}
}
return wasFormSubmitted;
}

}
1 change: 1 addition & 0 deletions Frameworks/Core/ERJars/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
<classpathentry exported="true" kind="lib" path="Libraries/httpclient-cache-4.3.1.jar"/>
<classpathentry exported="true" kind="lib" path="Libraries/httpcore-4.3.jar"/>
<classpathentry exported="true" kind="lib" path="Libraries/httpmime-4.3.1.jar"/>
<classpathentry exported="true" kind="lib" path="Libraries/servlet-api-3.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Binary file not shown.

9 comments on commit ad6a032

@ishimoto
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Here the same error. Have comment it out for now.

@hprange
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is the JavaXML library from WebObjects. It has an old version of the Servlet API. I'm fixing this problem for the Maven build by removing the dependency to JavaXML. I'm not sure, however, how to solve it in the Ant build. Can you force the ERJars library before the JavaXML library in the classpath order?

@ishimoto
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERJars is first, JavaXML is last.

@paulhoadley
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERJars is already on top:

$ cat Frameworks/Core/ERExtensions/.classpath
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="Sources"/>
    <classpathentry exported="true" kind="con" path="WOFramework/ERJars"/>
    <classpathentry exported="true" kind="con" path="WOFramework/JavaWOExtensions"/>
    <classpathentry exported="true" kind="con" path="WOFramework/JavaEOAccess"/>
    <classpathentry exported="true" kind="con" path="WOFramework/JavaEOControl"/>
    <classpathentry exported="true" kind="con" path="WOFramework/JavaEOProject"/>
    <classpathentry exported="true" kind="con" path="WOFramework/JavaJDBCAdaptor"/>
    <classpathentry exported="true" kind="con" path="WOFramework/JavaWebObjects"/>
    <classpathentry exported="true" kind="con" path="WOFramework/JavaWOJSPServlet"/>
    <classpathentry exported="true" kind="con" path="WOFramework/JavaXML"/>
    <classpathentry exported="true" kind="con" path="WOFramework/JavaWebServicesSupport"/>
    <classpathentry exported="true" kind="con" path="WOFramework/JavaFoundation"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

I've tried a clean John, it doesn't fix it. Are you saying that you don't see the errors flagged by Eclipse?

@johnthuss
Copy link
Member Author

@johnthuss johnthuss commented on ad6a032 Aug 14, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paulhoadley
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I knew you wouldn't commit them if you did. I meant what is the relevant difference with our environments? I am using Java 6.

@johnthuss
Copy link
Member Author

@johnthuss johnthuss commented on ad6a032 Aug 15, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paulhoadley
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have the ERJars project open in Eclipse?

No, I didn't. And that's the fix. Thanks John.

@pascalrobert
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Wonder 7.

Please sign in to comment.