Converts a string based response to a ResponseCtx obejct.

@param response
the string response
@return the ResponseCtx object
@throws MelcoeXacmlException
960358
public ResponseCtx makeResponseCtx(String response)
            throws MelcoeXacmlException {
        ResponseCtx resCtx = null;
        try {
            ByteArrayInputStream is =
                    new ByteArrayInputStream(response.getBytes());
            resCtx = ResponseCtx.getInstance(is);
        } catch (ParsingException pe) {
            throw new MelcoeXacmlException("Error parsing response.", pe);
        }
        return resCtx;
    }
560650
public static byte[] getContent(HttpResponse response) {

		try {
			if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
				return ResourceUtils.getBytes(response.getEntity().getContent());
			}
		}
		catch (IOException e) {
			log.error("Failed to read response: ", e.getMessage());
		}

		return null;
	}
993529
protected base_resource[] get_nitro_response(nitro_service service, String response) throws Exception {
		system_stats[] resources = new system_stats[1];
		system_response result = (system_response) service.get_payload_formatter().string_to_resource(system_response.class, response);
		if(result.errorcode != 0) {
			if (result.errorcode == 444) {
				service.clear_session();
			}
			if(result.severity != null)
			{
				if (result.severity.equals("ERROR"))
					throw new nitro_exception(result.message,result.errorcode);
			}
			else
			{
				throw new nitro_exception(result.message,result.errorcode);
			}
		}
		resources[0] = result.system;
		return resources;
	}
686567
@Override
    public RequestCtx handleResponse(HttpServletRequest request,
                                     HttpServletResponse response)
            throws IOException, ServletException {
        if (request.getParameter("terms") == null
                && request.getParameter("query") == null
                && request.getParameter("sessionToken") == null) {
            return null;
        }

        DataResponseWrapper res = (DataResponseWrapper) response;
        byte[] data = res.getData();

        byte[] result = null;
        String body = new String(data);

        if (body.startsWith("<html>")) {
            logger.debug("filtering html");
            result = filterHTML(request, res);
        } else if (body.startsWith("<?xml")) {
            logger.debug("filtering xml");
            result = filterXML(request, res);
        } else {
            logger.debug("not filtering due to unexpected output: {}", body);
            result = data;
        }

        res.setData(result);

        return null;
    }
461627
protected base_resource[] get_nitro_response(nitro_service service, String response) throws Exception {
		protocolicmp_stats[] resources = new protocolicmp_stats[1];
		protocolicmp_response result = (protocolicmp_response) service.get_payload_formatter().string_to_resource(protocolicmp_response.class, response);
		if(result.errorcode != 0) {
			if (result.errorcode == 444) {
				service.clear_session();
			}
			if(result.severity != null)
			{
				if (result.severity.equals("ERROR"))
					throw new nitro_exception(result.message,result.errorcode);
			}
			else
			{
				throw new nitro_exception(result.message,result.errorcode);
			}
		}
		resources[0] = result.protocolicmp;
		return resources;
	}
124867
protected Document responseToDoc(String response){
        Document doc = null;
        try {
            DocumentBuilderFactory factory = new DocumentBuilderFactoryImpl();
            DocumentBuilderFactory.newInstance();
            DocumentBuilder builder =  factory.newDocumentBuilder();
            ByteArrayInputStream input =  new ByteArrayInputStream(response.getBytes("UTF-8"));
            doc = builder.parse(input);
        } catch (ParserConfigurationException e) {
            LOG.error("ParserConfigurationException", e);
        } catch (UnsupportedEncodingException e) {
            LOG.error("UnsupportedEncodingException", e);
        } catch (IOException e) {
            LOG.error("IOException", e);
        } catch (SAXException e) {
            LOG.error("SAXException", e);
        }

        return doc;
    }
305408
public static String getResponseCodeOutput(Response response) {
        if (response == null) {
            return "";
        }
        StringBuilder responseOutput = new StringBuilder();
        String uuid = getUUID();
        responseOutput.append(ONCLICK_TOGGLE).append(uuid).append("\")'>Toggle Response Status Code</a> ");
        responseOutput.append(SPAN_ID).append(uuid).append(DISPLAY_NONE);
        responseOutput.append(DIV).append(response.getCode()).append(END_DIV);
        responseOutput.append(END_SPAN);
        return responseOutput.toString();
    }
92604
public static HttpServletResponse getEncodingResponse(
            HttpServletResponse response, String charset) {
        response.setCharacterEncoding(charset);
        response.setContentType("text/html;charset=" + charset);
        return response;
    }
1374780
public LaTeXMLServiceResponse parseAsService(String latex) {
        try {
            latex = UriComponentsBuilder.newInstance().queryParam("tex", latex).build().encode(StandardCharsets.UTF_8.toString()).getQuery();
        } catch (UnsupportedEncodingException ignore) {
            LOG.warn("encoding not supported", ignore);
        }

        String serviceArguments = config.buildServiceRequest();
        String payload = serviceArguments + "&" + latex;
        RestTemplate restTemplate = new RestTemplate();

        try {
            LaTeXMLServiceResponse rep = restTemplate.postForObject(config.getUrl(), payload, LaTeXMLServiceResponse.class);
            LOG.debug(String.format("LaTeXMLServiceResponse:\n"
                            + "statusCode: %s\nstatus: %s\nlog: %s\nresult: %s",
                    rep.getStatusCode(), rep.getStatus(), rep.getLog(), rep.getResult()));
            return rep;
        } catch (HttpClientErrorException e) {
            LOG.error(e.getResponseBodyAsString());
            throw e;
        }
    }
730058
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
  {

    String s1 = m_arg0.execute(xctxt).str();
    String s2 = m_arg1.execute(xctxt).str();

    // Add this check for JDK consistency for empty strings.
    if (s1.length() == 0 && s2.length() == 0)
      return XBoolean.S_TRUE;

    int index = s1.indexOf(s2);

    return (index > -1) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
  }
457476
public Object string_to_resource(Class<?> responseClass, String response)
	{
		Gson gson = new Gson();
		return gson.fromJson(response, responseClass);
	}
1054938
public static String getContentAsString(HttpResponse response) {

		try {
			if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {

				HttpEntity entity = response.getEntity();
				Header contentEncoding = entity.getContentEncoding();
				String encoding = contentEncoding != null ? contentEncoding.getValue() : UTF_8;
				return ResourceUtils.getString(entity.getContent(), encoding);
			}
		}
		catch (IOException e) {
			log.error("Failed to read response: ", e.getMessage());
		}

		return null;
	}
383865
public static void outputString(final HttpServletResponse response, final Object obj) {
        try {
            response.setContentType("text/javascript");
            response.setCharacterEncoding("utf-8");
            disableCache(response);
            response.getWriter().write(obj.toString());
            response.getWriter().flush();
            response.getWriter().close();
        } catch (IOException e) {
        }
    }
47296
public void setResponse(String response) {
		this.response = response;
		try {
			this.responseLength = response.getBytes("UTF-8").length;
		} catch (UnsupportedEncodingException e) {
			this.responseLength = response.length();
		}
	}
26977
public static String formatResponse(Response response) {
        if (response == null) {
            return "";
        }
        StringBuilder output = new StringBuilder();
        if (response.isData()) {
            output.append(DIV_I);
            Gson gson = new GsonBuilder().setPrettyPrinting().create();
            if (response.getArrayData() != null) {
                output.append(gson.toJson(response.getArrayData()));
            }
            if (response.getObjectData() != null) {
                output.append(gson.toJson(response.getObjectData()));
            }
            output.append(END_IDIV);
        }
        return formatHTML(output.toString());
    }
1111254
public HttpClientResponseBuilder doReturnJSON(String response, Charset charset) {
        return responseBuilder.doReturnJSON(response, charset);
    }
750639
protected base_resource[] get_nitro_response(nitro_service service, String response) throws Exception {
		qos_stats[] resources = new qos_stats[1];
		qos_response result = (qos_response) service.get_payload_formatter().string_to_resource(qos_response.class, response);
		if(result.errorcode != 0) {
			if (result.errorcode == 444) {
				service.clear_session();
			}
			if(result.severity != null)
			{
				if (result.severity.equals("ERROR"))
					throw new nitro_exception(result.message,result.errorcode);
			}
			else
			{
				throw new nitro_exception(result.message,result.errorcode);
			}
		}
		resources[0] = result.qos;
		return resources;
	}