The Term (Domain) Is Not Allowed

While configuring a domain within Google Apps, you may see the error message “ The Term [Domain Name] Is Not Allowed ”:

This error can come up due to several problems. The most likely issue is that the domain has been configured as an independent domain, rather than as an alias domain. A quick fix to this issue is to delete this domain from Google Apps, and then to re-add it. When the prompt comes up to select independent domain versus alias domain, select the alias domain option.

Slashdot Downtime Notices

I like to collect samples of downtime notices and error messages from popular websites; it’s always fascinating to see how sites handle messaging on technical issues.

Here’s an example downtime notice from Slashdot:

Here is the message in context:

Retrieving URL Parameter Values With Pure Javascript

Here is a short but incredibly useful piece of Javascript: it retrieves the value of a named URL parameter. For example, if the current page’s address is index.html?example=true&name=vinny this function would return vinny if passed the name name , and it would return true if passed the name example .

function getParameterByName(name) {
    var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
    return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}

A note of warning: calling this method repeatedly is inefficient, since the regular expression needs to be repeated every time.

Webmaster Tool Has Not Been Enabled

While configuring a new Google Apps account for a customer, I encountered the error below:

Here’s how to fix this. First, go to the Users tab, then click Services :

Type in Webmaster Tools in the search box directly under the Services tab:

Click the On button next to the Webmaster Tools label:

Remember to save your changes:

JSON, Javascript, and JSONP MIME Types

A quick note about MIME types: JSON responses have a MIME type of application/json while Javascript files use application/javascript . JSONP is a JSON object within a Javascript function call, so it shares the same MIME type as Javascript ( application/javascript ).

With that said, there are some browsers (largely older browsers) and applications that don’t understand the application/json MIME type. They may require JSON responses to have a content type of application/javascript , application/x-javascript , or text/html . If you encounter issues with handling JSON, it’s a good idea to try changing the MIME type – it may solve the problem.

As a reminder, here’s how to set the content type of a response in Java (other languages have similar functions):

resp.setContentType(mime_type);

The resp object represents a javax.servlet.http.HttpServletResponse reference.

Google Services Modifying Site Navigation

A quick note about some Google UI changes: Google is in the middle of removing the top black navigation bar.

Previously, Google had a top nav bar linking to various Google services:

Now that navigation bar is gone:

Google is popping up a little note to explain the changes:

In short, the grid icon drops down a list of various Google services to choose from:

Generating Callbacks For JSONP Code

Here’s a code snippet demonstrating how to wrap JSON text within a JSONP response.

The text of the JSON object is in the string json. The variable resp represents a HttpServletResponseobject. Callback represents contents of the HTTP parameter callback , which should be set with the name of the Javascript function to call. Before calling this code, it’s a good idea to validate that parameter.

String callback = req.getParameter("callback");
String json_text = callback + "(" + json + ");";
resp.getWriter().println(json_text);

Here’s an example of a simple JSONP response:

findIP({"ip": "8.8.8.8"});

This response will call the JS function findIP (the callback parameter contents), with an object containing the property ip (the JSON data).

Java GET Using java.net

Here’s a simple code snippet showing how to fetch the contents of a URL. The URL to fetch is in the string url_string , and html stores the contents of the fetched file.

URL url = new URL(url_string);
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
String html = "";
String line = "";
while ((line = reader.readLine()) != null) {
    html += line;
}
reader.close();

This code may throw a java.io.IOException if an error is encountered while fetching the URL.

This code requires the below imports:

import java.net.URL;
import java.io.InputStreamReader;
import java.io.BufferedReader;

Access-Control-Allow-Origin In JSONP Responses

A quick note for today: JSONP responses need to include an Access-Control-Allow-Origin header set to a wildcard. If this header isn’t included, browsers won’t allow JSONP responses to be read in by Javascript.

The header key and value should look like this:

Access-Control-Allow-Origin: *

Here’s an example of this header in Java:

resp.setHeader("Access-Control-Allow-Origin", "*");

The variable resp represents a HttpServletResponse reference. Make sure to add this line before writing the body of the response to the client.