www.webdeveloper.com
Results 1 to 5 of 5

Thread: nullpointerexception after site idle

  1. #1
    Join Date
    Apr 2012
    Posts
    3

    nullpointerexception after site idle

    After weeks of research and little help from my webhost I thought I'd ask the coldfusion community.
    I'm a beginner developer so bear with me. I'll provide as much info as I can think of.

    I'm getting a nullpointerexception error on my site any time it sits idle for a few minutes(less than 5). If I refresh the page it works fine...until the site sits idle again. I've attached the relevant files (application.cfc and header.cfm).
    It happens when GetAuthUser() is called on line 12 of header.cfm.
    I've tried moving that query to onrequeststart in application.cfc and setting a session variable but then i get the same nullpointerexception there.

    Another point is that I have the same exact setup on my local developer server and the error does not occur. The only difference is the lack of ssl on my developer server.

    Also, if I remove the form at the bottom of the header, the error doesn't occur.

    I tried to remove all the irrelevant code from the header.cfm

    Thanks in advance.

    APPLICATION.CFC
    <cfcomponent>
    <cfscript>
    this.name = "TCPro_1_5";
    this.applicationTimeout = createTimeSpan(0,0,90,0);
    this.clientmanagement= "no";
    this.loginstorage = "session" ;
    this.sessionmanagement = "yes";
    this.sessiontimeout = createTimeSpan(0,0,60,0);
    this.setClientCookies = "yes";
    this.setDomainCookies = "no";
    this.scriptProtect = "all";
    </cfscript>

    <cffunction name="onApplicationStart" output="false">
    <cfscript>
    //set your app vars for the application
    application.dsn = "tcswfldata";
    application.sessions = 0;
    </cfscript>
    <cftry>
    <!--- Test whether the DB is accessible by selecting some data. --->
    test query here
    <!--- If we get a database error, report an error to the user, log the
    error information, and do not start the application. --->
    <cfcatch type="database">
    catch code here
    </cfcatch>
    </cftry>
    <cflog file="#this.name#" type="Information" text="Application #this.name# Started">
    <cfreturn True>
    </cffunction>
    <cffunction name="onApplicationEnd" output="false">
    <cfargument name="applicationScope" required="true">
    <cflog file="#this.name#" type="Information" text="Application #this.name# Stopped">
    </cffunction>
    <cffunction name="onSessionStart" output="false">
    <cfscript>
    session.started = now();
    session.defaultFacility = 0;
    </cfscript>
    <cfoutput>#session.started#</cfoutput>
    <cflock scope="application" timeout="5" type="Exclusive">
    <cfset application.sessions = application.sessions + 1>
    </cflock>
    <cflog file="#this.name#" type="Information"
    text="Session #session.sessionid# started.">
    </cffunction>
    <cffunction name="onSessionEnd" output="false">
    <cfargument name = "sessionScope" required=true/>
    <cfargument name = "applicationScope" required=true/>
    <cfset var sessionLength = TimeFormat(Now() - sessionScope.started, "H:mm:ss")>
    <cflock name="AppLock" timeout="5" type="Exclusive">
    <cfset arguments.applicationScope.sessions = arguments.applicationScope.sessions - 1>
    </cflock>
    <cflog file="#this.name#" type="Information"
    text="Session #arguments.sessionScope.sessionid# ended. Length: #sessionLength# Active sessions: #arguments.applicationScope.sessions#">
    </cffunction>
    <cffunction name="onRequestStart" access="public" output="true">
    <cfargument name="requestname" required=true/>

    SSL REDIRECT HERE

    <!--- Check for login here --->
    <cfif isDefined('form.j_username') and isDefined('form.j_password')>
    <cflogin>
    cflogin here
    </cflogin>
    <cfelseif isDefined('form.nd_GOEmailPword')>
    reset password code here
    </cfif>
    <cfelseif isDefined('URL.emailPwd')>
    an include file here
    <cfabort>
    <cfelseif NOT isUserLoggedIn()>
    an include file here
    <cfabort>
    </cfif>
    <cfif isUserLoggedIn()>
    <cfif not structKeyExists(session,'defaultFacility')>
    <cfset session.defaultFacility = 0 />
    </cfif>
    <cfif structKeyExists(form,'sessionDefaultFacility')>
    <cfinvoke component="/tcswfl/TCPro/components.tcpro" method="UpdateDefaultFacility" returnvariable="qResult">
    <cfinvokeargument name="defaultFacility" value="#sessionDefaultFacility#">
    </cfinvoke>
    </cfif>
    <cfset defaultFacility = 0 />
    <cfquery name="qGetDefaultFacility" datasource="#application.dsn#">
    SELECT u.ID
    ,fu.facility_id as default_facility_id
    FROM tblUsers u
    join tblFacility_User fu on u.ID = fu.user_id and fu.default_facility
    WHERE uName = <cfqueryparam value="#getauthuser()#" cfsqltype="cf_sql_varchar /">
    </cfquery>
    <cfif qGetDefaultFacility.recordCount>
    <cfset defaultFacility = qGetDefaultFacility.default_facility_id />
    </cfif>
    <cfif session.defaultFacility neq defaultFacility>
    <cfset session.defaultFacility = defaultFacility />
    </cfif>


    </cfif>

    </cffunction>
    <cffunction name="onError" output="true">
    error handling here
    </cffunction>
    </cfcomponent>


    HEADER.CFM
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"><head>
    <title>
    <!---TITLE GOES HERE --->
    </title>
    <!--- css and javascript links go here--->
    <cfif IsUserLoggedIn()>
    <cfquery name="qMYID" datasource="#application.dsn#">
    SELECT ID AS myID, CONCAT(firstName,' ',lastName) AS myName
    FROM tblUsers
    WHERE uName = <cfqueryparam value="#getauthuser()#" cfsqltype="cf_sql_varchar /">
    </cfquery>
    <cfquery name="qMyLocations" datasource="#application.dsn#">
    SELECT fu.facility_id
    , fu.default_facility AS defFacility
    , f.location
    , f.description
    , concat(f.location, ' ( ', f.description, ' )') as location_display_name
    FROM tblFacility_User fu
    join tblUsers u on fu.user_id = u.ID
    join tblFacility f on fu.facility_id = f.ID
    WHERE u.ID = <cfqueryparam value="#qMYID.myID#" cfsqltype="cf_sql_integer" />
    </cfquery>
    <cfset utcTime = DateConvert('local2UTC',now())>
    <cfinvoke component="components.timezone" method="castFromUTC" returnvariable="localTime">
    <cfinvokeargument name="thisDate" value="#utcTime#">
    <cfinvokeargument name="thisTZ" value="#qLocalTZ.localTZ#">
    </cfinvoke>
    </cfif>
    </head>
    <body>
    <cfif getAuthUser() NEQ ''>
    <div id="contatiner">
    <!---site logo goes here --->
    <div id="panel">
    <cfquery name="qFirstName" datasource="#application.dsn#">
    SELECT firstName
    FROM tblUsers
    WHERE uName = '#GetAuthUser()#'
    </cfquery>
    <div class="panel_content">
    <table width="100%">
    <tr>
    <td style="text-align:right">Welcome Back <cfoutput query="qFirstName"><strong>#firstName#</strong>
    </cfoutput><a href="/tcswfl/TCPro/settings.cfm">(Settings)</a>
    </td>
    </tr>
    </table>
    </div>
    </div>
    <!--- Navigation goes here --->
    <div id="header_content">
    <div id="panel2">
    <cfif qMyLocations.recordCount gt 1>
    <table>
    <tr>
    <td style="vertical-align:top"><span class="smallText">current facility:&nbsp;</span></td>
    <td>
    <form action="/tcswfl/TCPro/index.cfm" method="post" name="formSelectLocation">
    <select name="sessionDefaultFacility" onchange="submit();" style="font-size:10px;">
    <cfoutput query="qMyLocations">
    <option value="#qMyLocations.facility_id#"<cfif qMyLocations.facility_id EQ session.defaultFacility>selected=selected</cfif>>#qMyLocations.location_display_name#</option>
    </cfoutput>
    </select>
    </form>
    </td>
    </tr>
    </table>
    <cfelseif qMyLocations.recordCount eq 1>
    <cfoutput>
    <table>
    <tr>
    <td><span class="smallText">Current Location: #qMyLocations.location_display_name#</span></td>
    </cfoutput>
    </cfif>
    </tr>
    </table>
    </div>
    </div>
    </cfif>
    </body>
    </html>

  2. #2
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    I've looked and looked at the code, and the only thing that I can think of is that the CF 9 server isn't properly set up for using GetAuthUser(). OR, something else may be interfering with it.
    |||||
    o . Q
    ___ "You live and you learn; or you don't live long." - Lazarus Long

    ^_^

  3. #3
    Join Date
    Apr 2012
    Posts
    3
    Many thanks for checking it out. I've just uploaded the site to a different host and the problem isn't there. I can't seem to convince my current host that "it's you and not me". Guess its about time to change.

    Thanks again

  4. #4
    Join Date
    Apr 2012
    Posts
    3
    just wanted to follow up with this in case anyone else has a similar issue. I contacted my web host and explained the problem. they disabled the "maintain connections" options in the datasource options of the coldfusion server and now everything works fine with no errors. there's a good explanation of the issue here: http://forums.adobe.com/message/3396333

    hope this helps someone

  5. #5
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    Glad that you got it working. AND that it wasn't your code. I thought it all seemed correct. Did they apologize for not believing you?
    |||||
    o . Q
    ___ "You live and you learn; or you don't live long." - Lazarus Long

    ^_^

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles