/** * @since 4.4 */ public HttpRequestBuilder setCharset(final CharsetEnum charset) { this.charset = charset.getCharset(); return this; }
public ResultEntity setStatus(Integer status) { this.status = status == null ? ResultStatus.SUCCESS.getValue() : status; return this; }
public String getByKey(Integer key) { if (key == null) return null; for (DelFlag d : DelFlag.values()) { if (key.equals(d.key)) { return d.value; } } return null; } }
/** * 获取指定URL页面或资源 * @author sjw * @date 2016年9月29日 下午5:11:14 * @param urlString url地址 */ public static String getURLResponse(String urlString) { return getURLResponse(urlString, null, RequestMethod.GET, CharsetEnum.UTF_8.getName(), null); }
/** * Constructor with method, URL, headers, body and type. * @param body the body * @param headers the headers * @param method the method * @param url the URL * @param type the type used for generic type resolution * @since 4.3 */ public RequestEntity(T body, MultiValueMap<String, String> headers, HttpMethod method, URI url, Type type) { this(body, headers, method, url, null, CharsetEnum.UTF_8.getCharset()); }
/** * 获取指定URL页面或资源 * @author sjw * @date 2016年9月29日 下午5:11:58 * @param urlString * url地址 * @param method * 访问方法:GET/POST * @return */ public static String getURLResponse(String urlString, Map<String, String> params, RequestMethod method) { return getURLResponse(urlString, params, method, CharsetEnum.UTF_8.getName(), null); }
public static boolean check(ResponseEntity<String> response) { if (response == null || response.getStatusCode() != HttpStatus.OK) return false; String body = response.getBody(); if (!StringUtil.notEmpty(body)) { return false; } try { JSONObject jobj = JSONObject.parseObject(body); int status = jobj.getInteger("status"); if (status == ResultStatus.SUCCESS.getValue()) { return true; } } catch (Exception e) { if (log.isWarnEnabled()) { log.warn("body:{},exception is : {}", body, e.getLocalizedMessage()); } } return false; }
public DefaultBodyBuilder(HttpMethod method, String url) { this.method = method; this.url = url; this.charsetResolve = CharsetEnum.UTF_8.getCharset(); this.headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); }
/** * 获取指定URL页面或资源 * @author sjw * @date 2016年9月29日 下午5:11:58 * @param urlString * url地址 * @param method * 访问方法:GET/POST * @return */ public static String getURLResponse(String urlString, Map<String, String> params) { return getURLResponse(urlString, params, RequestMethod.GET, CharsetEnum.UTF_8.getName(), null); }
@Override public ResultEntity build() { ResultEntity resultEntity; if (this.info.getSystemCode() == null) { resultEntity = new ResultEntity(this.info.getCode()); } else { resultEntity = new ResultEntity(this.info.getSystemCode()); } resultEntity.setStatus(resultStatus.getValue()).setValidate(validate); if (this.data != null) { resultEntity.setData(data); } else if (this.rows != null) { Map<String, Object> returnMap = new QuickHashMap<String, Object>().quickPut(Global.HTMLVALIDATE.ROWS, this.rows); if (this.total != null) { returnMap.put(Global.HTMLVALIDATE.TOTAL, this.total); } resultEntity.setData(returnMap); } resultEntity.getInfo().setFunctionEntity(this.functionEntity); resultEntity.setPromptMessage(promptMessage); return resultEntity; }
/** * 获得认证信息 * @return */ public String getAuthentication() { return "Basic " + EncryptUtil.encodeBase64((name + ":" + password).getBytes(CharsetEnum.UTF_8.getCharset())); }
@Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { Object arg = null; String[] paramValues = webRequest.getParameterValues(parameter.getParameterName()); if (paramValues != null) { arg = paramValues.length == 1 ? paramValues[0] : paramValues; } if (arg != null) { return new String(arg.toString().getBytes(CharsetEnum.ISO_8859_1.getName()), CharsetEnum.UTF_8.getName()); } return null; }
@Override public ResultEntity build() { ResultEntity resultEntity; if (this.info.getSystemCode() == null) { resultEntity = new ResultEntity(this.info.getCode()); } else { resultEntity = new ResultEntity(this.info.getSystemCode()); } resultEntity.setStatus(resultStatus.getValue()).setValidate(validate); if (this.data != null) { resultEntity.setData(data); } else if (this.rows != null) { Map<String, Object> returnMap = new QuickHashMap<String, Object>().quickPut(Global.HTMLVALIDATE.ROWS, this.rows); if (this.total != null) { returnMap.put(Global.HTMLVALIDATE.TOTAL, this.total); } resultEntity.setData(returnMap); } resultEntity.setThrowable(throwable); resultEntity.setFilterNames(filterNames); resultEntity.setPromptMessage(promptMessage); resultEntity.setJsonConfig(jsonConfig); return resultEntity; }
public String stringVale() { return new String(getContent(), CharsetEnum.UTF_8.getCharset()); }
public static String importFile(InputStream inputStream, CharsetEnum charset) { BufferedInputStream bis = null; StringBuffer stringBuffer = null; try { bis = new BufferedInputStream(inputStream); int len = 0; byte[] b = new byte[1024]; stringBuffer = new StringBuffer(); while ((len = bis.read(b)) != -1) { stringBuffer.append(new String(b, 0, len, charset.getName())); } } catch (Exception e) { log.error("读取文件出错,原因为:" + e); } finally { IOUtils.closeQuietly(bis); IOUtils.closeQuietly(inputStream); } return stringBuffer.toString(); }
@Override public void channelReadInternal(NettyProtocol read) { System.out.println(new String(read.getContent(), CharsetEnum.UTF_8.getCharset())); }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { T buf = (T) msg; String request = new String(buf.getContent(), CharsetEnum.UTF_8.getCharset()); channelReadInternal(ctx, request); }
@Override public void channelReadInternal(NettyProtocol read) throws Exception { System.out.println(new String(read.getContent(), CharsetEnum.UTF_8.getCharset())); write("success!"); } }
public void write(String content) throws Exception { getCtx().writeAndFlush(new NettyProtocol(content.getBytes(CharsetEnum.UTF_8.getCharset()))); }
private static EncodedResource[] loadResources(String location) { try { Resource[] resources = resourceResolver.getResources(location); EncodedResource[] encodeResources = new EncodedResource[resources.length]; for (int i = 0; i < resources.length; i++) { Resource resource = resources[i]; encodeResources[i] = new EncodedResource(resource, CharsetEnum.UTF_8.getCharset()); } return encodeResources; } catch (Exception e) { log.error("loadResource error", e); throw new BusinessException("loadResource error"); } }