/** Parses input stream and creates new <code>HttpRequest</code> object. */ public static HttpRequest readFrom(InputStream in) { BufferedReader reader; try { reader = new BufferedReader(new InputStreamReader(in, StringPool.ISO_8859_1)); } catch (UnsupportedEncodingException uneex) { return null; } HttpRequest httpRequest = new HttpRequest(); String line; try { line = reader.readLine(); } catch (IOException ioex) { throw new HttpException(ioex); } if (!StringUtil.isBlank(line)) { String[] s = StringUtil.splitc(line, ' '); httpRequest.method(s[0]); httpRequest.path(s[1]); httpRequest.httpVersion(s[2]); httpRequest.readHeaders(reader); httpRequest.readBody(reader); } return httpRequest; }
public Map<String, Object> getVariableMap() { Map<String, Object> vars = new HashMap<String, Object>(); ConvertUtils.register(new DateConverter(), java.util.Date.class); if (StringUtil.isBlank(keys)) { return vars; } String[] arrayKey = keys.split(","); String[] arrayValue = values.split(","); String[] arrayType = types.split(","); for (int i = 0; i < arrayKey.length; i++) { if ("".equals(arrayKey[i]) || "".equals(arrayValue[i]) || "".equals(arrayType[i])) { continue; } String key = arrayKey[i]; String value = arrayValue[i]; String type = arrayType[i]; Class<?> targetType = Enum.valueOf(PropertyType.class, type).getValue(); Object objectValue = ConvertUtils.convert(value, targetType); vars.put(key, objectValue); } return vars; }
/** * 为返回结果data中添加一行redirect_url记录,用于定位跳转页面 * * @param url * @return */ public ResultObject returnWithRedirectUrl(String url) { /// 如果跳转url不为空,则记录需要跳转的url if (this.data == null) { this.data = new HashMap<String, Object>(); } if (!StringUtil.isBlank(url)) { this.data.put("redirect_url", url); } return this; }