Sunday, September 06, 2015

Facebook + Chrome: Please try closing and reopening your browser window.

Symptom:

You get "Please try closing and reopening your browser window." when posting a message on Facebook. But closing the window does not get this message to go away.

Possible Cause

In my situation, this was due to having the Cross Origin Resource Sharing mode enabled on my Chrome using the CORS extension. By turning it off, the problem went away.

This is often considered as a non-secure mode and Facebook especially will not allow some features to be used like Posting and Messaging when the web request has been modified.

The CORS extension is used by developers like myself to access resources from different web servers and it is not normally needed for consumer use, so if you do get into this situation, you may actually have some other mechanisms/extensions which is causing the same effect, and that could mean that your Chrome may be infected with malware so be sure to check your extensions and remove anything that you do not understand what they do.

Also try with a different browser and if it only happens on Chrome (or vise versa), then I will clean up the browser.


Friday, June 19, 2015

Hibernate Envars, ValidityAuditStrategy Fails with Cannot update previous revision for entity

Symptom:

You have configured for the org.hibernate.envers.strategy.ValidityAuditStrategy with your Hibernate Envers to audit trail SQL table records with the following exception;

java.lang.RuntimeException: Cannot update previous revision for entity

Root Cause:

This happens when the table that already has records and you add the Envers auditing with ValidateAuditStrategy "after the fact". In other words, there are legacy records which were not originally audited.

Basically, the ValidityAuditStrategy was designed only with the assumption that you started using it from completely no data in the table and its related tables. It requires the initial INSERT record of the very first record of all rows with a unique record ID.

This issue has been logged in the Hibernate JIRA HHH-8456

Workarounds:

If you can afford to disable the ValidyAuditStrategy, that will log the entries.

The initial revision entry must be inserted into the newly created _AUD table for every existing legacy record.

This problem may be worked around by using the following tool that's available from the GitHub.

https://github.com/hydra1983/hibernate-envers-tools

Sunday, May 24, 2015

IntelliJ IDEA 14.x How To Resolve "routes" Activator/Play Object

Problem:

You just imported the SBT project of Activator or Play framework app in IntelliJ IDEA (14), and you found that you "routes" among other symbols do not resolve.

Root Cause:

You are lacking the dependency for the auto-generated routing class.

Solution:

You can add Module Dependency to classes_managed. This is located in the target/scala_2.xx/classes_managed

I originally posted a similar solution, but this one is much better and works with Play 2.3 or later. This video shows you exactly what you will need to do.



Thursday, April 30, 2015

Windows File History (7, 8 and 10) - One Of the Most Useful and Overlooked Feature

You are probably using some type of backup software from a commercial vendor. I have been too, but recently I stopped using it and switched to a Built in File History.

If you are used to Mac OS Time Machine, it comes as close to that, but in some ways better because you can still control what gets backed up and what does not. Like the Time Machine, you can ask it to back up hourly or even every 30 min of recent file changes and then automatically prune off old backups.

Another advantage is that it is very well integrated with the power control of your system, especially a laptop. I was using another vendor's backup software and any time I wanted to sleep or shutdown, it refused to do so because it was in a middle of a backup. Not with this, you can go to sleep, close the cover and you won't get in a situation where you have a hot battery drained laptop when you pull it out of your case.

In my situation, what I needed was automated hourly backup of some of my important documents, especially the code I am currently working on (but not quite ready to commit to Git). But if you are a teacher or an accountant just keeping the Office docs that works pretty painlessly.

Where to Backup?


Cloud backup is very popular, but the problem is that you are not always on the most reliable network especially on laptops. You could also be in flight and working on documents or code. Fortunately, most laptops have a memory card slot. So I advise that you buy as big of a memory (SD card) as you can afford, I would say get at least 64 GB. So just plug it in, format it in NTFS.

Since this is a solid-state memory, it does not consume much power and you know you have a backup available to you pretty much anywhere.

How To Enable and Configure It?





  • Go to your control panel and find File History which is under System and Security.
  • You can now enable the feature and select the destination "drive" here.
  • After the drive has been configured, click Advanced Settings

  • You can configure how often you want to back up.

Selecting Items to Back Up

Here is another cool thing about this. You can easily manage which stuff on your system is backed up. The key answer to " how to select which folder to backup" is that anything included in the Libraries part of your Explorer is backed up. By default your Documents, Music, Photos and Videos are backed up. In the picture below I have dragged in WinguMD folder which contains my work stuff. Note that dragging the items in the Libraries folder does not move the folder there, but it just like the shortcuts but backups are enabled.  I would not back-up videos if you have a small memory card.

On a side note, I have been wondering what the Libraries were for the longest time. Now we both know what this is.





Windows 10 Lost Ability to RDP Into the System

Symptom:


You upgraded to Windows 10 and now you cannot RDP to the system at your home network. (I do this a lot because I use Mac at home and RDP to my laptop which is Surface 3).

One of the Root Causes

In my situation, all of my WiFi connection went to Public which automatically turned off just about any incoming traffic to it from the Windows Firewall. This is a good feature. Do not turn that off.

To Make Your WiFi Network to Private

This, I guarantee you will take some time as there has been a big change.

  1. On your desktop, click the New Notifications icon on the task bar. That' far right and looks like a Messaging icon.
  2. Right click over WiFi and "Go to Settings."
  3. This is where you will be lost, especially if you have many spots.
  4. On the list of WiFi access points scroll all the way down.
  5. Click HomeGroup
  6. If your system is like mine, you will get a chance to enable the HomeGroup on the network you are on.




Friday, April 03, 2015

VertX Development with IntelliJ IDEA

Problem:


How can I develop Vert.X Verticles with IntelliJ IDEA?

Some Tips (May not be a Solution):


I have been trying to evaluate the Vert.X system (after getting my head spin around Activator + Scala), and believe or not, I have been in C/C++/C# woorld all this time and manged to avoid Java altogether (yes, you can have a whole career based on C# and JavaScript only!). So I am sure there are some figments of ignorance in this article. If you find anything wrong, please let me know as that will help me a lot.

As I stared on this path, I did find many other articles all over the net but I have found that most were written by seasoned Java developers directed to other still-a-bit-seasoned Java developers. This article is written by someone who hardly know much about Java. So if that's your situation this will help a lot, at least get to the point your Verticle to run and debug under IDEA.

Much of the hurdle in dealing with the Java environment (not so much with the language itself) is that  there is initial confusion as where all the classes come from (yes CLASSPATH) and there are more than one ways of doing things right. As a result it has gotten very time consuimg tasks to learn each of the paradigm. For example, there are Maven, Gradle and Ant to handle the builds just to name a few then there are things like Scala and Groovy and such to even confuse us, and on top of various Java frameworks for example Vert.X is one of them and Activator is another, then there are even more stuff like Spring, Netty etc.

Each serves slightly different purpose but they also get combined to do a lot of similar things like serving up Web APIs and web pages and such.

So with that in mind, here is probably very overly simplistic description of how to work IntelliJ with VertX development.

How To Start


I started with both Gradle based project initialization to Marven based. I have found that the Maven based one is a bit less intimidating to approach and lot simpler overall, so I also advise you try the Maven way first then do other stuff.

The most of how to set up the Maven based project skeleton is described on Vert.X document on THIS PAGE. But that page does not give you much more info on how to debug etc.

So first off, follow the directions on that page until you are all done and typed in "mvt idea:idea" to create the IDEA project. Then you can open the top level of your project (where you will find the IDEA files like .iml, .ipr and .iws). This will first convert the project format. Let IDEA handle that.

Integrating the Maven Project is the Key


After you open the project, and after a few minutes IDEA will say, it has found a Maven project and if you want to import it. Say yes. This will cause a small Marven Tab on the right hand side of the IDE.



What I have found out is that clean, compile and package commands (goals) are very handy.

For example, let's say you have added a new Verticle class. I have found that first doing the clean then do compile will make it appear in the target directory.

Now if you want to create the mod directory containing your Verticles, then doing package.


  • For each of the action, which is called Goal in Marven, select an item then press the Green start button above to execute.
  • clean will clean out any derived objects
  • compile should be used each time you update the source
  • package will create the mod directory in the target
  • install will also create the mod directory on the top level of the project, but what will be install is not always updated when you change the source.

Starting Verticles from Within the IDEA

For the reasons that I do not completely know, if you run "vert runnomd com...." stuff from the top directory of your project, it can find your module. So do not be afraid to use that option. But if you want to debug your updated verticle code each time via the mod then you can first do the "package" Marven goal first, then you can "cd" into your "target" directory then you can run the latest version.

Also not shown in this but instead of specifying Make before you debug, you can specify the Maven "package" goal which will always recreates the mod directory with the latest code. You may want to do that. Make takes forever to build, so I would at least switch to "compile" verb of the Marven and remove the Make action.





Adding or Running Your Own Verticle From Within IDEA

This is still an area that is a bit of mystry to me, but here is what I know so far and it does work, but the Vert.X documentation does not tell you how, so I had to do some experimentation to find what worked for me.

  • Go a head and add a new Verticle class under src/main/java/com.blah/ directory.
  • Do not remove PingVerticle.java If you do remove it what will happen is that it will break the build because there are some "tests" that will call this. You could, in theory, remove the tests too but why bother when you actually do not have to remove it.
  • If you want to run your own Verticle, you will have to go inside the "resources" directory, find mod.json and edit it to contain your class under "main": 
  • Now do a clean and then package and you will have your new Verticle to launch when you do runmod com.blah... stuff.
I am sure there are some errors in my post, but I feel that I have given you enough information that allowed me to do what I wanted to do. As I find more information, I will plan to update this document.




Thursday, February 12, 2015

Method with C# Generic Cannot Have == (Equality) or Comparison Operator

Problem:

You have written a function like the following;

       static Boolean IsV1GtV2(T v1, T v2)
        {
            return v1 > v2;
        }

And you get a compiler error stating;

Operator '>' cannot be applied to operands of type 'T' and 'T'

The error is reasonable, since there is no gurantee that some generic type T would support comparison.

The Following will Also Break

So next you could have tried.

return (int) v1 > (int) v2;

And you still cannot get that to work. 

Solution

The only real way it works (for me at least) is to work the code this way. 

            if (typeof (T) == typeof (System.Int32))
            {
                return (int) (object) v1 > (int) (object) v2;
            }

You wold, of course, need to add this type of block for every possible type that you plan to use.







Sunday, January 11, 2015

Fixing Plantronics Voyager Legend Audio Drop Issue + Activating Google Now

I have been a big fan of Plantronics. They come up with innovative product and of course, my friend works there too!

I have also been using Motrola MotoX for some time and I have had some issues with my Voyager Legend for some time for which I finally got around to address.

Frequent Disconnect Issue

There are several forum complaints that the Legend disconnects. I have the same issue with it. One thing that can help resolve this issue is to download the Firmware Updater from the company's web site. This requires a direct USB connection to your Mac or PC.

To do that, go to This Support KB Article.

The Talk Button Does Not Turn on Google Now Voice Recognition


With an iPhone or other Android phones when I press and hold the Pickup button for a few seconds, you can activate Siri or Google Now for most phones, but that stopped working (or never worked until now) on my Moto X.

This is more likely specific to Moto X with the hands-free operation mode. In my case Google Now, by default, turns off the Bluetooth Headset Mode OFF. By turning that feature on, you can gain back the mode that you can press the pickup button for a few seconds.

Here is what you need to do;


  1. Open Google Now uses the Google Now gesture (swiping up on the screen.)
  2. Scroll through all the cards until you see the last one on the bottom.
  3. You should now see the familiar (vertical set of 3 dots ...) setup icon on the bottom right of the screen. Tap that.
  4. Tap Settings
  5. Tap the Voice icon
  6. Enable the "Bulethooth headset" mode. It says Records audio through Bluetooth Headset if available. The term "record" does not sound quite appropriate, but what it means is that it can pick up the audio from the headset after pressing the pickup button. 





Friday, October 03, 2014

VS 2010: The key file may be password protected error When Building

Symptom:

  1. You pulled a fresh project (i.e., the porject you never had on your machine) from a source control such as Git
  2. You build it on Visual Studi 2010 (or even may be later version) and you get the following type of error and cannot proceed.
  3. You know you have the .PFX file in your project.

Error 1 Cannot import the following key file: XYZZY42.pfx. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name: VS_KEY_07B0CF4FE777D718

Root Cuase:


It just simply cannot locate the cached password (I don't know where it stores it.)Fix

If you do know the password and the fix is easy. If you don't know it might as well create another new pfix file of your own.

Steps to Fix:


1. Go to the Property of the Project

2. On the left panel, click Signing

3. Under "Choose a strong name key file" pull it down and select Browse, and select the same key file as indicated. This will prompt you the password and you should be all set to go.



Tuesday, September 09, 2014

Windows 8, IIS WCF Service Fails to Add Service Reference

Symptom,


When I tried to add a WCF Service Reference to a WCF Application hosted on IIS 8 (Windows 8), I got the following type of message,

'http://localhost/MyDataServices/DataService.svc/_vti_bin/ListData.svc/$metadata'.
The request failed with HTTP status 404: Not Found.
Metadata contains a reference that cannot be resolved: 'http://localhost/DataServices/DataService.svc'.
The remote server returned an unexpected response: (405) Method Not Allowed.
The remote server returned an error: (405) Method Not Allowed.
If the service is defined in the current solution, try building the solution and adding the service reference again.

Root Cause


The IIS configuration is incorrect or has become corrupted in some ways.

How I Got It To Work Right

  1. Uninstall and Reinstall IIS from Programs and Features
  2. When re-installed the IIS, be sure to restart the computer. The OS will not ask you to restart on re-install, but in my case the IIS was completely stuck.
  3. Next and most important is this, Be sure that in the .NET Framework 4.5 Advanced Services, and under WCF Services, the HTTP Activation is enabled. 


Side Notes/ Don't Go There...

  • First test with the IIS Express built into your Visual Studio. If that does not work, then there can be a coding issue.
  • Do not bother with editing the web.config file yet (to create behaviors and endpoints). The default ought to work.


Tuesday, August 26, 2014

dcm4chee 2.7 Mac OS Mavericks Installation Note

dcm4chee is a DICOM Server system (and a lot more) that runs under Java runtime environment. It can store medical images and send them out in the DICOM format. If you are reading this article, you must have been familiar with the medical imaging environment in your institution, so I am not going much deeper than that.

I had a chance to install dcm4chee on my Mac OS Mavericks today. I would like to supplement the instructions that have been given on their home site. I think following these steps should save you a couple of hours of finding and trying.

JBoss-4.2.3GA Installation

JBoss must be copied from http://sourceforge.net/projects/jboss/files/JBoss/JBoss-4.2.3.GA/
The link on the instructions page is broken.

JDK Related

I have used jdk1.7.0_09. This is available from the Java Download site (note, at this time of writing the latest JDK is Java 8). 

The JAVA_HOME environment variable should be pointing to (for jdk1.7.0._09) to /Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home

Note that Contents/Home in the path.

If you are testing this on your own environment, then JAVA_HOME should be set in your ~/.bash_profile file.

So it would add a line that looks like;


export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home

Fix the ARR Schema Creation Script for the Latest MySQL

  • The latest version of MySQL uses engine= instead of type=  You will need to correct this.
  • It is also best to manually create the schema even though the document says it will auto-create, it actually does not.

mysql -uarr -parr arrdb < dcm4chee-arr-mysql.ddl

Sunday, August 17, 2014

CAR IT: Mazda CX-5 Fails Download Text Messages

Symptom:


You have a compatible Android phone (like the MotoX or Galaxy) but the text message download fails. Note that iPhone is not compatible with your Mazda.

Root Cause:


You have too many messages.

Fix:


Remove and clear all previously stored text messages. Keep the limit to about 200 or less.

Note also that having your SMS mode in Hangout or not does not make the difference. If the message count is small enough it will work both ways.

Sunday, July 20, 2014

Understanding the C# Yield

We have all seen the new "yield" keyword in C# at one point or another, but if you are like me, sometimes, we just say, "what's the big deal, I can do that myself" and move on.

But this weekend, I took time to get a bit more understanding of "yield."  I looked around on the net to to see various examples, but none of them still made sense to me.  So I decided to write a bit of code to experiment. The example included on this post contains the complete code that you can run as a console app.

I found that most examples show the use of the yielding function from within another loop, and that did not make much sense to me, since if you do that, then I would think that why not even bother having a separate loop. But hardly no examples showed me to use an Enumerator to iterate through, throughout a part of program, and that's what I plan to demonstrate here.

First, a bit about the example. Let's say that we need a program for the shipping department of a computer store and you want to make sure the employees will not forget to pack each part in the right box. You would have a list of parts like monitor, keyboard etc., and display the instructions what goes where etc.

What I wanted to get out of this example is to see if my assumptions are correct, and in one case I was not, and glad I caught that by writing this example.

So here is what I have learned;

It's a Way To Implement the Deferred Computation Pattern

  • The yield consutruction is probably good for performing complex calculations within a loop and especially the computation for a specific part of iteration is not performed until you request it, you might save resource or time.

    This approach appears to be very effective if I create an Enumerator then use MoveNext() to the next item, and that's where its power lies. For example, accessing a database or looking up something from a web service. You can defer the computation like this just until you call MoveNext(), and you do not need to write a special state management between the calls. Come to think of it, that's how LINQ works and that's the core of IEnumerable is about. Makes sense!

    We can certainly do this without yield, but to do the same thing, I have to keep track of the states and either store them as private data members or in a separate class structure and pass that back and forth. Also some loops take a decent effort to initialize, and in the yeild approach, we can certainly reduce that effort.

    As the functional programming approch recommends, the more states we create and must manage locally, they tend to cause hard-to find/fix bugs.

    So the advantage with this is a much simpler (hence reliable and testable) design.

My Bad Assumption Cleared

  • If you create a foreach loop again, the iteration will reset from the position 0 for each loop. I misunderstood this aspect. I thought if I have left the loop (say picked up first 3 items) and then did another loop for the next set, I thought I can pick up from where I left off. It does not work that way. So you have also been warned now.

The Code

using System;
using System.Collections.Generic;
using System.Linq;

namespace Yield
{
    class Program
    {
        static void Main(string[] args)
        {
            var sample = new YeldSample();
            sample.Run();
        }
    }

    public class YeldSample
    {
        public void Run()
        {
            var packingList = new List<string>
            {
                "A: Memory""A: Disk""A: DVD Drive",
                "B: Display",  "B: Monitor Cable""B: Monitor Power Cord",
                "C: Mouse""C: Memory Card""C: Keyboard",
            };

            var itemCount = 0;
            var iterator = YieldPart(packingList);

            var enumerable = iterator as string[] ?? iterator.ToArray();
            foreach (var item in enumerable)
            {
                Console.WriteLine("{0} Done!", item);
                itemCount++;
                if (itemCount == 3) break;
            }

            Console.WriteLine("\r\nBad Example Below. This will begin the loop from the start again.\r\n");
            itemCount = 0;

            foreach (var item in enumerable)
            {
                Console.WriteLine("{0} packed again!", item);
                itemCount++;
                if (itemCount == 3) break;
            }

            Console.WriteLine("\r\nExample Using the Enumerator\r\n");

            var items = enumerable.GetEnumerator();

            items.MoveNext();
            Console.WriteLine("{0} Done!", items.Current);
            items.MoveNext();
            Console.WriteLine("{0} Done!", items.Current);
            items.MoveNext();
            Console.WriteLine("{0} Done!", items.Current);

            Console.WriteLine("\r\nTake a break!\r\n");

            items.MoveNext();
            Console.WriteLine("{0} Done!", items.Current);
            items.MoveNext();
            Console.WriteLine("{0} Done!", items.Current);
            items.MoveNext();
            Console.WriteLine("{0} Done!", items.Current);

            Console.WriteLine("\r\nTake a break!\r\n");

            items.MoveNext();
            Console.WriteLine("{0} Done!", items.Current);
            items.MoveNext();
            Console.WriteLine("{0} Done!", items.Current);
            items.MoveNext();
            Console.WriteLine("{0} Done!", items.Current);

        }

        public IEnumerable<String> YieldPart(List<String> parts)
        {
            foreach (var part in parts)
            {
                var dest = "";
                if (part.StartsWith(("A:"))) dest = "main carton.";
                if (part.StartsWith(("B:"))) dest = "monitor carton.";
                if (part.StartsWith(("C:"))) dest = "accessory carton.";

                var phrase = String.Format("Put {0} in the {1}", part.Substring(3), dest);
                yield return phrase;
            }
        }
    }
}

Thursday, July 17, 2014

Google Drive Windows & Mac - "Sign into a different account" does not work

Symptom:


You have either left a company that was using the Google Apps, or you may have recently removed a Google Account and then changed to another. Now you try to connect to the Google Drive, it won't let you change the account, instead it remembers your previous account, and clicking the "Sign into a different account" performs nothing.


Do Not Go Down This Route!


First, it took me about 8 hours to solve this fairly serious flaw and I also checked on the net to see if there has been any solutions.

  • There is no need for you to go to the C:\Users... \Drive folder to remove it. 
  • There is no need to uninstall.
  • There is no need to run CC Cleaner
  • There is no need to clear the history of Chrome. It's not where this issue is happening.
  • There is nothing in the registry so don't look there.

Root Cause:


It is the IE caching the log-in credentials. Not the Chrome. But to make the matter worse, you need to log-into the new Google Account in the IE to clear the previous credential that was cached.

The Fix

I will now explain the steps.

First, go to the Internet Options of the IE, then Delete the browsing history.




Now this is the important part. By default "Preserve Favorite website data." You would not want to do that. So you must UNCHECK that box. The illustration below shows it is checked. Again uncheck this (if you know what to do, you could just remove the cookie for your previous account.)


Wait for the cache to be cleared, then, next thing you need to do is to Sign In to Your New Google Account with the User and Password of the new account.




Mac OS Mavericks Procedure (Inconclusive but Worked For Me)


You will run into the identical problem if you also have a Mac. You are also likely to have Safari and Firefox installed, therefore you need to do this with Chrome, Firefox and Safari in that order.

First, clear the stored password from every browser you have.

Then close all the browsers and do the following steps on every browser from Chrome, Firefox and then Safari in that order.

  • Go to http://www.google.com and if it is still logged into a Google account, log out of it and then log back in.
  • Go to http://drive.google.com now and click your profile photo on the top right of the page. If you do, you should see Add Account button. If you do not see this button, log out and log back in. If you have more than one Active account, then you should add those now.
  • Close the browser and do the same to the next browser.
When you are all done with them, you have cleared the any cached log-in information and you can now re-launch the Google Drive app and you should be able to log-in.

You may still get the following dialog box after all of that;




This is due to the leftover config files that's been on your ~/ (home) directory. There are two places
  • Remove everything in the Google/Drive folder  
    • /Users//Library/Application Support/Google/Drive
  • Remove 
    • in /Users//Library/Preferences

    • com.google.GoogleDrive.plist com.google.GoogleDrive.plist.lockfile



Mazda IT: TomTom Navigation Map Starts to Spin Aound For No Good Reason

Symptom

Around June of 2014 or later, your Mazda TomTom (CX-5 in my case) map start to jigger and spin around and also indicate "acquiring a signal."

What Fixed It

Update the firmware on your TomTom, this is possible by going to the TomTom web site and then downloading the TomTom Home software then update the SD card.

Visual Studio 2012 Installation Hangs

Note: You might be wondering why this is about VS 2012 and not 2013. It turns out that I had to install 2012 for a gig that required it, then I ran into this problem.

Symptom:

You started to install Visual Studio 2012 (Pro in my situation). You have tried the Web install as well as the DVD install and it launches the installer, but shortly after there is no window and installation is hang up no matter how long you wait.

Fix:

Uninstall .NET Framework 3.5.1 (or possibly any other ones) before proceeding to start the installer. Your .NET Framework is likely corrupted in the manner that VS 2012 would not work.

Friday, July 04, 2014

IIS 8 - Get 405 (Method Not Allowed) on DELETE

Symptom


You have implemented an Web API interface (in my case Web API 2) for Delete operation. Your GETs as well as POST works, but when you try to execute DELETE, you get a 405 error code.

DELETE http://localhost/MySite/MyApp 405 (Method Not Allowed)

What Worked For Me


Since I have explicitly set up my environment not to get into CORS situation, it was clear to me that something else was an issue. However, if you are using the built-in IIS from the Visual Studio to test your interface, it will come with a special port number and it is highly likely that you are running into the CORS situation so be sure to check that as well.

What fixed was to modify a part of the web.config file in the following manner.


By removing ExtensionlessUrlHandler-ISAPI-4.0_64bit, it started to work.

The Microsoft KB Article http://support.microsoft.com/kb/224609 was most helpful in deriving this solution for me.

According to the above article, the configuration catches "like" configurations first and thus by the time it is at your level of web application, the configuration is basically "messed up."


Side Note


Also, I did not have a proper configuration on my web interface declaration and after above issue was fixed I was starting to get an error code 500. This goes to say that if you get the error 500, the DELETE is trying to execute and you are out of the web.config issue.

In my case, I forgot to add "{id}" in my Route declaration.

      [Route("{id}")]
        [HttpDelete]
        public void Delete(Guid id)
        {


Thursday, July 03, 2014

Super Beginner Guide to AngularJS - Uncaught Object

OK, I will admit. I am just starting out learning AngularJS and already spent numerous hours where an experienced programmer won't step into. Well, just a few months from now, though, I won't be in that situation, nor I would remember the kind of traps I got into. So it's time to blog about them because if I ran into them, you would too.

What to Do If You Get Uncaught Object on Chrome Console

So your text book author said, "you can test in any browser you choose so long as it is Chrome." And you believed it, didn't you. You tried your first program, and you get the following message in the JavaScript console.

Uncaught object
  (anonymous function) angular.js:78
  (anonymous function) angular.js:1751
  ensure angular.js:1675
  module angular.js:1749
  (anonymous function) app.html:9

Unlike a debugging in C# or Java, it does not tell you where and what the issue is. Very frustrating. You even set a breakpoint where the issue was found and it says "missing ngLocale" module to that effect when you have not even plan to reference such a module in your code.

This turns out to be a current (as of July 2014) bug in Chrome. May be it has been fixed by the time you read this, but it goes to say that when debugging JavaScript it might be worthwhile trying another browser than just Chrome. Especially Firefox and IE are great choices as the JavaScript implementation is totally different from Chrome or Webkit based.

Error: [$injector:nomod] Module 'undefined' is not available! You have either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.3.0-beta.11/$injector/nomod?p0=undefined angular.js
Error: [$injector:nomod] Module 'mtSample' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.3.0-beta.11/$injector/nomod?p0=mtSample angular.js

Now at least here the debug console output will be more specific as to the nature of the problem. For above example, I have purposely eliminated a comma after "mtSample" from angular.module("mtSample" ["ngRoute"]).

Go Ahead, Try the IE too!

I know, I know, we are supposed to sit and code at Petes with our latest Mac Books and bash the IE ( I am writing this artile on my iMac by the way). But you will be surprised to know how much changes Microsoft has made to embrace the latest open source technology. You can even run Linux on Microsoft Azure now!

So, even on the IE, the message is clear! In fact, it is the cleanest and clearest of all in this specific example. So at least, let's give some hands to the Micrsoft folks. We should not lose a sight that as software engineers our task is to get our job done. I would use any tool I can lay my hands on.



A Side Note - Do Not Mix and Match Angular Libraries

I have accidentally mixed in additional Angular components (like routing package) from the latest into the rest which was in a pervious version. If you do this, you will run into a very similar issue. When in doubt, refresh the complete AngularJS library to the same perstine version.


... to be continued.

Friday, June 20, 2014

Avoiding CORS on localhost testing via Simple Node.js Proxy Server

What Is CORS Anyway?

Before I get deeper into this topic, I just want to tell you a bit about CORS. CORS an abbreviation of "Cross Origin Resource Sharing", and it is described in this Wikipedia Article.  To make a short summary of this issue, basically, what it means is that there is a security mechanism in just about every modern browser that prevent you to perform AJAX requests from a different server than where your original content came from.

For example, a typical tutorial lesson you get from books may require that you have a simple web server running on Node.js (really easy and cool) then a separate database server that's serving up JSON data (for example, via a Deployed service), you would do something like http://localhost:5000 for your web contents and then http://localhost:5500 for JSON data server. That triggers CORS.

Of course, if you ask most experts, they will say, the answer is easy. They will say just enable CORS on the server side. But it is not that simple. This is a blog about answers that experts do not know how to answer after all.

The reason I am writing this article is because I spent a couple of days to explore different ways of resolving this issue when I was writing some local development and testing environment to learn Angular.js

Because of a very specific way Angular.js performs the HTTP Get and Post the JSON data, you will find it difficult to get around CORS issue. There is even an extension in Chrome to allow CORS in Chrome but even with it, the POST part of the equation does not work for me. In my case, even if I (thought) modified the header to do;

Access-Control-Allow-Origin *
It still did not give me the result I wanted. I even read that on Firefox, a * is not even permitted, and that a specific host be specified. Pretty tricky if you want to test various browsers too! (*I even implemented a version of Microsft IIS site with web.config edited to allow CORS with no avail!)

It is also even worse when dealing with a localhost than any other hosts to get around CORS.

The Proxy Based Solution

In my situation, what ended up working the best is to completely avoid CORS altogether and make it look as if the database service is coming from the same server. And as a bonus of using Node.js it is quite easy to implement it.

It is basically the use of proxy-middleware (e.g. npm install proxy-middleware) that solved this. In this case, all of my test implementation files are stored under ./angularjs folder, so for example, http://localhost:5000/app.html will pull the file from ./angularjs/app.html

I then created a Deployd server at port 5500 (i.e., http://loclhost:5500) and I wanted my server to proxy all of these requests to that when an AJAX request is made to http://localhost:5000/db  So this means that when I was originally doing http://localhsot:5500/products to get the Products JSON data, I will request http://localhost:5000/db/products

var connect = require('connect')
    , url = require('url')
    , proxy = require('proxy-middleware')
    ;
var app = connect();
app.use(connect.logger('dev'));
app.use(connect.static('./angularjs'));
var proxyFunc = proxy(url.parse('http://localhost:5500'));
app.use('/db', proxyFunc);
app.listen(5000);

Stupid Side Note:

Actually, when I tried this the first time, it did not work, the POST failed, because I had some leftover modifications like this in my code

      app.config(['$httpProvider', function ($httpProvider) {
            //Reset headers to avoid OPTIONS request (aka preflight)
            $httpProvider.defaults.headers.common = {};
            $httpProvider.defaults.headers.post = {};
            $httpProvider.defaults.headers.put = {};
            $httpProvider.defaults.headers.patch = {};
        }]);

Be sure to back out any attempts you've done to fix the issue.  It should just work with a bare-bone POST call of Angular.js HTTP provider!