8 Replies Latest reply on Jun 12, 2007 1:13 PM by jpollar319

    Inconsistent Components - Only Work on 2nd Execution

    jpollar319
      Is there a bug in the ColdFusion server that is preventing components from executing without error?

      I have 20+ components that I'm executing using a gateway. Many of them are returning errors.

      Examples would be parameters in a find function or expression error for math functions like ceiling.

      When I try to invoke them using a test cfm page...I get the same errors.

      However, when I run the same exact script (no mods)...the code MAGICALLY works.

      Why is this happening???? It's driving me up the damn wall!
        • 1. Re: Inconsistent Components - Only Work on 2nd Execution
          insuractive Level 3
          Let me see if I understand the situation - you have a set of User Defined Functions (UDFs) that work when you include them in your page code, but don't work when you call them from a component?

          Where are your components located and how are you referencing them in your code? Do they work if you put them in the same directory as your calling page OR if you put them in your CF custom tags directory?

          Have you set any access restrictions on the functions using the <cfunction access=""> attribute?
          • 2. Re: Inconsistent Components - Only Work on 2nd Execution
            jpollar319 Level 1
            Michael...thanks for the reply.

            No UDFs are being used. Only standard CF functions like find and ceiling to name a few.

            The components and code work fine....the problem is that some of them only work after being invoked again. I think the errors from the first invokation are bogus.

            I'm starting to think it's a network issue. Sometimes when I browse on our network I get a "page cannot be displayed" error for certain URLs. I hit the refresh button on my browser and everything comes up just fine. This issue is probably also affecting ColdFusion.

            I probably need to contact our network admins and ask them wtf is going on.
            • 3. Re: Inconsistent Components - Only Work on 2nd Execution
              Dan Bracuk Level 5
              What is the error that you are getting?
              • 4. Re: Inconsistent Components - Only Work on 2nd Execution
                insuractive Level 3
                What exactly do you mean by components? Are you talking about .cfc files? custom tags? regular coldfusion pages (.cfm)?

                I had assumed that since you used the term components, you were using cfc's. But the fact that you aren't using UDFs, makes me think that perhaps there is a bit confusion about the nominclature used.

                Why don't you tell us a little more about what types of CF files you have, where they are located in relation to your calling page, how you are calling them and (like Dan suggests) the errors you are receiving.
                • 5. Inconsistent Components - Only Work on 2nd Execution
                  iKnowKungFoo
                  Can you give us some sample code? One time I can think this would happen would be if the functions are in an application or session scoped variable that isn't set when you call them the first time.
                  • 6. Re: Inconsistent Components - Only Work on 2nd Execution
                    jpollar319 Level 1
                    Gents,

                    Thanks much for the responses.

                    First off, I'm about 100% certain its a network issue. I'm using cfhttp to connect to different websites; using a cfc for each site. I just tested the site below in a web browser and got "the page cannot be displayed." I hit refresh and the site came up just fine.

                    Here's a small example.

                    Error (Created in my own log file):

                    BeltwayBrokerage Started - 02:51
                    Expression Error - 02:52 | Page: 0 - Parameter 3 of function RemoveChars which is now -1 must be a non-negative integer -
                    BeltwayBrokerage Completed - 02:52

                    The component is being invoked from a test template in the root folder.

                    Test.cfm:

                    <cfinvoke component="comps.beltwaybrokerage" method="beltwaybrokerage">


                    This is only a small portion of the code from a single cfc. The error above is from the last line of code shown below. The removechars function obviously fails because the page could not be successfully captured by cfhttp. The code is in a sub folder called comps.

                    CFC (BeltwayBrokerage.cfc):

                    <cfcomponent>
                    <cffunction name="beltwaybrokerage" output="true">
                    <cfparam name="records" default="">
                    <cfparam name="offset" default="0">

                    <cffile action="append" addnewline="yes" file="d:\cfusionmx7\wwwroot\bizgot\log\gateway_#dateformat(now(),'dd-mmm-yyyy')#.log" output="BeltwayBrokerage Started - #timeformat(now(),'HH:mm')#" fixnewline="no">

                    <cfloop index="offset" from="10" to="630" step="10">

                    <cfset offset = 0>

                    <!--- BeltwayBrokerage.com --->
                    <cfhttp url=" http://www.beltwaybrokerage.com/listing.php" delimiter="," resolveurl="yes">
                    </cfhttp>

                    <cfset xmldoc = cfhttp.FileContent>

                    <!--- Remove unneeded HTML --->
                    <cftry>
                    <cfset xmldoc = removechars(xmldoc,1,findnocase("<a href=' http://www.beltwaybrokerage.com:80/dispprop.php?id=",xmldoc)-1)>
                    • 7. Re: Inconsistent Components - Only Work on 2nd Execution
                      insuractive Level 3
                      So you are using a User Defined Function - beltwaybrokerage()

                      Just out of curiosity, why are you hitting beltwaybrokerage 63 times? And I'm pretty sure <cfloop index="offset" from="10" to="630" step="10"> is the same as <cfloop index="offset" from="1" to="63">.

                      Also, you might want to consider specifying the method for your <cfhttp> call (get or post).

                      In CFMX, <cfhttp> returns a lot of really useful information in the CFHTTP scope. Once you perform your post, I would do a <cfdump> and see if any of that information might help you determine if your CFHTTP call was successful (status code?).

                      If you know that your CFHTTP call might fail, you probably should test if
                      LEN(TRIM(xmldoc)) gt 0
                      before you continue with your processing.

                      The problem might not just be your network - If beltwaybrokerage is not your site, the problems might have to do with the server the site is hosted on as well - can't handle the amount of network traffic, etc. Hitting it 63 times is probably not helping with that.

                      So when you place the code for beltwaybrokerage() in a page, it executes successfully every time?
                      • 8. Re: Inconsistent Components - Only Work on 2nd Execution
                        jpollar319 Level 1
                        The offset designates which record starts the recordset shown on the screen....hence the increments by 10. 1 to 63 would not produce the desired result.

                        cfhttp defaults to the get method...it isn't required.

                        Testing the results from the cfhttp is a plausible solution....it's looking like it will be required.

                        The script fails before i can even hit it 63 times though...in fact, it fails on the very first pass.

                        No matter where I put the code (UDF or cfm) or how I execute / invoke it....the code ALWAYS fails the first time...but succeeds on EVERY following attempt. THIS is what baffles me.

                        I'm getting ready to try the code from home to test my (network issue) theory.