Nope, not paraphrasing. You can see the full error message at bottom
of the email.
The only time I have heard of the active editing context is for a save.
Nope haven't had the chnace yet to separate this out to its own project.
Heres the full code ( it includes our RADIUS authentication methods
which I did paste before ):
// Generated by the WebObjects Assistant Mon Feb 07 14:26:32
Australia/Sydney 2005
import com.webobjects.foundation.*;
import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;
import com.webobjects.eoaccess.*;
import net.sourceforge.jradiusclient.*;
import net.sourceforge.jradiusclient.exception.*;
public class Main extends WOComponent {
protected Application app;
protected EOEditingContext ec;
protected NSMutableDictionary bindings;
protected String userName;
protected String password;
protected String errorMessage;
protected boolean forgotPassword;
protected boolean thankyou;
protected boolean emailAddress;
protected boolean gotMobile;
private String secretHandshake;
private String hostName;
private RadiusClient rc;
private String exitCode;
//----------------------------- The Constructors
---------------------------------------------
public Main( WOContext context ) throws Exception
{
super(context);
app = (Application)Application.application();
//ec = ((Session)session()).defaultEditingContext();
ec = new EOEditingContext();
System.out.println("Editing Context just been made : " + ec);
// ((Session)session()).resetCrumbs();
secretHandshake = "*********";
hostName = "radius.uow.edu.au";
RadiusClient rc = null;
NSArray mems;
forgotPassword = false;
thankyou = false;
emailAddress = false;
gotMobile = false;
}
//------------------------------- WOComponent Functions
---------------------------------------
//Called when the Persons clicks the submit button to login
public WOComponent checkLogin() throws Exception
{
errorMessage = "";
WOComponent nextPage = null;
//If both fields have some data in them
if ( userName != null && password != null )
{
userName.trim();
password.trim();
try {
rc = new RadiusClient(hostName,
1812,1813,secretHandshake,userName);
} catch(java.net.SocketException soex) {
app.setErrorMessage("Unable to create Radius Client due to
failure to create socket!");
throw soex;
} catch(java.security.NoSuchAlgorithmException
nsaex) {
app.setErrorMessage("Unable to create Radius Client due to
failure to create MD5 MessageDigest!");
throw nsaex;
} catch(InvalidParameterException ivpex) {
app.setErrorMessage("Unable to create Radius Client due to
invalid parameter! " + ivpex.getMessage() );
throw ivpex;
}
try {
boolean returned;
if (app.debugMode )
{
returned = true;
}
else
{
returned =
authenticate(rc,password,null);
}
// Radius confirmed the userName and
password are valid
if (returned)
{
nextPage =
(Menu)pageWithName("Menu");
//check if the user is in the
recipient table
checkRecipient();
}
else
{
errorMessage = "<span class=\"failure\">User name & Password
incorrect</span>";
if (isUppercase(password)) {
errorMessage += "<span class=\"failure\"><br>Check Caps lock
is not on.</span>";
}
}
} catch(InvalidParameterException ivpex){
app.setErrorMessage(ivpex.getMessage());
} catch(java.net.UnknownHostException uhex){
app.setErrorMessage(uhex.getMessage());
} catch(java.io.IOException ioex){
app.setErrorMessage(ioex.getMessage());
} catch(RadiusException rex){
app.setErrorMessage(rex.getMessage());
}
}
else {
errorMessage = "<span class=\"failure\">Please enter
both user name & password.</span>";
}
password = "";
return nextPage;
}
//Authenticate against the RADIUS server
public static boolean authenticate(RadiusClient rc, String
userPass, byte[] callingStationId) throws InvalidParameterException,
java.net.UnknownHostException, java.io.IOException, RadiusException
{
int returnCode;
returnCode = rc.authenticate(userPass);
boolean returned = false;
switch (returnCode){
case RadiusClient.ACCESS_ACCEPT:
System.out.println("Authenticated");
returned = true;
break;
case RadiusClient.ACCESS_REJECT:
System.out.println("Not Authenticated");
returned = false;
break;
case RadiusClient.ACCESS_CHALLENGE:
System.out.println(rc.getChallengeMessage());
break;
default:
System.out.println("How the hell did we get here?");
returned = false;
break;
}
return returned;
}
// Returns true is each character entered is in uppercase
private boolean isUppercase(String password)
{
boolean flag = true;
char[] temp = password.toCharArray();
char aChar;
for(int i = 0; i<password.length();i++)
{
aChar = temp[i];
if(Character.isLowerCase(aChar))
{
flag = false;
break;
}
}
return flag;
}
public void checkRecipient() throws Exception
{
System.out.println("Editing Context at start of checkRecipient : "
+ ec);
try {
//search the recipient table for the username
Recipient r = null;
NSMutableDictionary dic = new NSMutableDictionary();
dic.setObjectForKey(userName,"logon");
NSArray temp = EOUtilities.objectsWithFetchSpecificationAndBindings
(ec,"Recipient","RecipSearch",dic);
if( temp.count() > 0 ) {
r = (Recipient)temp.lastObject();
System.out.println("Old : " + r.surname() + r.logonIdentifier() +
r.editingContext());
}
System.out.println("Editing after search for old : " +
ec);
//insert new row in database if recipient does not exist
if (r==null) {
System.out.println("Editin Context at start of
create : " + ec);
Company theCompany = (Company)
com.webobjects.eoaccess.EOUtilities.objectMatchingKeyAndValue
(ec,"Company","logonIdentifier","UOW");
System.out.println("Company : " +
theCompany.editingContext());
if( theCompany != null ) {
r = ( Recipient)
com.webobjects.eoaccess.EOUtilities.createAndInsertInstance
(ec,"Recipient");
System.out.println("New Recipient : " +
r.editingContext());
r.setLogonIdentifier(userName);
r.addObjectToBothSidesOfRelationshipWithKey(theCompany,"company");
//Get their details from LDAP
//Should only be one entry returned for
1 username
//Use a new Editing Context as we us e a different Adaptor type
i.e. JNDI not JDBC, not sure if this is required but added in case it
was causing the bug
PersonLDAP person = (PersonLDAP)
EOUtilities.objectMatchingKeyAndValue(new EOEditingContext
(),"PersonLDAP","uid",userName);
r.setFirstName(person.givenName());
r.setSurname(person.sn());
r.setEmailAddress(userName +
"@uow.edu.au");
r.setDateRegistered(new NSTimestamp());
//set the session user to the new
instance of recipient
System.out.println("new : " + r.surname() + r.logonIdentifier()
+ r.editingContext());
save();
}
}
System.out.println("editing Context : " + ec);
((Session)session()).setCurrentUser((Recipient)
EOUtilities.localInstanceOfObject(((Session)session
()).defaultEditingContext(),r));
}
catch (java.lang.IllegalArgumentException ex) {
}
catch (Exception e)
{
throw e;
}
}
private void save() throws Exception
{
try {
// ec.lock();
ec.saveChanges();
// ec.unlock();
} catch (Exception exception) {
app.setErrorMessage("Error when trying to add a new recipient. save
() menu.java\n");
throw exception;
}
}
}
Owen McKerrow
WebMaster, emlab
Ph : +61 02 4221 5517
http://emlab.uow.edu.au
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - -
'The test of a first-rate intelligence is the ability to hold two
opposed ideas in the mind at the same time and still be able to
function.'
-F.Scott Fitzgerald,
On 02/08/2006, at 1:09 PM, Ken Anderson wrote:
Owen,
Are you paraphrasing the error message? I have to admit, I've
never heard of a database context's "active" editing context. Is
there other code besides this? Have you isolated this code out in
a separate project?
Ken
On Aug 1, 2006, at 10:42 PM, Owen McKerrow wrote:
Hi All,
Im having issues with an editing context that seems to somehow be
switching behind my back.
Vitals : OS X 10.4.7 WO 5.3 Java 1.4.2
OK first an explaination :
On our login in page we check if the user already has an account,
if so log them in, if not make them one attach them to an instance
of company and then log them in. From a clean DB i.e. no users in
it I can log in as user one and it makes the user fine. I can then
re-log in as this user. If I log in as another user I get a error
saying that the company object is in another editing context.
So I added in debug statements to check what was happening with it.
And it seems between grabbing the company, creating a new user and
then doing addObjectToBothSidesOfRelationship, my active editing
context changes.
Short Version ( debug statements spaced in-between the lines of
code ) :
//Editing Context just been made :
[EMAIL PROTECTED]
Company theCompany = (Company)
com.webobjects.eoaccess.EOUtilities.objectMatchingKeyAndValue
(ec,"Company","logonIdentifier","UOW");
System.out.println("Company : " + theCompany.editingContext());
//Company : [EMAIL PROTECTED]
if( theCompany != null ) {
r = ( Recipient)
com.webobjects.eoaccess.EOUtilities.createAndInsertInstance
(ec,"Recipient");
System.out.println("New Recipient : " + r.editingContext());
//New Recipient : [EMAIL PROTECTED]
r.setLogonIdentifier(userName);
r.addObjectToBothSidesOfRelationshipWithKey
(theCompany,"company"); //Error is thrown on this line
Short error ( referring to theCompany ):
Cannot obtain globalId for an object which is registered in an
other than the databaseContext's active editingContext
databaseContext: [EMAIL PROTECTED]
object's editingContext:
[EMAIL PROTECTED]
databaseContext's active editingContext:
[EMAIL PROTECTED]
As you can see the Company's editing context is aab7d, however
when I call addObjectToBothSidesOfRelationshipWithKey the active
editing context is apparently 883540.
How is the active editing context "swapping" ? In fact where is if
getting this active editing context from ?
Anyone have any ideas ?
Thanks
Owen
PS Heres the "fuller" version
Long Version :
The code :
ec = new EOEditingContext();
try {
//search the recipient table for the username
Recipient r = null;
NSMutableDictionary dic = new NSMutableDictionary();
dic.setObjectForKey(userName,"logon");
NSArray temp =
EOUtilities.objectsWithFetchSpecificationAndBindings
(ec,"Recipient","RecipSearch",dic);
if( temp.count() > 0 ) {
r = (Recipient)temp.lastObject();
System.out.println("Old : " + r.surname() + r.logonIdentifier
() + r.editingContext());
}
System.out.println("Editing after search for old : " +
ec);
//insert new row in database if recipient does not exist
if (r==null) {
System.out.println("Editin Context at start of
create : " + ec);
Company theCompany = (Company)
com.webobjects.eoaccess.EOUtilities.objectMatchingKeyAndValue
(ec,"Company","logonIdentifier","UOW");
System.out.println("Company : " +
theCompany.editingContext());
if( theCompany != null ) {
r = ( Recipient)
com.webobjects.eoaccess.EOUtilities.createAndInsertInstance
(ec,"Recipient");
System.out.println("New Recipient : " +
r.editingContext());
r.setLogonIdentifier(userName);
r.addObjectToBothSidesOfRelationshipWithKey
(theCompany,"company");
The Debug Statements :
Logged in as user 1 ( all works fine ) :
Editing Context just been made :
[EMAIL PROTECTED]
Session has been created.
Editing Context at start of checkRecipient :
[EMAIL PROTECTED]
Editing after search for old :
[EMAIL PROTECTED]
Editin Context at start of create :
[EMAIL PROTECTED]
Company : [EMAIL PROTECTED]
New Recipient : [EMAIL PROTECTED]
new : [EMAIL PROTECTED]
editing Context : [EMAIL PROTECTED]
Session Terminate
Log in for second time as user 1 ( all works fine ) :
Editing Context just been made :
[EMAIL PROTECTED]
Session has been created.
Editing Context at start of checkRecipient :
[EMAIL PROTECTED]
Old : [EMAIL PROTECTED]
Editing after search for old :
[EMAIL PROTECTED]
editing Context : [EMAIL PROTECTED]
Session Terminate
Log in As User 2 :
Editing Context just been made :
[EMAIL PROTECTED]
Session has been created.
Editing Context at start of checkRecipient :
[EMAIL PROTECTED]
Editing after search for old :
[EMAIL PROTECTED]
Editin Context at start of create :
[EMAIL PROTECTED]
Company : [EMAIL PROTECTED]
New Recipient : [EMAIL PROTECTED]
Long Error :
[2006-08-02 12:15:34 EST] <WorkerThread3>
<com.webobjects.appserver._private.WOComponentRequestHandler>:
Exception occurred while handling request:
java.lang.IllegalStateException: Cannot obtain globalId for an
object which is registered in an other than the databaseContext's
active editingContext, object: {values = {companyName =
"University of Wollongong"; recipient =
"<com.webobjects.eocontrol._EOCheapCopyMutableArray f65b0e
(<EOAccessArrayFaultHandler recipient _EOIntegralKeyGlobalID
[Company (java.math.BigDecimal)1]>)>"; dateCreated =
<com.webobjects.foundation.NSKeyValueCoding$Null>; logonIdentifier
= "UOW"; trackingObject =
"<com.webobjects.eocontrol._EOCheapCopyMutableArray 6a1e78
(<EOAccessArrayFaultHandler trackingObject _EOIntegralKeyGlobalID
[Company (java.math.BigDecimal)1]>)>"; }; this = "<Company 864d2
_EOIntegralKeyGlobalID[Company (java.math.BigDecimal)1]>"; },
databaseContext: [EMAIL PROTECTED],
object's editingContext:
[EMAIL PROTECTED], databaseContext's
active editingContext:
[EMAIL PROTECTED]
[2006-08-02 12:15:34 EST] <WorkerThread3>
java.lang.IllegalStateException: Cannot obtain globalId for an
object which is registered in an other than the databaseContext's
active editingContext, object: {values = {companyName =
"University of Wollongong"; recipient =
"<com.webobjects.eocontrol._EOCheapCopyMutableArray f65b0e
(<EOAccessArrayFaultHandler recipient _EOIntegralKeyGlobalID
[Company (java.math.BigDecimal)1]>)>"; dateCreated =
<com.webobjects.foundation.NSKeyValueCoding$Null>; logonIdentifier
= "UOW"; trackingObject =
"<com.webobjects.eocontrol._EOCheapCopyMutableArray 6a1e78
(<EOAccessArrayFaultHandler trackingObject _EOIntegralKeyGlobalID
[Company (java.math.BigDecimal)1]>)>"; }; this = "<Company 864d2
_EOIntegralKeyGlobalID[Company (java.math.BigDecimal)1]>"; },
databaseContext: [EMAIL PROTECTED],
object's editingContext:
[EMAIL PROTECTED], databaseContext's
active editingContext:
[EMAIL PROTECTED]
at com.webobjects.eoaccess.EODatabaseContext._globalIDForObject
(EODatabaseContext.java:4847)
at
com.webobjects.eoaccess.EODatabaseContext.databaseOperationForObject(
EODatabaseContext.java:4964)
at com.webobjects.eoaccess.EODatabaseContext.valuesForKeys
(EODatabaseContext.java:6701)
at com.webobjects.eocontrol.EOObjectStoreCoordinator.valuesForKeys
(EOObjectStoreCoordinator.java:341)
at com.webobjects.eoaccess.EOQualifierSQLGeneration
$_KeyValueQualifierSupport.schemaBasedQualifierWithRootEntity
(EOQualifierSQLGeneration.java:418)
at com.webobjects.eoaccess.EOQualifierSQLGeneration
$Support._schemaBasedQualifierWithRootEntity
(EOQualifierSQLGeneration.java:165)
at
com.webobjects.eoaccess.EODatabaseChannel.selectObjectsWithFetchSpeci
fication(EODatabaseChannel.java:209)
at
com.webobjects.eoaccess.EODatabaseContext._objectsWithFetchSpecificat
ionEditingContext(EODatabaseContext.java:3205)
at
com.webobjects.eoaccess.EODatabaseContext.objectsWithFetchSpecificati
on(EODatabaseContext.java:3346)
at
com.webobjects.eocontrol.EOObjectStoreCoordinator.objectsWithFetchSpe
cification(EOObjectStoreCoordinator.java:539)
at
com.webobjects.eocontrol.EOEditingContext.objectsWithFetchSpecificati
on(EOEditingContext.java:4114)
at
com.webobjects.eoaccess.EODatabaseContext.objectsForSourceGlobalID
(EODatabaseContext.java:4260)
at
com.webobjects.eocontrol.EOObjectStoreCoordinator.objectsForSourceGlo
balID(EOObjectStoreCoordinator.java:682)
at
com.webobjects.eocontrol.EOEditingContext.objectsForSourceGlobalID
(EOEditingContext.java:3965)
at com.webobjects.eoaccess.EODatabaseContext._fireArrayFault
(EODatabaseContext.java:4427)
at
com.webobjects.eoaccess.EOAccessArrayFaultHandler.completeInitializat
ionOfObject(EOAccessArrayFaultHandler.java:70)
at com.webobjects.eocontrol._EOCheapCopyMutableArray.willRead
(_EOCheapCopyMutableArray.java:38)
at com.webobjects.eocontrol._EOCheapCopyMutableArray.count
(_EOCheapCopyMutableArray.java:92)
at com.webobjects.foundation.NSArray.containsObject(NSArray.java:
639)
at
com.webobjects.eocontrol.EOCustomObject.includeObjectIntoPropertyWith
Key(EOCustomObject.java:907)
at Company.addToRecipient(Company.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.webobjects.foundation.NSSelector._safeInvokeMethod
(NSSelector.java:120)
at
com.webobjects.eocontrol.EOCustomObject.addObjectToPropertyWithKey
(EOCustomObject.java:944)
at
com.webobjects.eocontrol.EOCustomObject.addObjectToBothSidesOfRelatio
nshipWithKey(EOCustomObject.java:1069)
at Main.checkRecipient(Main.java:229)
at Main.checkLogin(Main.java:122)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/lists%
40anderhome.com
This email sent to [EMAIL PROTECTED]
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to archive@mail-archive.com