Skip to content

Commit

Permalink
use ERXResponse and ERXHttpStatusCodes instead of WOResponse and plai…
Browse files Browse the repository at this point in the history
…n ints
  • Loading branch information
darkv committed Nov 9, 2012
1 parent b21dadd commit e9302a0
Show file tree
Hide file tree
Showing 25 changed files with 96 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import com.webobjects.monitor._private.MObject;
import com.webobjects.monitor._private.MSiteConfig;

import er.extensions.appserver.ERXHttpStatusCodes;
import er.extensions.appserver.ERXResponse;

/**
* <p>
* The following direct actions were added to Monitor. They might be useful for
Expand Down Expand Up @@ -336,8 +339,7 @@ protected AdminApplicationsPage applicationsPage() {
}

public WOActionResults infoAction() {
WOResponse woresponse = new WOResponse();
woresponse.setStatus(200);
ERXResponse woresponse = new ERXResponse();
String result = "";
for (Enumeration enumeration = instances.objectEnumerator(); enumeration.hasMoreElements();) {
MInstance minstance = (MInstance) enumeration.nextElement();
Expand Down Expand Up @@ -378,9 +380,7 @@ public WOActionResults infoAction() {
}

public WOActionResults runningAction() {
WOResponse woresponse = new WOResponse();
woresponse.setContent("YES");
woresponse.setStatus(200);
ERXResponse woresponse = new ERXResponse("YES");
String num = (String) context().request().formValueForKey("num");
int numberOfInstancesRequested = -1;
if (num != null && !num.equals("") && !num.equalsIgnoreCase("all")) {
Expand All @@ -402,30 +402,26 @@ public WOActionResults runningAction() {
}
if ((numberOfInstancesRequested == -1 && instancesAlive < instances.count()) || instancesAlive < numberOfInstancesRequested) {
woresponse.setContent("NO");
woresponse.setStatus(417);
woresponse.setStatus(ERXHttpStatusCodes.EXPECTATION_FAILED);
}
return woresponse;
}

public WOActionResults stoppedAction() {
WOResponse woresponse = new WOResponse();
woresponse.setContent("YES");
woresponse.setStatus(200);
ERXResponse woresponse = new ERXResponse("YES");
for (Enumeration enumeration = instances.objectEnumerator(); enumeration.hasMoreElements();) {
MInstance minstance = (MInstance) enumeration.nextElement();
if (minstance.state == MObject.DEAD)
continue;
woresponse.setContent("NO");
woresponse.setStatus(417);
woresponse.setStatus(ERXHttpStatusCodes.EXPECTATION_FAILED);
break;
}
return woresponse;
}

public WOActionResults bounceAction() {
WOResponse woresponse = new WOResponse();
woresponse.setContent("OK");
woresponse.setStatus(200);
ERXResponse woresponse = new ERXResponse("OK");
String bouncetype = (String) context().request().formValueForKey("bouncetype");
String maxwaitString = (String) context().request().formValueForKey("maxwait");
if (bouncetype == null || bouncetype == "" || bouncetype.equalsIgnoreCase("graceful")) {
Expand All @@ -444,7 +440,7 @@ public WOActionResults bounceAction() {
applicationsPage().bounceRolling(applications);
} else {
woresponse.setContent("Unknown bouncetype");
woresponse.setStatus(406);
woresponse.setStatus(ERXHttpStatusCodes.NOT_ACCEPTABLE);
}
return woresponse;
}
Expand Down Expand Up @@ -611,26 +607,25 @@ private MSiteConfig siteConfig() {
}

public WOActionResults performActionNamed(String s) {
WOResponse woresponse = new WOResponse();
WOResponse woresponse = new ERXResponse();
if (!siteConfig().isPasswordRequired() || siteConfig().compareStringWithPassword(context().request().stringFormValueForKey("pw"))) {
try {
WOActionResults woactionresults = performMonitorActionNamed(s);
if (woactionresults != null && (woactionresults instanceof WOResponse)) {
woresponse = (WOResponse) woactionresults;
} else {
woresponse.setContent("OK");
woresponse.setStatus(200);
}
} catch (DirectActionException directactionexception) {
woresponse.setStatus(directactionexception.status);
woresponse.setContent(s + " action failed: " + directactionexception.getMessage());
} catch (Exception throwable) {
woresponse.setStatus(500);
woresponse.setStatus(ERXHttpStatusCodes.INTERNAL_ERROR);
woresponse.setContent(s + " action failed: " + throwable.getMessage() + ". See Monitor's log for a stack trace.");
throwable.printStackTrace();
}
} else {
woresponse.setStatus(403);
woresponse.setStatus(ERXHttpStatusCodes.STATUS_FORBIDDEN);
woresponse.setContent("Monitor is password protected - password missing or incorrect.");
}
return woresponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import com.webobjects.monitor._private.MSiteConfig;
import com.webobjects.monitor.application.WOTaskdHandler.ErrorCollector;

import er.extensions.appserver.ERXResponse;

public class DirectAction extends WODirectAction {

public DirectAction(WORequest aRequest) {
Expand Down Expand Up @@ -97,7 +99,7 @@ private NSDictionary historyEntry(MApplication app) {
}

public WOResponse statisticsAction() {
WOResponse response = new WOResponse();
ERXResponse response = new ERXResponse();
String pw = context().request().stringFormValueForKey("pw");
if(siteConfig().compareStringWithPassword(pw)) {
WOTaskdHandler handler = new WOTaskdHandler(new ErrorCollector() {
Expand Down
5 changes: 2 additions & 3 deletions Examples/Ajax/AjaxExample/Sources/PushExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import er.ajax.AjaxPushRequestHandler;
import er.ajax.AjaxUtils;
import er.extensions.appserver.ERXResponse;

public class PushExample extends WOComponent {

Expand Down Expand Up @@ -70,8 +71,6 @@ public WOActionResults push() {
System.out.println("PushExample.push: starting " + session().sessionID());
_pushSessionIDs.add(session().sessionID());
}
WOResponse response = new WOResponse();
response.setContent("Sent some data");
return response;
return new ERXResponse("Sent some data");
}
}
3 changes: 2 additions & 1 deletion Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxRemoteLogging.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.webobjects.foundation.NSDictionary;

import er.extensions.appserver.ERXDirectAction;
import er.extensions.appserver.ERXResponse;

/**
* Allows you to log <code>window.console</code> JS messages from the browser to
Expand Down Expand Up @@ -107,7 +108,7 @@ else if ("info".equalsIgnoreCase(level)) {
else if ("debug".equalsIgnoreCase(level)) {
log.debug(msg);
}
return new WOResponse();
return new ERXResponse();
}
}

Expand Down
11 changes: 7 additions & 4 deletions Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxSessionPing.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.webobjects.appserver.*;
import com.webobjects.foundation.*;

import er.extensions.appserver.ERXHttpStatusCodes;
import er.extensions.appserver.ERXResponse;

/**
* Simple component to ping the session in the background. It can do two things. The first is
* to execute JavaScript if the session is no longer valid. The default action is to close the window
Expand Down Expand Up @@ -99,12 +102,12 @@ public Action(WORequest request) {
* @return bare HTTP response with status set
*/
public WOActionResults pingSessionAction() {
WOResponse response = new WOResponse();
boolean hasValidSession = existingSession() != null;
if (hasValidSession) {
ERXResponse response = new ERXResponse();
if (existingSession() != null) {
session();
} else {
response.setStatus(ERXHttpStatusCodes.MULTIPLE_CHOICES); // CHECKME is that really the appropriate status code?
}
response.setStatus(hasValidSession ? 200 : 300);
return response;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.webobjects.appserver.WOActionResults;
import com.webobjects.appserver.WOContext;
import com.webobjects.appserver.WOResponse;
import com.webobjects.directtoweb.D2WComponent;

import er.attachment.model.ERAttachment;
import er.extensions.appserver.ERXResponse;

/**
* D2W component for editing toMany ERAttachments
Expand Down Expand Up @@ -42,6 +42,6 @@ public String onComplete() {
// actions
public WOActionResults removeAttachment() {
object().removeObjectFromBothSidesOfRelationshipWithKey(attachment, propertyKey());
return new WOResponse();
return new ERXResponse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.webobjects.appserver.WOApplication;
import com.webobjects.appserver.WOContext;
import com.webobjects.appserver.WORequest;
import com.webobjects.appserver.WOResponse;
import com.webobjects.eocontrol.EOEditingContext;
import com.webobjects.foundation.NSArray;
import com.webobjects.foundation.NSData;
Expand All @@ -21,6 +20,8 @@
import er.attachment.model.ERAttachment;
import er.attachment.model.ERDatabaseAttachment;
import er.attachment.processors.ERAttachmentProcessor;
import er.extensions.appserver.ERXHttpStatusCodes;
import er.extensions.appserver.ERXResponse;
import er.extensions.appserver.ERXWOContext;
import er.extensions.components.ERXNonSynchronizingComponent;
import er.extensions.eof.ERXQ;
Expand Down Expand Up @@ -108,11 +109,7 @@ public WOActionResults invokeAction(WORequest request, WOContext context) {
} else if (invokeAction) {
invokeAction = false;
willAccept = true;
WOResponse response = new WOResponse();
//CHECKME 406 or 415?
response.setStatus(400);
response.setContent(localizer().localizedStringForKey("UnacceptableMimetype"));
return response;
return new ERXResponse(localizer().localizedStringForKey("UnacceptableMimetype"), ERXHttpStatusCodes.BAD_REQUEST); // CHECKME 406 or 415?
}
return super.invokeAction(request, context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.webobjects.appserver.WOActionResults;
import com.webobjects.appserver.WOComponent;
import com.webobjects.appserver.WORequest;
import com.webobjects.appserver.WOResponse;
import com.webobjects.directtoweb.D2W;
import com.webobjects.directtoweb.D2WContext;
import com.webobjects.directtoweb.D2WPage;
Expand Down Expand Up @@ -52,6 +51,8 @@
import er.directtoweb.pages.ERD2WQueryPage;
import er.extensions.appserver.ERXApplication;
import er.extensions.appserver.ERXDirectAction;
import er.extensions.appserver.ERXHttpStatusCodes;
import er.extensions.appserver.ERXResponse;
import er.extensions.eof.ERXEC;
import er.extensions.eof.ERXEOAccessUtilities;
import er.extensions.eof.ERXEOControlUtilities;
Expand Down Expand Up @@ -444,10 +445,7 @@ protected boolean allowPageConfiguration(String pageConfiguration) {
* Returns a response with a 401 (access denied) message. Override this for something more user friendly.
*/
public WOActionResults forbiddenAction() {
WOResponse response = new WOResponse();
response.setStatus(401);
response.setContent("Access denied");
return response;
return new ERXResponse("Access denied", ERXHttpStatusCodes.UNAUTHORIZED);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import com.webobjects.appserver.WOComponent;
import com.webobjects.appserver.WOContext;
import com.webobjects.appserver.WOResponse;
import com.webobjects.appserver.WOSession;
import com.webobjects.directtoweb.ConfirmPageInterface;
import com.webobjects.directtoweb.D2W;
Expand All @@ -18,6 +17,7 @@
import com.webobjects.eocontrol.EOEditingContext;
import com.webobjects.foundation.NSArray;

import er.extensions.appserver.ERXResponse;
import er.extensions.appserver.ERXSession;
import er.extensions.appserver.ERXWOContext;
import er.extensions.eof.ERXEC;
Expand Down Expand Up @@ -82,7 +82,7 @@ public void createPages() {
} else {
log.info("Unsupported: " + pageName + " -> " + page.name());
}
page.appendToResponse(new WOResponse(), context);
page.appendToResponse(new ERXResponse(), context);
} finally {
ec.unlock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ public WOResponse handleRequest(final WORequest request) {
if (url == null) {
return createErrorResponse(request);
}
response = new WOResponse();
response.setStatus(302);
response = new ERXResponse(ERXHttpStatusCodes.FOUND);
response.setHeader(url, "location");
// refresh entry, so it doesn't time out
_urls.setObjectForKey(url, id);
Expand Down Expand Up @@ -392,7 +391,7 @@ protected String cssUrl(WORequest request) {
* @param url
*/
protected WOResponse createRefreshResponse(WORequest request, String url) {
WOResponse result = new WOResponse();
ERXResponse result = new ERXResponse();
result.setHeader(refresh() + "; url=" + url + "\"", "refresh");
// ak: create a simple template
result.appendContentString("<html>\n<head>\n<meta http-equiv=\"refresh\" content=\"" + refresh() + "; url=" + url + "\">\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.webobjects.appserver._private.WOHTMLDynamicElement;
import com.webobjects.foundation.NSDictionary;

import er.extensions.appserver.ERXResponse;

/**
* IFRAME that can use its own contents to render when none of the other
* bindings are supplied. Makes page-writing a lot easier as you don't need an
Expand Down Expand Up @@ -51,7 +53,7 @@ public WOActionResults invokeAction(WORequest request, WOContext context) {
else if (_action != null) {
return (WOActionResults) _action.valueInComponent(component);
} else {
WOResponse response = new WOResponse();
ERXResponse response = new ERXResponse();
//AK: we might want to be able to set this...
response.appendContentString("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
response.appendContentString("<html><body style='border:0; margin: 0; padding: 0; width:100%; height: 100%'>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.webobjects.foundation.NSData;
import com.webobjects.foundation.NSForwardException;

import er.extensions.appserver.ERXResponse;
import er.extensions.foundation.ERXFileUtilities;
import er.extensions.foundation.ERXSimpleTemplateParser;

Expand Down Expand Up @@ -168,7 +169,7 @@ public InputSource resolveEntity(String arg0, String arg1) throws SAXException,
public void appendToResponse(WOResponse response, WOContext context) {
start = System.currentTimeMillis(); current = start;
if (isEnabled()) {
WOResponse newResponse = new WOResponse();
ERXResponse newResponse = new ERXResponse();
newResponse.setContentEncoding(response.contentEncoding());

super.appendToResponse(newResponse, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.webobjects.foundation.NSTimeZone;
import com.webobjects.foundation.NSTimestampFormatter;

import er.extensions.appserver.ERXResponse;
import er.extensions.appserver.ERXSession;
import er.extensions.formatters.ERXNumberFormatter;
import er.extensions.formatters.ERXTimestampFormatter;
Expand Down Expand Up @@ -265,7 +266,7 @@ public String toString() {
* Overridden to make output XML compatible.
*/
public void appendToResponse(WOResponse woresponse, WOContext wocontext) {
WOResponse newResponse = ERXPatcher.DynamicElementsPatches.cleanupXHTML ? new WOResponse() : woresponse;
WOResponse newResponse = ERXPatcher.DynamicElementsPatches.cleanupXHTML ? new ERXResponse() : woresponse;
super.appendToResponse(newResponse, wocontext);

ERXPatcher.DynamicElementsPatches.processResponse(this, newResponse, wocontext, 0, nameInContext(wocontext, wocontext.component()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.webobjects.appserver._private.WOInput;
import com.webobjects.foundation.NSDictionary;

import er.extensions.appserver.ERXResponse;
import er.extensions.foundation.ERXKeyValueCodingUtilities;
import er.extensions.foundation.ERXPatcher;

Expand Down Expand Up @@ -104,7 +105,7 @@ public void takeValuesFromRequest(WORequest worequest, WOContext wocontext) {
*/
@Override
public void appendToResponse(WOResponse woresponse, WOContext wocontext) {
WOResponse newResponse = ERXPatcher.DynamicElementsPatches.cleanupXHTML ? new WOResponse() : woresponse;
WOResponse newResponse = ERXPatcher.DynamicElementsPatches.cleanupXHTML ? new ERXResponse() : woresponse;
super.appendToResponse(newResponse, wocontext);

ERXPatcher.DynamicElementsPatches.processResponse(this, newResponse, wocontext, 0, nameInContext(wocontext, wocontext.component()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import er.extensions.appserver.ERXApplication;
import er.extensions.appserver.ERXResourceManager;
import er.extensions.appserver.ERXResponse;
import er.extensions.appserver.ERXResponseRewriter;
import er.extensions.foundation.ERXExpiringCache;
import er.extensions.foundation.ERXProperties;
Expand Down Expand Up @@ -161,7 +162,7 @@ else if (ERXResourceManager._shouldGenerateCompleteResourceURL(wocontext)) {
boolean render = cache.isStale(key);
render |= ERXApplication.isDevelopmentModeSafe();
if(render) {
WOResponse newresponse = new WOResponse();
WOResponse newresponse = new ERXResponse();
super.appendChildrenToResponse(newresponse, wocontext);
newresponse.setHeader("application/x-javascript", "content-type");
cache.setObjectForKey(newresponse, key);
Expand Down
Loading

0 comments on commit e9302a0

Please sign in to comment.