Monday, January 25, 2016

SOAP/WSDL on Perl, Ruby, PHP or Python (anything but .NET/Java)

SOAP was designed to provide cross platform RPC but the reality is that the only usable implementations of the spec are on .NET and Java.  Yes there are several available for other programming languages but they are incomplete or broken (they may or may not work).  Want to know what ALWAYS works?  Read on.

My recommendation is to avoid them completely and download SoapUI (which is written in Java).  This desktop software will allow you to create a new project using the WSDL (file or URL) and view and manually create requests against a service.  You can see the raw data exchange (HINT: There can be additional required HTTP headers you need to pass.  SOAPAction is one that is almost ALWAYS used) and then using whatever language you want create a web client that POSTs the XML (templated so you can change various parameters) and then parse the resulting XML response to get the data you want.  Every programming language has a decent XML parser so that shouldn't be a problem (although sometimes you have "massage" the resulting XML).

Here is a simple example of a client in PHP:

        $soap_url = "https://blahblah.com:1234/Service";
        $soap_act = '"/SomeCall"'; // Use SoapUI raw view of request to find this
        $soap_xml = <<<ENDOFFILE
        <soapenv .......... </soapenv ...............
        ENDOFFILE;

        $resp = \Httpful\Request::post($soap_url)
            ->body($soap_xml)
            ->sends('text/xml')
            ->addHeader('SOAPAction', $soap_act)
            ->timeoutIn(10)
            ->send();

        // There are ways to make the PHP XML parser handle namespaces but usually
        // we don't need them so make them simple XML elements instead
        // (eg. s_Envelope)

        $xml_str = str_replace('<?xml version="1.0" encoding="UTF-8"?>', '',
                               $resp->body);
        $xml_str = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2_$3", $xml_str);
        $xml_str = preg_replace("/ \w+(:\w+)?=\"[^\"]*\"/", "", $xml_str);

        $xml = new \SimpleXMLElement($xml_str);
        $body = $xml->xpath('//s_Envelope'); // Can use this to narrow it down

        $array = json_decode(json_encode((array)$body), TRUE);

        // Now you can access the data using $array['key_name'][1] etc.. etc..

        print_r($array);

Good luck and hopefully this will save you some time! :)

Monday, August 3, 2015

How to run a cronjob on the last day of the month

You may have to escape the % sign for direct crontab entry depending on your cron software.  The example runs on the first minute of the last day of the month and starts trying for last day on the 28th (to deal with Feb).

0 0 28,29,30,31 * * [ $(date +\%d -d tomorrow) = “01” ] && command_you_want_to_run

Friday, August 22, 2014

mysqldump warning skipping mysql.event table data

If you don't want to give your "backup" user Super permissions and you don't use events you'll be stuck with an annoying warning:

-- Warning: Skipping the data of table mysql.event. Specify the --events option explicitly.

Every time you run a scheduled backup of your mysql database.  You still want those cronjob emails with any database backup errors but you don't want that one.  This might help you:

mysqldump --routines -u$USER -p$PASS -h$HOST -r$DIR/$FILE $DB 2>&1 | grep -v 'Skipping the data of table mysql.event' 1>&2

What it does is redirects all errors from mysqldump to STDIN.  It then greps out the event error and redirects any other errors back to STDERR.

The key is that you MUST use the -r option  (write to a file directly to a file rather than STDOUT) with mysqldump.  If you have other warnings you don't want to see you can use:

... | grep -vE '(warning 1 substring|warning 2 substring)' 1>&2

Another option might be to use Cronic.  Good luck!

Wednesday, February 27, 2013

Windows device manager / colorspace correction refreshing

If you are experiencing constant refreshing of your device manager or color correction screens in Windows 7 or 8 you will eventually do a search and find lots of information about loose device connections, bad drivers or other types of issues. After several days of uninstalling drivers and disconnecting various devices in my system I stumbled upon the root of the problem. Windows identifies some remote network services (multimedia servers) as "devices." These devices do not show up in the device manager. My issue was that windows automatically discovers these "multimedia streaming services" on your network (other PCs) and when they enter and leave the network (who knows why) they are dropped and added to your devices repeatedly. They might show up under "Plug and Play" devices on Windows 7 but on Windows 8 they show up on a "Devices" screen. If you remove them (right click, "Remove Device") the problem goes away. This might not solve your problem but I wanted to put this here for the search engines. Good luck.

Wednesday, October 10, 2012

Logging STDOUT, STDERR and outputting STDERR

You may find yourself with the need to log both STDOUT and STDERR but also display STDERR. A perfect example is when running cronjobs on Linux. As we all know getting too many notifications will result in the important notifications being lost in the noise. The solution is generally only to show errors. The problem is that those errors might lose context without various debug information. This is where I/O redirection becomes handy. Because we only want to receive emails (cron automatically sends all STD output as an email to the job owner) for errors we can use the following:

<command> 2>&1 >>blah.log | tee -a blah.log

What this does is runs <command> and copies STDERR (file descriptor 2) to STDOUT (file descriptor  1, 2>&1) and then redirects (>>) STDOUT (file descriptor 1) to blah.log.  Because of the order STDERR is not being appended to the blah.log.   That happens in the pipe to the tee command.  The tee command takes input from STDIN, adds it to a file and then echos that output to STDOUT.  The net result is that we now have STDERR from <command> being emailed to us should we use that series of commands in a cronjob.

Friday, April 13, 2012

BlueHarbor Auto Refinance Ripoff

Do not waste your time trying to refinance through BlueHarbor Auto.  You'll give them all your information and they will secure you a good rate and then tell you about all the "fees" involved in completing the loan.  $199 financing fee.  Ok, everyone charges those.  $87.50 re-titling fee.  HUH?  Oh and btw, you have to sign up for our extended service contract on the vehicle.  At this point I told them I was no longer interested in their services.  I found this company on Bankrate.com.  I really do not think that Bankrate knows that this company is trying to rip people off to save a few points on a loan.  I'm going to be contacting them.  If they don't do anything about it I'd say it's safe to assume that Bankrate has gone down the tubes.

EDIT:

I guess one good thing came out of this situation.  I discovered Pentagon Federal Credit Union.  They had better rates than the above mentioned and their customer service is incredibly helpful and courteous.  Also, the entire application for membership ($5) and the loan (free) are handled online.  After a couple days my loan (refinance) was approved and I had the pay-off check for the current lender.

Thursday, April 5, 2012

AR.Drone 2.0

I received my AR.Drone 2.0 the other day and had a chance to play around with it a bit.  The biggest problem I see with the device is the horrible battery life and they have not released AR.Free Flight 2.0 for Android devices yet.  AR.Free Flight 1.9 does work fine with the AR.Drone 2.0 but there is no video support and FF 1.9 doesn't support the 2.0 feature of using the "Absolute Control" mode.  If you use the accelerometer with 1.9 you must keep the camera pointing forward to have the drone respond intuitively.  For now I'm just using it in 2 stick mode.  Here are some pictures of the un-boxing.








Here is a video of my second flight with the device.  It isn't very long because I'd already played with it a bit and the battery was nearly dead:


If you have any questions let me know.

Additional close up photos of the battery:










Added another short video of flying the AR.Drone 2.0 with AR. Free Flight 2.0 on a borrowed iPhone.  I used Absolute Control which is awesome.