/***************************************************************** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. ****************************************************************/ #import "CAYHessianConnection.h" #import "CAYClientMessage.h" #import "CAYCocoaCayenne.h" #import "CAYMissingSessionException.h" @implementation CAYHessianConnection -(id)init { self = [super init]; if(self) { [self updateClassMapping:[CAYCocoaCayenne classMapping]]; } return self; } -(id)initWithUrl:(NSURL *)url { [self init]; BBSHessianProxy *px = [[BBSHessianProxy alloc] initWithUrl:url]; [self setProxy:px]; [px release]; return self; } -(void)connect { id result1 = [[self proxy] callSynchronous:@"establishSession" withParameters:nil]; NSLog(@"DEBUG: establishSession result: %@", result1); } -(void)updateClassMapping:(NSDictionary *)cm { [BBSHessianProxy setClassMapping:cm]; } - (id) sendMessage:(CAYClientMessage *)message { NSArray *parameters = [NSArray arrayWithObject:message]; id result = [proxy callSynchronous:@"processMessage" withParameters:parameters]; if([result isKindOfClass:[NSError class]]) { NSError *err = (NSError *)result; NSDictionary *userInfo = [err userInfo]; id underlyingError = [userInfo valueForKey:NSUnderlyingErrorKey]; if([underlyingError isKindOfClass:[CAYMissingSessionException class]]) { NSLog(@"ERROR: missing session. try to reconnect."); [self connect]; // reissue processMessage with the new session result = [proxy callSynchronous:@"processMessage" withParameters:parameters]; NSLog(@"DEBUG: processMessage (after reconnect) result: %@", result); } } return result; } -(void) setProxy:(BBSHessianProxy *)p { [p retain]; [proxy release]; proxy = p; } -(BBSHessianProxy *) proxy { return proxy; } -(void)dealloc { [self setProxy:nil]; [super dealloc]; } @end