private void processResponse(CallReport callReport, Response response, HttpURLConnection connection, int count) throws IOException {
		println("RESPONSE:");

		final List<Variable> contextVariables = workflow.getContext().getVariables();

		final List<Variable> headerVariables = new ArrayList<Variable>();
		final Map<String,List<String>> responseHeaders = connection.getHeaderFields();
		for (final String headerName : responseHeaders.keySet()) {
			if (headerName != null) {
				final Variable newVariable = new Variable();
				newVariable.setId("header:" + headerName);
				newVariable.setValue(connection.getHeaderField(headerName));
				headerVariables.add(newVariable);
			}
		}
				
		final Variable statusVariable = new Variable();
		statusVariable.setId("meta:Status");
		statusVariable.setValue(connection.getHeaderField(null));
		headerVariables.add(statusVariable);

		final Variable codeVariable = new Variable();
		codeVariable.setId("meta:HttpCode");
		codeVariable.setValue(String.valueOf(connection.getResponseCode()));
		headerVariables.add(codeVariable);
		
		for (final Variable headerVariable : headerVariables) {
			println(" " + headerVariable.getId() + " = " + headerVariable.getValue());
		}

		// Add context variables for substitution purpose
		headerVariables.addAll(contextVariables);

		String kind = "out";
		boolean binary = false;
		String contentType = connection.getHeaderField("Content-Type");
		String contentEncoding = connection.getHeaderField("Content-Encoding");

		// Handle : text/xml;charset=utf-8
		if (contentType != null && contentType.contains(";")) {
			contentType = contentType.split(";")[0];
			contentType = contentType.trim();
		}
		
		if (contentType != null) {
			if (contentType.endsWith("xml")) {
				kind = "xml";
			}
			else if (contentType.endsWith("html")) {
				kind = "html";
			}
			else if (contentType.endsWith("plain")) {
				kind = "txt";
			}
			else if (contentType.endsWith("pdf")) {
				kind = "pdf";
				binary = true;
			}
			else if (contentType.equals("application/vnd.ms-excel")) {
				kind = "xls";
				binary = true;
			}
			else if (contentType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) {
				kind = "xlsx";
				binary = true;
			}
			else if (contentType.equals("application/zip")) {
				kind = "zip";
				binary = true;
			}
			else if (contentType.startsWith("multipart/form-data")) {
				kind = "multipart";
				//binary = true;
			}
			else if (contentType.endsWith("jpg") || contentType.endsWith("jpeg")) {
				kind = "jpg";
				binary = true;
			}
			else if (contentType.endsWith("png")) {
				kind = "png";
				binary = true;
			}
			else if (contentType.endsWith("gif")) {
				kind = "gif";
				binary = true;
			}
			else if (contentType.endsWith("bmp")) {
				kind = "bmp";
				binary = true;
			}
		}

		if (contentEncoding != null && contentEncoding.equals("gzip")) {
			kind = "zip";
			binary = true;
		}

		
		// Raw data of response
		if (response != null && response.getRaw() != null) {
			final RawResponse rawResponse = response.getRaw();
			rawResponse.setCode(connection.getResponseCode());
			rawResponse.setStatus(connection.getHeaderField(null));
			
			for (final String headerName : responseHeaders.keySet()) {
				if (headerName != null) {
					final com.sap.azot.RawResponse.Header newResponseHeader = new com.sap.azot.RawResponse.Header();
					newResponseHeader.setName(headerName);
					newResponseHeader.setValue(connection.getHeaderField(headerName));
					rawResponse.getHeaders().add(newResponseHeader);
				}
			}
		}
		
		
		InputStream responseStream = null;
		try {
			// Normal content
			Object content = connection.getContent();
			if (content instanceof InputStream) {
				responseStream = (InputStream) content;				
			}
			else if(content instanceof ImageProducer) {
				responseStream = connection.getInputStream();
			}
		} catch (IOException e) {
			// Error content
			responseStream = connection.getErrorStream();
		}

		String responseContent = "";
		// Binary
		if (binary) {
			println("<binary>");
			println();

			if (AzotConfig.GLOBAL.DUMP && responseStream != null) {
				final File responseFile = new File(workflowReport.getOutputDirectory(), "call_" + String.valueOf(count) + "_response." + kind);
				final FileOutputStream out = new FileOutputStream(responseFile);
				copy(responseStream, out);
				out.flush();
				out.close();
				
				// Raw data of response
				if (response != null && response.getRaw() != null) {
					final RawResponse rawResponse = response.getRaw();
					
					final ExternalContent reponseContent = new ExternalContent();
					reponseContent.setType(contentType);
					reponseContent.setFilename(responseFile.getAbsolutePath());
					rawResponse.setExternalContent(reponseContent);
				}

				// Add a Variable with the dump path
				final Variable filepathVariable = new Variable();
				filepathVariable.setId("azot-dump-filepath");
				filepathVariable.setValue(responseFile.getCanonicalPath());
				headerVariables.add(filepathVariable);
			}
		} else {
			if (responseStream != null) {
				responseContent = stringify(responseStream);	
			}

			if (responseContent != null && !responseContent.isEmpty()) {

				// Add content as an Azot variable
				final Variable contentVariable = new Variable();
				contentVariable.setId("meta:Content");
				contentVariable.setValue(responseContent);
				headerVariables.add(contentVariable);

				println(" meta:Content = " + responseContent);

				if (AzotConfig.GLOBAL.DUMP) {
					final File responseFile = new File(workflowReport.getOutputDirectory(), "call_" + String.valueOf(count) + "_response." + kind);
					final FileOutputStream out = new FileOutputStream(responseFile);
					out.write(responseContent.getBytes());
					out.flush();
					out.close();
					
					// Add a Variable with the dump path
					final Variable filepathVariable = new Variable();
					filepathVariable.setId("azot-dump-filepath");
					filepathVariable.setValue(responseFile.getCanonicalPath());
					headerVariables.add(filepathVariable);
				}
			}
			
			// Raw data of response
			if (response != null && response.getRaw() != null) {
				final RawResponse rawResponse = response.getRaw();
				
				final Content reponseContent = new Content();
				reponseContent.setType(contentType);
				reponseContent.setValue(responseContent);
				rawResponse.setContent(reponseContent);
			}
		}
	
		
		if (response != null) {
			Document document = null;
			
			// Handle metadata on namespaces
			if (response.isNamespaceAware()) {
				try {
					final XPath xpath = XFACTORY.newXPath();
					document = initDocument(responseContent, document, response.isNamespaceAware());
					final UniversalNamespaceCache nsCache = new UniversalNamespaceCache(document, false);
					nsCache.setDebug(true);
					xpath.setNamespaceContext(nsCache);
					xpath.compile("/*");
					
					final Map<String, String> uriForPrefixes = nsCache.getUris();
					final Set<String> uris = uriForPrefixes.keySet();
					
					for (final String uri : uris) {
						// Add content as an Azot variable
						final Variable nsVariable = new Variable();
						final String nsVarName = "meta:NameSpace:" + uri;
						nsVariable.setId(nsVarName);
						nsVariable.setValue(uriForPrefixes.get(uri));
						headerVariables.add(nsVariable);
						
						println(" " + nsVariable.getId() + " = " + nsVariable.getValue());
					}
				} catch (XPathExpressionException e) {
					e.printStackTrace();
				}
			}

			final List<Variable> responseVariables = response.getVariables();
			for (final Variable responseVariable : responseVariables) {
				// Don't modify the variable in response call to keep initial expression
				final Variable variable = VariableHelper.addOrUpdateVariable(responseVariable.getId(), responseVariable.getValue(), responseVariable.isOverwrite(), responseVariable.isReport(), contextVariables);

				String value = VariableHelper.substituteVariables(variable.getValue(), headerVariables);

				if (responseContent != null) {
					if(value.startsWith(XPATH)) {
						// Init XML document (if needed)
						document = initDocument(responseContent, document, response.isNamespaceAware());
						value = processXPathValue(document, value, response.isNamespaceAware(), contextVariables);	
					}
					else if(value.startsWith(AZOT)){
						value = processAzotValue(responseContent, value, contextVariables);
					}
				}

				variable.setValue(value);

				println();
				println("Setting variable: ${" + variable.getId() + "} = " + value);
			}

			// Plugins handling
			final List<PluginRef> responsePlugins = response.getPlugins();
			for (final PluginRef responsePlugin : responsePlugins) {
				PluginsManager.invokePlugin(responsePlugin.getName(), responsePlugin, headerVariables);
			}

			
			// Assertions handling
			final List<Assert> responseAsserts = response.getAsserts();
			for (final Assert responseAssert : responseAsserts) {
				String actual = responseAssert.getActual();
				actual = VariableHelper.substituteVariables(actual, headerVariables);
				actual = VariableHelper.substituteVariables(actual, contextVariables);

				if (responseContent != null && actual.startsWith(XPATH)) {
					// Init XML document (if needed)
					document = initDocument(responseContent, document, response.isNamespaceAware());
					actual = processXPathValue(document, actual, response.isNamespaceAware(), contextVariables);
				}

				String expected = responseAssert.getExpected();
				expected = VariableHelper.substituteVariables(expected, headerVariables);
				expected = VariableHelper.substituteVariables(expected, contextVariables);
				if (responseContent != null && expected.startsWith(XPATH)) {
					// Init XML document (if needed)
					document = initDocument(responseContent, document, response.isNamespaceAware());
					expected = processXPathValue(document, expected, response.isNamespaceAware(), contextVariables);
				}

				if (actual != null && !actual.equals(expected)) {
					callReport.setStatus(Status.FAILURE);
					callReport.setType("com.sap.azot.AssertionFailedError");
					callReport.setFailureMessage("Assert failure: expected='" + expected + "' actual='" + actual + "'");
					break;
				}
			}
		}

	}