private boolean isValid() { if (myUseHTTPProxyRb.isSelected()) { String host = getText(myProxyHostTextField); if (host == null) { return false; } try { HostAndPort parsedHost = HostAndPort.fromString(host); if (parsedHost.hasPort()) { return false; } host = parsedHost.getHostText(); try { InetAddresses.forString(host); return true; } catch (IllegalArgumentException e) { // it is not an IPv4 or IPv6 literal } InternetDomainName.from(host); } catch (IllegalArgumentException e) { return false; } if (myProxyAuthCheckBox.isSelected()) { return !StringUtil.isEmptyOrSpaces(myProxyLoginTextField.getText()) && myProxyPasswordTextField.getPassword().length > 0; } } return true; }
public static String hostToPublicSuffix(String host) { InternetDomainName idn; try { idn = InternetDomainName.from(host); } catch (IllegalArgumentException e) { return host; } InternetDomainName tmp = idn.publicSuffix(); if (tmp == null) { return host; } String pubSuff = tmp.toString(); int idx = host.lastIndexOf(".", host.length() - (pubSuff.length() + 2)); if (idx == -1) { return host; } return host.substring(idx + 1); }
@RequestMapping( value = ApiConstants.PUSH_DATA, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @Transactional public String pushData(@RequestBody String body) { try { Map dataMap = new ObjectMapper().readValue(URLDecoder.decode(body, "utf-8"), Map.class); leadProcessingService.pushLead( new JSONObject((Map) dataMap.get(ApiConstants.PUSH_DATA_FORM_DATA_PARAM)).toString(), StringEscapeUtils.unescapeHtml((String) dataMap.get(ApiConstants.PUSH_DATA_PARAMS_PARAM)), StringEscapeUtils.unescapeHtml( (String) dataMap.get(ApiConstants.PUSH_DATA_REFERRER_PARAM)), InternetDomainName.from((String) dataMap.get(ApiConstants.PUSH_DATA_HOST_PARAM)) .toString(), LeadType.FORM); return ApiResponseStatuses.toJson(ApiResponseStatuses.OK); } catch (IOException e) { return ApiResponseStatuses.toJson(ApiResponseStatuses.BAD_REQUEST); } }