Paul's Dev Blog – iGonzo.net

And here I though we were just having a normal till-the-death shoot out. Silly Me.

Archive for the ‘asp’ tag

ASP hates XML

without comments

This is what I thought. For the last day or so I have been trying to get a silly little (well, quite large actually) XML string to import into a database table.

After my previous troubles with just getting the data file, I thought I was in the clear. However, it seems that some of the nodes within the taget XML file contained characters that XML did not like at all. Mostly those characters that have squiggly little lines and flourishes above them. And despite my efforts, I just could not get them to import or to simply skip that data node.

So have spending more hours than I care to admin banging my head against the desk, I stepped back to examine the problem from its most basic form.

The simplified problem was this: I have a string of text that I need to parse and put into the database. There is a character or three preventing that.

The simplified solution was this: Remove the offending character.

Trouble was, I could not get the character targeted for a replace, as it was being processed according to whatever format the MS XMLHTTP object uses. Then it hit me. No matter what, information has to get passed, and the only want to ensure this was to convert certain characters to their HTML equivalents, such as   for spaces, < for brackets, etc. This is basic to every form of data transmission on the web.

So the simplified plan of attack now was this: Convert the entire XML string to and HTML encoded string; Find the HTML encoded character and replace it; Decode the string back to an XML string.

Once I had that plan it was stupidly simple to convert, replace, and then convert back to XML. I piped that into my DB input script and it worked.

So kids, the moral of the story is this: Step back once in a while to examine the problem. And then break it down (or convert it) to its most basic workable form. After that, solutions tend to pop up faster than just mucking about with fancy object functions.

-Cheers

Written by iGonzo

July 20th, 2011 at 1:20 pm

IIS and multiple IPs

without comments

So it was that we had a site that was needing to pull in some XML data from a clients internal system. Not a huge deal, we do it all the time. The client needed to restrict the data to an IP address for security. Also not a problem, we do that quite regularly. But as it turned out, it was a problem. A small, annoying problem that the client caught onto.

You see, in an IIS server that has multiple IPs going to it, you can assign an IP to a site. This is what we did here; specifically set the site to respond to a certain IP. The client allowed an exception to that IP. But it still would pull in data.

Begin frustration.

After more than a day of fiddling around with setting, I asked the client to pull up the IP of the site we are working on. They did, and confirmed that the site was from that IP. But there was also something else. Another IP entry in their firewall logs. Turns out, that was one of our IPs.

Weird. So I asked the client to add exceptions to all the IPs running to our server. He did. And low and behold, the site is pulling in the data now.

Begin confusion.

The data grab is being done on the backend through an XML load. Apparently, the server decided to use whatever available channel to grab the data. In this instance, it was the first IP on the list. So it turns out that the IP we specifically set the site to respond to is just that, it responds to just that IP, and responds only. Getting data, however, is a different matter it seems, ad the site will use whatever available IP, regardless of what the site is set to respond to.

End confusion. End frustration.

I havent seen where to set IIS to only pipe data trough the IP we assign it, but at this point I am not really concerned about that. It works and for now, I will take that as a win.

So in the future, if you use IIS, be sure to allow exceptions for all IPs to the box when needing to get data from an external source. Save yourself the frustration. Then go have a beer.

Mmmm, beer. :)

Written by iGonzo

July 19th, 2011 at 12:42 pm

Authorize.net and Classic ASP

with 2 comments

You know, a lot of people are moving off to other, cooler programming languages. PHP, ASP.NET, Ruby, all of these are seen as superior to Classic ASP; at one time the greatest language to use for dynamic data driven sites.

More often than I care to admit, I get asked “Why don’t you do it in [insert current language here] to do that? It’s easier”. True, but I have been using ASP for 11 years and am quite good at it if I do say so myself. Besides, as long as it can process XML, I see little reason to change our entire code base. Which brings me to the actual crux of this post: Using Classic ASP with Authorize.net.

More specifically, you can use any programming language with the Authorize API as long as you can process XML. But since I use primarily Classic ASP, that is what we have to use.

Authorize, in their wisdom, has seen fit to provide examples of accessing their API. One of these examples includes an ASP version. At first I totally ignored these, assuming that they could not accomplish what the client needed (which is integration with the Authorize CIM system). And so I toiled for many an hour creating functions and testing. Eventually I came across a problem I could not bull my way through, so I humbled myself and looked at their example code.

My first reaction was, of course, chagrin. Their ASP examples were performing functions that I needed. Precisely what I needed. *urg*. So, over the next 20 minutes, I functionalized their examples, added in our data points, and low and behold I got a positive response without any errors. I even tried to create errors and still the data went through.

Begin head banging on desk.

So then, after my headache went away, I grabbed every code example they had and was able to add in a whole mess of features and functions that not only added robustness to the site, but some serious value for the client. The transmission functions I created are able to take any form of XML request and sent it to Authorize and get a response back. After a quick check my reply data is added to the database and its on to the next thing: which for the client is making money (businesses are funny that way).

The lesson here, trolls and girls, is to not scoff at API example code. We can all look at the PDF of how to form this or that request, and what to expect back in response, but seeing a bit of sample code execute without errors is, in my opinion, a very uplifting thing to experience.

Now, if I can just figure out how this FBML crap, I think I’ll be golden.

Cheers

Written by iGonzo

November 5th, 2010 at 1:34 pm

Search Arrays without server code (sorta)

without comments

So it happens that I have a database field value that is a comma separated string of numbers. Classically, I would grab the field, turn it into an array, and search the array. Somewhat cumbersome and not really worth the effort of another function. That, and I would have to grab every record in the database, search through the applicable fields, and filter out the record(s) I need.

Me, being lazy, want an easier way to do it. Then I found this:

Then I came across this: http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_find-in-set

All I have to do is construct a statement like this:

SELECT * FROM table_name WHERE FIND_IN_SET(‘thevalue‘,Field_To_Search)

You can also use a variable in place of ‘thevalue‘ if you need to search for, say, a passed parameter.

In the end, I was given a list of one or two records that I can easily do the rest of the work for, instead of grabbing every record in the table and filtering after the search.

For the lazy folks, this is quite a good thing. For the non-lazy folks, this is still a good thing. The above query not only executes faster, the code weight is greatly reduced and also runs faster (tests show about a 40% increase in speed and a 50% reduction in code execution time).

Final thoughts; this now leaves me more time to either work on something else, or go grab some food. I vote food.

Cheers

Written by iGonzo

October 15th, 2010 at 11:53 am

Posted in Database,Programming

Tagged with , ,

Check Yourself (and your code)

without comments

So I just spent a large-ish amount of time trying to figure out why, when I updated one data table from an XML feed, it updated a completely separate table that was not even related to the updated one.

The answer was on one tiny little line of code. That line of code executed a function in the other XML feed processor for the other table and dataset. The problem was that I copied the function and changed a few variables (since the feeds were almost identical) but didn’t go through and check to see if anything else was going on.

The lesson for today: Check your freaking code. If you want to copy/modify a function to use elsewhere, make sure that there aren’t any little items that would make for a not fun programming day.

Cheers

Written by iGonzo

August 20th, 2010 at 3:27 pm

Posted in Programming

Tagged with , ,