• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Mysterious EditingContext Swap
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mysterious EditingContext Swap


  • Subject: Re: Mysterious EditingContext Swap
  • From: "Jerry W. Walker" <email@hidden>
  • Date: Wed, 2 Aug 2006 08:14:54 -0400

Hi, Owen,

Though I'm not sure what's causing your error, it sounds like you might be having a contention issue with your EOEditingContext. I notice that you're not locking it until you're ready to saveChanges on it.

When creating your own EOEditingContext (vs. using Sessions defaultEditingContext), it should be locked before ANY use (including such things as creating or obtaining EOs through it, updating EOs in it, deleting EOs from it, etc.).

The best way I know of doing that is by using Jonathan Rochkind's MultiECLockManager (or Chuck Hill's customization of it).

You can find it at:

    http://www.wocode.com/WOCode/Files/MultiECLockManager.java

I can't see anything else in the code that would cause such a problem.

Regards,
Jerry

On Aug 1, 2006, at 11:50 PM, Owen McKerrow wrote:

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,

...

--
__ Jerry W. Walker,
WebObjects Developer/Instructor for High Performance Industrial Strength Internet Enabled Systems


    email@hidden
    203 278-4085        office



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Mysterious EditingContext Swap (From: Owen McKerrow <email@hidden>)
 >Re: Mysterious EditingContext Swap (From: Ken Anderson <email@hidden>)
 >Re: Mysterious EditingContext Swap (From: Owen McKerrow <email@hidden>)

  • Prev by Date: Re: MSSQL Server 2005 Unicode Support and EOF
  • Next by Date: Re: Event update ; notice
  • Previous by thread: Re: Mysterious EditingContext Swap
  • Next by thread: Re: Mysterious EditingContext Swap
  • Index(es):
    • Date
    • Thread