Code example for EntityTemplate

Methods: setContentType

0
				HttpContext httpContext) throws HttpException, IOException {
			 
			final String uri = URLDecoder.decode(request.getRequestLine().getUri());
			final List<NameValuePair> params = URLEncodedUtils.parse(URI.create(uri),"UTF-8");
			 
			EntityTemplate body = new EntityTemplate(new ContentProducer() {
				public void writeTo(final OutputStream outstream) throws IOException {
					OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
					writer.write("{");
					if (SpydroidActivity.lastCaughtException!=null) { 
						String lastError = SpydroidActivity.lastCaughtException.getMessage();
						writer.write("\"lastError\":\""+(lastError!=null?lastError:"unknown error")+"\",");
						writer.write("\"lastStackTrace\":\""+SpydroidActivity.lastCaughtException.getStackTrace().toString()+"\",");
					} 
					writer.write("\"cameraInUse\":\""+Session.isCameraInUse()+"\",");
					writer.write("\"microphoneInUse\":\""+Session.isMicrophoneInUse()+"\",");
					writer.write("\"activityPaused\":\""+(SpydroidActivity.activityPaused?"1":"0")+"\"");
					writer.write("}");
					writer.flush();
					 
					if (params.size()>0) {
						if (params.get(0).getName().equals("clear")) {
							SpydroidActivity.lastCaughtException = null; 
						} 
					} 
					 
				} 
			}); 
			 
			response.setStatusCode(HttpStatus.SC_OK);
        	body.setContentType("application/json; charset=UTF-8");
        	response.setEntity(body);
        	 
		} 
	}	 
	 
	/**