* GSWeb.framework/GSWActionRequestHandler.m:

o -_handleRequest: partially rewritten for exception handling


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@18892 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
mguesdon 2004-03-25 08:27:29 +00:00
parent 6ccff85df6
commit 32ed97413d

View file

@ -304,10 +304,18 @@ RCS_ID("$Id$")
LOGObjectFnStop(); LOGObjectFnStop();
}; };
//--------------------------------------------------------------------
-(GSWAction*)getActionInstanceOfClass:(Class)actionClass -(GSWAction*)getActionInstanceOfClass:(Class)actionClass
withRequest:(GSWRequest*)aRequest withRequest:(GSWRequest*)aRequest
{ {
GSWAction* action=(GSWAction*)[[actionClass alloc]initWithRequest:aRequest]; GSWAction* action=nil;
LOGObjectFnStart();
action = (GSWAction*)[[actionClass alloc]initWithRequest:aRequest];
LOGObjectFnStop();
return action; return action;
} }
@ -324,6 +332,7 @@ RCS_ID("$Id$")
NSString* actionName=nil; NSString* actionName=nil;
NSString* actionClassName=nil; NSString* actionClassName=nil;
GSWContext* context=nil; GSWContext* context=nil;
GSWAction* action=nil;
LOGObjectFnStart(); LOGObjectFnStart();
application=[GSWApplication application]; application=[GSWApplication application];
@ -333,6 +342,8 @@ RCS_ID("$Id$")
if (_shouldAddToStatistics) if (_shouldAddToStatistics)
[self registerWillHandleActionRequest]; [self registerWillHandleActionRequest];
[application awake];
requestHandlerPathArray=[self getRequestHandlerPathForRequest:aRequest]; requestHandlerPathArray=[self getRequestHandlerPathForRequest:aRequest];
NSDebugMLLog(@"requests",@"requestHandlerPathArray=%@", NSDebugMLLog(@"requests",@"requestHandlerPathArray=%@",
requestHandlerPathArray); requestHandlerPathArray);
@ -354,21 +365,36 @@ RCS_ID("$Id$")
resourceManager=[application resourceManager]; resourceManager=[application resourceManager];
appBundle=[resourceManager _appProjectBundle]; appBundle=[resourceManager _appProjectBundle];
[resourceManager _allFrameworkProjectBundles];//So what ? [resourceManager _allFrameworkProjectBundles];//So what ?
[application awake];
GSWAction* action=[self getActionInstanceOfClass:actionClass action=[self getActionInstanceOfClass:actionClass
withRequest:aRequest]; withRequest:aRequest];
NSAssert1(action,@"Direct action of class named %@ can't be created", NSAssert1(action,@"Direct action of class named %@ can't be created",
actionClassName); actionClassName);
actionResult=[action performActionNamed:actionName]; NS_DURING
{
actionResult=[action performActionNamed:actionName];
}
NS_HANDLER
{
LOGException(@"%@ (%@)",localException,[localException reason]);
response=[application handleActionRequestErrorWithRequest:aRequest
exception:localException
reason:"InvocationError"
requestHanlder:self
actionClassName:actionClassName
actionName:actionName
actionClass:actionClass
actionObject:action];
[localException raise];
};
NS_ENDHANDLER;
response=[actionResult generateResponse]; response=[actionResult generateResponse];
context=[action _context]; context=[action _context];
[[NSNotificationCenter defaultCenter]postNotificationName:@"DidHandleRequestNotification" [[NSNotificationCenter defaultCenter]postNotificationName:@"DidHandleRequestNotification"
object:context]; object:context];
[self _setRecordingHeadersToResponse:response [self _setRecordingHeadersToResponse:response
@ -381,19 +407,37 @@ RCS_ID("$Id$")
if ([actionClassName length]>0) if ([actionClassName length]>0)
{ {
exception=[NSException exceptionWithName:NSInvalidArgumentException//TODO better name (IllegalStateException)
exception=[NSException exceptionWithName:NSInvalidArgumentException//TODO better name
reason:[NSString stringWithFormat:@"Can't find action class named '%@'",actionClassName] reason:[NSString stringWithFormat:@"Can't find action class named '%@'",actionClassName]
userInfo:nil]; userInfo:nil];
response=[application handleActionRequestErrorWithRequest:aRequest
exception:exception
reason:"InvocationError"
requestHanlder:self
actionClassName:actionClassName
actionName:actionName
actionClass:actionClass
actionObject:action];
} }
else { else
exception=[NSException exceptionWithName:NSInvalidArgumentException//TODO better name {
reason:[NSString stringWithFormat:@"Can't execute action with path: '%@'",requestHandlerPathArray] exception=[NSException exceptionWithName:NSInvalidArgumentException//TODO better name (IllegalStateException)
userInfo:nil]; reason:[NSString stringWithFormat:@"Can't execute action with path: '%@'",
} requestHandlerPathArray]
userInfo:nil];
response=[application handleActionRequestErrorWithRequest:aRequest
exception:exception
reason:"InvocationError"
requestHanlder:self
actionClassName:actionClassName
actionName:actionName
actionClass:actionClass
actionObject:action];
};
NSDebugMLog(@"Exception=%@",exception);
NSDebugMLog(@"Response=%@",response);
[exception raise]; [exception raise];
NSDebugMLog(@"Not raised ? Exception=%@",exception);
}; };
if ([application isCachingEnabled]) if ([application isCachingEnabled])
{ {
@ -406,13 +450,26 @@ RCS_ID("$Id$")
} }
NS_HANDLER NS_HANDLER
{ {
LOGException(@"%@ (%@)",localException,[localException reason]); LOGException(@"%@ (%@)",localException,[localException reason]);
if (!context) NSDebugMLog(@"EXCEPTION localException=%@",localException);
context=[GSWApp _context]; if (!response)
response=[application handleException:localException {
inContext:context]; if (!context)
//TODO {
context=[action _context];
if (!context)
{
context=[GSWApp _context];
if (!context)
{
context = [application createContextForRequest:aRequest];
};
};
};
response = [self generateErrorResponseWithException:localException
inContext:context];
};
}; };
NS_ENDHANDLER; NS_ENDHANDLER;
NSDebugMLLog(@"requests",@"response=%@",response); NSDebugMLLog(@"requests",@"response=%@",response);