private boolean registerOrUpdate(Printer printer, String ppd,
			String gcpCommand) throws ClientProtocolException, IOException,
			JSONException {
		HttpPost post = new HttpPost(GCP_BASE_URL + "/" + gcpCommand);
		addGcpHeaders(post);

		List<NameValuePair> nvps = new ArrayList<NameValuePair>();
		if (gcpCommand.equals(GCP_CMD_UPDATE)) {
			nvps.add(new BasicNameValuePair("printerid", printer.getId()));
		}
		nvps.add(new BasicNameValuePair("printer", printer.getName()));
		nvps.add(new BasicNameValuePair("proxy", printer.getProxy()));
		nvps.add(new BasicNameValuePair("capabilities", ppd == null
				|| ppd.length() == 0 ? PPD_MINIMAL : ppd));
		nvps.add(new BasicNameValuePair("defaults", ppd));
		nvps.add(new BasicNameValuePair("status", printer.getStatus()));
		nvps
				.add(new BasicNameValuePair("description", printer
						.getDescription()));
		nvps.add(new BasicNameValuePair("output", "json"));

		post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

		HttpResponse response = httpclient.execute(post);
		int code = response.getStatusLine().getStatusCode();

		String responseStr = EntityUtils.toString(response.getEntity());

		if (code == HttpStatus.SC_OK) {
			JSONObject json = new JSONObject(responseStr);
			if (json.has("message")) {
				lastResponse.setMessage(json.getString("message"));
			}

			if (json.getBoolean("success")) {
				if (gcpCommand.equals(GCP_CMD_REGISTER)) {
					printer.setId(json.getJSONArray("printers")
							.getJSONObject(0).getString("id"));
				}
				lastResponse.setSuccess(true);
				return true;
			} else {
				lastResponse.setSuccess(false);
				return false;
			}
		} else {
			lastResponse.setSuccess(false);
			lastResponse.setMessage("HTTP result code: " + code);
			return false;
		}
	}