Creates a string suitable for logging output.

@param request a RestExpress Request instance.
@param response a RestExpress Response instance.
@param duration the duration of the request, in milliseconds.
@return a String as described above.
494815
public String create(Request request, Response response, Long duration)
	{
		return createStringBuilder(request, response, duration).toString();
	}
134409
public CreateWaterMarkResponse createWaterMark(CreateWaterMarkRequest request) {
        checkStringNotEmpty(request.getBucket(), "The parameter bucket should NOT be null or empty string.");
        checkStringNotEmpty(request.getKey(), "The parameter key should NOT be null or empty string.");
        InternalRequest internalRequest = createRequest(HttpMethodName.POST, request, WATER_MARK);
        
        return invokeHttpClient(internalRequest, CreateWaterMarkResponse.class);
    }
191353
private String formatDuration(Object value)
   {
      String result = null;
      if (value instanceof Duration)
      {
         Duration duration = (Duration) value;
         result = m_formats.getDurationDecimalFormat().format(duration.getDuration()) + formatTimeUnit(duration.getUnits());
      }
      return result;
   }
1180006
public static void makeStringResponse(HttpResponse response, String s) {
        StringEntity entity = new StringEntity(s, ContentType.TEXT_PLAIN);
        entity.setContentEncoding("utf-8");
        response.setEntity(entity);
    }
789297
public Response makeRequest(Request request) throws InvalidRequestException {

		logger.debug("Enter HttpRequestClient::makeRequest");

		//prepare request
		RequestBuilder builder = RequestBuilder.create(request.getMethod().value()).setUri(request.constructURL().toString()).setVersion(HttpVersion.HTTP_1_1).setCharset(StandardCharsets.UTF_8);

		//add auth header
		if (request.isRequiresAuthentication()) {
			builder.addHeader(HttpHeaders.AUTHORIZATION, request.getAuthString());
		}

		MethodType method = request.getMethod();
		if (method == MethodType.POST) {
			//add post header
			builder.addHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");

			//add post params
			for (NameValuePair nvp : request.getPostParams()) {
				builder.addParameter(nvp);
			}
		}

		logger.debug("Request URI : " + builder.getUri());
		logger.debug("Http Method : " + builder.getMethod());

		try {
			//make the call
			HttpResponse response = client.execute(builder.build());
			//prepare response
			return new Response(response.getEntity() == null ? null : response.getEntity().getContent(), response.getStatusLine().getStatusCode());
		} catch (IOException e) {
			logger.error("Exception while making httpRequest", e);
			throw new InvalidRequestException(e.getMessage());
		}

	}
324768
private String clientResponseToString(ClientResponse response) {
        if (response == null) {
            return null;
        }
        StringBuilder builder = new StringBuilder();
        builder.append("[status: ").append(response.getStatus());
        builder.append(", media type: ").append(response.getType());
        if (response.getStatus() != 404) {
            try {
                String responseBody = response.getEntity(String.class);
                if (responseBody != null) {
                    builder.append(", response body: ").append(responseBody);
                }
            } catch (RuntimeException ignore) {
                // Ignore if there is no response body, or IO error - it may have already been read in certain scenario.
            }
        }
        builder.append(", response headers: ").append(response.getHeaders());
        builder.append("]");
        return builder.toString();
    }
776751
public static Duration formattedStringToDuration(final String formattedDuration) {
        if (formattedDuration == null) {
            return null;
        }

        final TemporalAccessor ta = DateTimeFormatter.ofPattern(DURATION_FORMAT).parse(formattedDuration.trim());
        return Duration.between(LocalTime.MIDNIGHT, LocalTime.from(ta));
    }
770372
static String getConsumedContentType(HttpServletRequest request) {
        String mimeType = firstNotNull(request.getParameter("format"), request
                .getContentType());

        return ((mimeType != null) ? mimeType.replace("application/xml",
                BaseRestResource.XML) : null);
    }
466195
function(request) {
        var doc = request.responseXML;
        if (!doc || !doc.documentElement) {
            doc = request.responseText;
        }
        if (!doc || doc.length <= 0) {
            return null;
        }
        return this.format.read(doc);
    }
1083416
protected String getEncoding(HttpServletRequest request) {
        final String encoding = request.getCharacterEncoding();
        if (encoding != null) {
            return encoding;
        }

        return this.defaultEncoding;
    }
695234
public static String getRequestBody(HttpServletRequest request) {
		if(request.getMethod().equals("GET") || request.getMethod().equals("DELETE")) {
			return null;
		}
		
		StringBuilder stringBuilder = new StringBuilder();
		BufferedReader bufferedReader = null;
		try {
			InputStream inputStream = request.getInputStream();
			if (inputStream != null) {
				bufferedReader = new BufferedReader(new InputStreamReader(
						inputStream));
				char[] charBuffer = new char[128];
				int bytesRead = -1;
				while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
					stringBuilder.append(charBuffer, 0, bytesRead);
				}
			} else {
				stringBuilder.append("");
			}
		} catch (IOException ex) {
			// to nothing
		} finally {
			if (bufferedReader != null) {
				try {
					bufferedReader.close();
				} catch (IOException ex) {

				}
			}
		}

		if (!StringUtils.isEmpty(stringBuilder)) {
			return stringBuilder.toString();
		}

		if (request.getParameterMap().keySet().size() > 0) {
			return request.getParameterMap().keySet().toArray()[0].toString();
		}

        return null;
	}
995152
public static String getFullRequestUrl(HttpServletRequest request) {
        StringBuilder buff = new StringBuilder(
                request.getRequestURL().toString());
        String queryString = request.getQueryString();
        if (queryString != null) {
            buff.append("?").append(queryString);
        }

        return buff.toString();
    }
1140863
@Override
    protected Long logResponse(Response response) {
        Long responseId = super.logResponse(response);
        int code = response.getStatusCode() == null ? 0 : response.getStatusCode();
        String message = response.getStatusMessage() == null ? StatusResponse.forCode(code).getStatus().getMessage() :
                response.getStatusMessage();
        Status status = new Status(code, message);
        try {
            updateServiceSummary(status, responseId);
        }
        catch (ActivityException | SQLException ex) {
            logexception(ex.getMessage(), ex);
        }
        return responseId;
    }
633844
public static StringBuilder durationConfigString(Duration duration) {
        Duration remainder = duration;

        long days = remainder.getStandardDays();
        remainder = remainder.minus(Duration.standardDays(days));

        long hours = remainder.getStandardHours();
        remainder = remainder.minus(Duration.standardHours(hours));

        long minutes = remainder.getStandardMinutes();
        remainder = remainder.minus(Duration.standardMinutes(minutes));

        long seconds = remainder.getStandardSeconds();
        remainder = remainder.minus(Duration.standardSeconds(seconds));

        if (!remainder.isEqual(Duration.ZERO))
            Logger.getLogger(ConfigSupport.class.getName()).log(Level.WARNING, "Duration is more precise than configuration will handle: {0}, dropping remainder: {1}", new Object[]{duration, remainder});

        StringBuilder result = new StringBuilder();
        if (days != 0) {
            if (result.length() != 0) result.append(' ');
            result.append(days).append('d');
        }
        if (hours != 0) {
            if (result.length() != 0) result.append(' ');
            result.append(hours).append('h');
        }
        if (minutes != 0) {
            if (result.length() != 0) result.append(' ');
            result.append(minutes).append('m');
        }
        if (result.length() == 0 || seconds != 0) {
            if (result.length() != 0) result.append(' ');
            result.append(seconds).append('s');
        }

        return result;
    }
1202647
@RequestMapping(value = "/invoke", method = {RequestMethod.POST})
    @ResponseBody
    public ResponseMessage invoke(HttpServletRequest request, HttpServletResponse response) {
        ResponseMessage res = new ResponseMessage();
        try {
            JSONObject json = tgtools.web.util.RequestHelper.parseRequest(request);
            ValidMessage rm = (ValidMessage) tgtools.util.JsonParseHelper.parseToObject(json, ValidMessage.class);

            mUserService.tokenLogin(request.getRemoteAddr(), rm.getUser(), rm.getToken());

            Object obj = restCommand.process(rm.getOperation(), rm.getData());
            res.setStatus(true);
            res.setData(obj);
        } catch (Exception e) {
            res.setStatus(false);
            res.setData(e.getMessage());
        }
        try {
            System.out.println("client结果：" + tgtools.util.JsonParseHelper.parseToJsonObject(res).toString());
        } catch (Exception d) {
        }
        return res;
    }
494646
public void doIndex(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        if (!common.checkGet(request, response)) return;

        // If there's a user logged in, send them to "/home".
        User user = common.getLoggedInUser(request);
        if (user != null) {
            response.sendRedirect("/home");
            return;
        }

        FormProtection fp = FormProtection.start(response);

        response.setContentType("text/html");
        response.setCharacterEncoding("utf-8");
        PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "UTF-8"));

        out.println("<html>");
        out.println("<head><title>Home - Web File Browser</title></head>");
        out.println("<body>");
        fp.insertAntiRedressHtml(out);

        // Login form.
        out.println("<h2>Log in</h2>");
        out.println("<form action='/login' method='POST'>");
        fp.insertAntiCsrfFormField(out);
        out.println("<p>Username: <input name='username' type='text' /> (pick whatever you want)</p>");
        out.println("<p>No password needed for this tiny example.</p>");
        out.println("<input type='submit' value='Login' />");
        out.println("</form>");

        out.println("</body>");
        out.println("</html>");
        out.flush();
    }
122080
public String createStateCookie(HttpServletRequest request, HttpServletResponse response) {
        String stateValue = SocialUtil.generateRandom();
        String loginHint = socialWebUtils.getLoginHint(request);
        if (!request.getMethod().equalsIgnoreCase("GET") && loginHint != null) {
            stateValue = stateValue + loginHint;
        }
        if (tc.isDebugEnabled()) {
            Tr.debug(tc, "Setting cookie " + ClientConstants.COOKIE_NAME_STATE_KEY + " to " + stateValue);
        }
        Cookie stateCookie = referrerURLCookieHandler.createCookie(ClientConstants.COOKIE_NAME_STATE_KEY, stateValue, request);
        response.addCookie(stateCookie);
        return stateValue;
    }