Beispiel #1
0
  public static String getId(String recipient) {
    String ret = null;
    byte[] testp = recipient.getBytes();
    int pcount = 0;
    for (byte p : testp) {

      if ((char) p == '|') {
        pcount++;
      }
    }
    System.out.println("count = " + pcount);
    if (pcount > 1) {
      String address = StringUtils.splitPreserveAllTokens(recipient, "|")[2];
      String test = StringUtils.splitPreserveAllTokens(address, "^")[3];
      int stop = test.indexOf("<");
      if (stop > 0) {
        test = test.substring(0, stop);
      }
      System.out.println(test);
      ret = test;
    } else {
      String address = StringUtils.splitPreserveAllTokens(recipient, "|")[1];
      String test = StringUtils.splitPreserveAllTokens(address, "^")[0];
      System.out.println(test);
      ret = test;
    }
    System.out.println("about to test ret " + ret);

    return ret;
  }
Beispiel #2
0
  /**
   * GET request parameters as map.
   *
   * @param requestURL request URL {@link HttpServletRequest#getRequestURL()}
   * @param pathVariables path markers that should be identified as extra parameters
   * @return map of parameters (with preserved other)
   */
  public static Map<String, List<String>> getParameters(
      final String requestURL, final Set<String> pathVariables) {

    final Map<String, List<String>> parameters = new LinkedHashMap<String, List<String>>();

    try {
      final String[] request = StringUtils.splitPreserveAllTokens(requestURL, '?');

      String key = null;

      if (request != null && request.length > 0) {
        final String[] pathPairs = StringUtils.splitPreserveAllTokens(request[0], '/');

        for (String pathItem : pathPairs) {
          if (key != null) {
            if (!parameters.containsKey(key)) {
              parameters.put(key, new LinkedList<String>());
            }
            final String value = URLDecoder.decode(pathItem, "UTF-8");
            parameters.get(key).add(value);
            key = null;
          } else if (pathVariables.contains(pathItem)) {
            key = pathItem; // next path is value
          }
        }
      }

      if (request != null && request.length > 1) {

        final String[] parameterPairs = StringUtils.splitPreserveAllTokens(request[1], '&');
        for (String parameterPair : parameterPairs) {
          final int idx = parameterPair.indexOf("=");
          key =
              idx > 0 ? URLDecoder.decode(parameterPair.substring(0, idx), "UTF-8") : parameterPair;
          if (!parameters.containsKey(key)) {
            parameters.put(key, new LinkedList<String>());
          }
          final String value =
              idx > 0 && parameterPair.length() > idx + 1
                  ? URLDecoder.decode(parameterPair.substring(idx + 1), "UTF-8")
                  : null;
          parameters.get(key).add(value);
        }
      }

    } catch (UnsupportedEncodingException uee) {
      throw new RuntimeException(uee);
    }
    return parameters;
  }
  @Override
  public void runTask(ProcessInstance instance) throws Exception {
    fsDefaultFS =
        String.format(
            "hdfs://%s:%s",
            getHelper().get(clusterName + ".nn.address"),
            getHelper().get(clusterName + ".nn.port"));

    FileUtils.forceMkdir(new File(working));

    saveScriptFile(buildCommand(working), working);

    String cli =
        MessageFormatter.arrayFormat("sh {}/script.sh", new Object[] {working}).getMessage();
    saveCommandFile(cli, working);
    String[] cmds = StringUtils.splitPreserveAllTokens(cli, " ");

    FileWriter fileWriter = new FileWriter(logger, working + "/task.log");

    Map<String, Object> socketParams = new HashMap<>();
    socketParams.put("identifier", getIdentifier());
    socketParams.put("taskId", getTaskId());
    socketParams.put("type", "workflow");
    socketParams.put("user", getUser());

    ManagedProcess managedProcess =
        new ManagedProcess(cmds, getDefaultEnvs(working), working, logger, fileWriter);
    managedProcess.setSocketParams(socketParams);
    managedProcess.run();
  }
  private Map<String, String[]> getConfigurationMap(Reference ref) {
    Map<String, String[]> configMap = new HashMap<String, String[]>();

    String separatorChars = ",";
    RefAddr separatorCharsRefAddr = ref.get("separatorChars");
    if (separatorCharsRefAddr != null) {
      String value = (String) separatorCharsRefAddr.getContent();
      if (value != null && !"".equals(value)) {
        separatorChars = value.trim();
      }
    }

    Enumeration addrs = ref.getAll();

    while (addrs.hasMoreElements()) {
      RefAddr addr = (RefAddr) addrs.nextElement();
      String type = addr.getType();
      String value = (String) addr.getContent();

      String[] valueArray = StringUtils.splitPreserveAllTokens(value, separatorChars);

      for (int i = 0; i < valueArray.length; i++) {
        valueArray[i] = valueArray[i].trim();
      }

      configMap.put(type, valueArray);
    }

    return configMap;
  }
Beispiel #5
0
  public static List<String> parseDirectRecipients(DirectDocuments documents) {

    List<String> ret = new ArrayList();
    for (String recipient : documents.getSubmissionSet().getIntendedRecipient()) {

      String address = StringUtils.splitPreserveAllTokens(recipient, "|")[2];
      ret.add(parseXTN(address));
    }
    return ret;
  }
Beispiel #6
0
    public void map(Object key, Text value, OutputCollector<Text, Text> output, Reporter reporter)
        throws IOException {
      String[] _allCols = StringUtils.splitPreserveAllTokens(value.toString(), splitChar);
      StringBuffer stringBuffer = new StringBuffer();

      for (int i = 0; i < _allCols.length; i++) {
        stringBuffer.append(i).append('=').append(_allCols[i]).append("\t");
      }
      output.collect(new Text(_allCols[0]), new Text(stringBuffer.toString()));
    }
 protected String escapeQuotes(final String input) {
   final String[] splitedInput = StringUtils.splitPreserveAllTokens(input, SEMICOLON_CHAR);
   final List<String> tmp = new ArrayList<String>();
   for (final String string : splitedInput) {
     if (doesNotContainNewLine(string)) {
       tmp.add(StringEscapeUtils.escapeCsv(string));
     } else {
       tmp.add(string);
     }
   }
   return StringUtils.join(tmp, SEMICOLON_CHAR);
 }
 @Override
 public void configure(Map<String, String> configuration) {
   if (configuration.get(GROUP_BY) != null) {
     groupByFields =
         StringUtils.splitPreserveAllTokens(configuration.get(GROUP_BY), GROUP_BY_DELIM);
   }
   if (configuration.get(OUTPUT_FIELD) != null) {
     outputField = configuration.get(OUTPUT_FIELD);
   }
   if (configuration.get(OPERATED_FIELD) != null) {
     operatedField = configuration.get(OPERATED_FIELD);
   } else {
     // TODO: 一定要有一个操作字段operatedField? 如果是没有分组的count(*),operatedField是什么?
     // TODO: 多个分组条件的count,operatedField有几个?  operatedField和groupByFields一样吗?
     // throw new RuntimeException("Aggregator needs a field to operate it. Property missing: " +
     // OPERATED_FIELD);
   }
   if (configuration.get(ASSOC_FIELD) != null) {
     assocField = StringUtils.splitPreserveAllTokens(configuration.get(ASSOC_FIELD), ",");
   }
 }
Beispiel #9
0
 private void parseLine() {
   String line = reader.getCurrentValue().toString();
   String[] tokens = StringUtils.splitPreserveAllTokens(line, PASSWD_LINE_SEPARATOR);
   value =
       new Passwd(
           StringUtils.trimToNull(tokens[0]),
           StringUtils.trimToNull(tokens[1]),
           StringUtils.trimToNull(tokens[2]) == null ? null : Long.valueOf(tokens[2]),
           StringUtils.trimToNull(tokens[3]) == null ? null : Long.valueOf(tokens[3]),
           StringUtils.trimToNull(tokens[4]),
           StringUtils.trimToNull(tokens[5]),
           StringUtils.trimToNull(tokens[6]));
 }
Beispiel #10
0
  /** 3、字符串的分割 */
  @Test
  public void test3() {
    // 默认半角空格分割
    String str1 = "aaa bbb ccc";
    String[] dim1 = StringUtils.split(str1); // => ["aaa", "bbb", "ccc"]

    System.out.println(dim1.length); // 3
    System.out.println(dim1[0]); // "aaa"
    System.out.println(dim1[1]); // "bbb"
    System.out.println(dim1[2]); // "ccc"

    // 指定分隔符
    String str2 = "aaa,bbb,ccc";
    String[] dim2 = StringUtils.split(str2, ","); // => ["aaa", "bbb",
    // "ccc"]

    System.out.println(dim2.length); // 3
    System.out.println(dim2[0]); // "aaa"
    System.out.println(dim2[1]); // "bbb"
    System.out.println(dim2[2]); // "ccc"

    // 去除空字符串
    String str3 = "aaa,,bbb";
    String[] dim3 = StringUtils.split(str3, ","); // => ["aaa", "bbb"]

    System.out.println(dim3.length); // 2
    System.out.println(dim3[0]); // "aaa"
    System.out.println(dim3[1]); // "bbb"

    // 包含空字符串
    String str4 = "aaa,,bbb";
    String[] dim4 = StringUtils.splitPreserveAllTokens(str4, ","); // =>
    // ["aaa",
    // "",
    // "bbb"]

    System.out.println(dim4.length); // 3
    System.out.println(dim4[0]); // "aaa"
    System.out.println(dim4[1]); // ""
    System.out.println(dim4[2]); // "bbb"

    // 指定分割的最大次数(超过后不分割)
    String str5 = "aaa,bbb,ccc";
    String[] dim5 = StringUtils.split(str5, ",", 2); // => ["aaa",
    // "bbb,ccc"]

    System.out.println(dim5.length); // 2
    System.out.println(dim5[0]); // "aaa"
    System.out.println(dim5[1]); // "bbb,ccc"
  }
Beispiel #11
0
  public Option(String[] columns, String csvLine, String delimiter) {
    this.optionValuesMap = new LinkedHashMap<String, String>();

    String[] values = StringUtils.splitPreserveAllTokens(csvLine, delimiter);
    if (values.length != columns.length) {
      System.out.println("Value length - " + values.length + " Columns length " + columns.length);
      System.err.println(
          "Something is massively screwed up and the number of columns does not match the number of values! Exiting the applcation");
      System.exit(-1);
    }
    for (int i = 0; i < values.length; i++) {
      this.optionValuesMap.put(columns[i], values[i]);
    }
  }
Beispiel #12
0
  // based on old XDR stuff
  public static List<String> parseRecipients(DirectDocuments documents) {

    List<String> ret = new ArrayList();
    for (String recipient : documents.getSubmissionSet().getIntendedRecipient()) {
      if (recipient.startsWith("|")) {
        String address = StringUtils.remove(recipient, "|");
        ret.add(StringUtils.splitPreserveAllTokens(address, "^")[0]);
      } else {
        String id = getId(recipient);
        ret.add(id);
      }
    }
    return ret;
  }
Beispiel #13
0
 public static Map<String, String> parseDictionary(String data) {
   String[] tokens = data.split(",");
   Map<String, String> result = new HashMap<>();
   for (String token : tokens) {
     String[] items = StringUtils.splitPreserveAllTokens(token, '=');
     if (items.length > 2) {
       String key = items[0];
       items = Arrays.copyOfRange(items, 1, items.length);
       result.put(key.trim(), StringUtils.join(items, "=").trim());
     } else {
       result.put(items[0].trim(), items[1].trim());
     }
   }
   return result;
 }
Beispiel #14
0
  public void syntaxError(
      Recognizer<?, ?> recognizer,
      Object offendingSymbol,
      int line,
      int charPositionInLine,
      String msg,
      RecognitionException e) {
    CommonTokenStream tokens = (CommonTokenStream) recognizer.getInputStream();
    String input = tokens.getTokenSource().getInputStream().toString();
    Token token = (Token) offendingSymbol;
    String[] lines = StringUtils.splitPreserveAllTokens(input, '\n');
    String errorLine = lines[line - 1];

    String simpleMessage = "syntax error at or near \"" + token.getText() + "\"";
    throw new LangParserException(token, line, charPositionInLine, simpleMessage, errorLine);
  }
Beispiel #15
0
 // 使用者 时间 preurl cururl
 public void map(
     LongWritable key, Text value, OutputCollector<Text, LongWritable> out, Reporter reporter)
     throws IOException {
   String line = value.toString();
   String[] _allCols = StringUtils.splitPreserveAllTokens(line, TAB);
   if (_allCols.length < 41) {
     return;
   }
   String gmtCreated = _allCols[AuctionAuctions.OLD_STARTS];
   if (gmtCreated != null && gmtCreated.indexOf(date) >= 0) {
     String status = _allCols[AuctionAuctions.AUCTION_STATUS];
     String attr = _allCols[AuctionAuctions.FEATURES];
     String from = TaobaoPath.getValue(attr, "source", null);
     out.collect(new Text(from + "\t" + status), one);
     out.collect(new Text("cat\t" + _allCols[AuctionAuctions.CATEGORY]), one);
   }
 }
Beispiel #16
0
  @Override
  protected void doWork(String line, OutputCollector<Text, LongWritable> output)
      throws IOException {
    String[] _allCols = StringUtils.splitPreserveAllTokens(line, TAB);
    if (_allCols.length < 47) {
      return;
    }
    String queryDate = DateStringUtils.format(inputArgs[0]);
    String gmtCreated = _allCols[TcBizOrder.GMT_CREATE];
    String payTime = _allCols[TcBizOrder.PAY_TIME];
    String gmtModified = _allCols[TcBizOrder.GMT_MODIFIED];
    if (Utils.isSameDay(queryDate, gmtCreated)) {
      output.collect(Utils.mergeKey("t", "sys", "created"), ONE);
      output.collect(Utils.mergeKey("d", "sys", "created", "m", getMinutes(gmtCreated)), ONE);
      output.collect(Utils.mergeKey("d", "sys", "created", "s", gmtCreated), ONE);
    }
    if (Utils.isSameDay(queryDate, gmtModified)) {
      output.collect(Utils.mergeKey("t", "sys", "modified"), ONE);
    }

    // filter not effective order
    if (!TcBizOrder.isEffective(_allCols)) {
      return;
    }

    if (TcBizOrder.isMain(_allCols)) {
      commonMonitor("all", _allCols, output, queryDate);
      if (TcBizOrder.isB2C(_allCols)) {
        commonMonitor("b2c", _allCols, output, queryDate);
      } else {
        commonMonitor("c2c", _allCols, output, queryDate);
      }
      if (TcBizOrder.isFromTgroupon(_allCols)) {
        commonMonitor("jhs", _allCols, output, queryDate);
      }
      if (Utils.isSameDay(payTime, queryDate)) {
        long fee = TcBizOrder.getTotalFee(_allCols);
        String key = alipayTradeArea.getArea(fee);
        output.collect(Utils.mergeKey("t", "alipay_area", key), ONE);
      }
    }
    if (TcBizOrder.isDetail(_allCols)) {
      String rootCatId = Utils.getValue(_allCols[TcBizOrder.ATTRIBUTES], "realRootCat", "NULL");
      commonTotalMonitor("cat", rootCatId, _allCols, output, queryDate);
    }
  }
Beispiel #17
0
  public static void main(String[] f) {
    try {
      BufferedReader2 reader =
          new BufferedReader2(
              new FileReader(
                  "D:\\tmp\\monitor-app-org.jboss.mx.loading.UnifiedClassLoader3.log.buy2.cm3"));
      String d = null;
      Set<String> set = new HashSet<String>();
      while ((d = reader.readLine()) != null) {

        String[] v = StringUtils.splitPreserveAllTokens(d, '\01');
        set.add(v[1]);

        System.out.println(d);
      }
      for (String s : set) System.out.println(s);
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  /**
   * This method loads UserAdminRole entity temporal and ARBAC constraint instance variables with
   * data that was retrieved from the 'ftARC' attribute on the 'ftUserAttrs' object class. This is
   * the raw format that Fortress uses to condense the temporal and ARBAC data into a compact String
   * for efficient storage and retrieval and is not intended to be called by external programs.
   *
   * @param szRawData contains a raw formatted String that maps to 'ftARC' attribute on
   *     'ftUserAttrs' object class
   * @param contextId contains the tenant id.
   * @param parentUtil provides method to getParents.
   */
  public void load(String szRawData, String contextId, ParentUtil parentUtil) {
    if ((szRawData != null) && (szRawData.length() > 0)) {
      String[] tokens =
          StringUtils.splitPreserveAllTokens(szRawData, Config.getInstance().getDelimiter());
      for (int i = 0; i < tokens.length; i++) {
        if (StringUtils.isNotEmpty(tokens[i])) {
          switch (i) {
            case 0:
              name = tokens[i];
              parents = parentUtil.getParentsCB(name.toUpperCase(), contextId);
              break;

            case 1:
              this.setTimeout(Integer.parseInt(tokens[i]));
              break;

            case 2:
              this.setBeginTime(tokens[i]);
              break;

            case 3:
              this.setEndTime(tokens[i]);
              break;

            case 4:
              this.setBeginDate(tokens[i]);
              break;

            case 5:
              this.setEndDate(tokens[i]);
              break;

            case 6:
              this.setBeginLockDate(tokens[i]);
              break;

            case 7:
              this.setEndLockDate(tokens[i]);
              break;

            case 8:
              this.setDayMask(tokens[i]);
              break;

            default:
              String szValue = tokens[i];
              int indx = szValue.indexOf(P + GlobalIds.PROP_SEP);
              if (indx >= 0) {
                String szOsP = szValue.substring(indx + 2);
                this.setOsP(szOsP);
              }
              indx = szValue.indexOf(U + GlobalIds.PROP_SEP);
              if (indx >= 0) {
                String szOsU = szValue.substring(indx + 2);
                this.setOsU(szOsU);
              }
              indx = szValue.indexOf(R + GlobalIds.PROP_SEP);
              if (indx >= 0) {
                String szRangeRaw = szValue.substring(indx + 2);
                this.setRoleRangeRaw(szRangeRaw);
              }
              break;
          }
        }
      }
    }
  }
  public void reduce(
      Text key, Iterator<Text> values, OutputCollector<Text, Text> output, Reporter reporter)
      throws IOException {
    List<String[]> _temp = new ArrayList<String[]>();
    int count = 0;
    while (values.hasNext()) {
      Text _out = values.next();
      String[] tokens = StringUtils.splitPreserveAllTokens(_out.toString(), TAB);
      _temp.add(tokens);
      if (count++ > 100000) break;
    }

    if (count > 10000) {
      Set<String> ipSet = new HashSet<String>();
      for (int posI = 0; posI < _temp.size(); posI++) {
        String[] array = _temp.get(posI);
        if (array == null) continue;

        String mid = array[2];
        String ip = array[3];
        ipSet.add(ip);
      }
      output.collect(
          key, Utils.mergeKey(String.valueOf(ipSet.size()), StringUtils.join(ipSet, '|')));
      return;
    }

    /**
     * ·Ö×éËã·¨ FOREACH ALL_DATA IF IN INDEX THEN UPDATE INDEX AND INSERT DATA ELSE FOREACH SUB_DATA
     * MAKE INDEX AND SET FIND'S DATA AS NULL
     */
    // List<List<String[]>> dataList = new ArrayList<List<String[]>>();
    List<StringBuffer> indexList = new ArrayList<StringBuffer>();
    Set<String> ipSet = new HashSet<String>();
    boolean muliHost = false;
    for (int posI = 0; posI < _temp.size(); posI++) {
      String[] array = _temp.get(posI);
      if (array == null) continue;

      String mid = array[2];
      String ip = array[3];
      ipSet.add(ip);
      boolean hasIndex = false;
      for (int i = 0; i < indexList.size(); i++) {
        StringBuffer index = indexList.get(i);
        if (index.indexOf("|" + mid + "|") >= 0 || index.indexOf("|" + ip + "|") >= 0) {
          if (index.indexOf("|" + mid + "|") < 0) {
            index.append('|').append(mid).append('|');
          }

          if (index.indexOf("|" + ip + "|") < 0) {
            index.append('|').append(ip).append('|');
          }
          // dataList.get(i).add(array);
          hasIndex = true;
          break;
        }
      }
      if (!hasIndex) {
        StringBuffer index = new StringBuffer("|" + mid + "|" + ip + "|");
        // List<String[]> _tmp = new ArrayList<String[]>();
        // _tmp.add(array);
        for (int k = posI + 1; k < _temp.size(); k++) {
          String[] _newArray = _temp.get(k);
          if (_newArray == null) {
            continue;
          }
          String _mid = _newArray[2];
          String _ip = _newArray[3];
          if (index.indexOf("|" + _mid + "|") >= 0 || index.indexOf("|" + _ip + "|") >= 0) {
            if (index.indexOf("|" + _mid + "|") < 0) {
              index.append('|').append(_mid).append('|');
            }

            if (index.indexOf("|" + _ip + "|") < 0) {
              index.append('|').append(_ip).append('|');
            }
            // _tmp.add(_newArray);
            _temp.set(k, null);
          }
        }
        indexList.add(index);
        // dataList.add(_tmp);
      }
    }
    //        for(String[] _array : _temp){
    //            output.collect(key,Utils.mergeKey(_array[1],_array[2],_array[3],_array[4]));
    //        }

    StringBuffer allIndex = new StringBuffer();
    for (StringBuffer index : indexList) {
      allIndex.append(index).append(';');
    }
    if (allIndex.length() > 0) {
      allIndex.deleteCharAt(allIndex.length() - 1);
    }
    output.collect(
        key, Utils.mergeKey(String.valueOf(indexList.size()), StringUtils.join(ipSet, '|')));
  }
Beispiel #20
0
 public static String parseXTN(String address) {
   return StringUtils.splitPreserveAllTokens(address, "^")[3];
 }
 public void map(Object key, Text value, OutputCollector<Text, Text> output, Reporter reporter)
     throws IOException {
   String[] _allCols = StringUtils.splitPreserveAllTokens(value.toString(), TAB);
   output.collect(new Text(_allCols[0]), value);
 }
  public HttpResponse fetch(org.apache.shindig.gadgets.http.HttpRequest request)
      throws GadgetException {
    HttpUriRequest httpMethod = null;
    Preconditions.checkNotNull(request);
    final String methodType = request.getMethod();

    final org.apache.http.HttpResponse response;
    final long started = System.currentTimeMillis();

    // Break the request Uri to its components:
    Uri uri = request.getUri();
    if (StringUtils.isEmpty(uri.getAuthority())) {
      throw new GadgetException(
          GadgetException.Code.INVALID_USER_DATA,
          "Missing domain name for request: " + uri,
          HttpServletResponse.SC_BAD_REQUEST);
    }
    if (StringUtils.isEmpty(uri.getScheme())) {
      throw new GadgetException(
          GadgetException.Code.INVALID_USER_DATA,
          "Missing schema for request: " + uri,
          HttpServletResponse.SC_BAD_REQUEST);
    }
    String[] hostparts = StringUtils.splitPreserveAllTokens(uri.getAuthority(), ':');
    int port = -1; // default port
    if (hostparts.length > 2) {
      throw new GadgetException(
          GadgetException.Code.INVALID_USER_DATA,
          "Bad host name in request: " + uri.getAuthority(),
          HttpServletResponse.SC_BAD_REQUEST);
    }
    if (hostparts.length == 2) {
      try {
        port = Integer.parseInt(hostparts[1]);
      } catch (NumberFormatException e) {
        throw new GadgetException(
            GadgetException.Code.INVALID_USER_DATA,
            "Bad port number in request: " + uri.getAuthority(),
            HttpServletResponse.SC_BAD_REQUEST);
      }
    }

    String requestUri = uri.getPath();
    // Treat path as / if set as null.
    if (uri.getPath() == null) {
      requestUri = "/";
    }
    if (uri.getQuery() != null) {
      requestUri += '?' + uri.getQuery();
    }

    // Get the http host to connect to.
    HttpHost host = new HttpHost(hostparts[0], port, uri.getScheme());

    try {
      if ("POST".equals(methodType) || "PUT".equals(methodType)) {
        HttpEntityEnclosingRequestBase enclosingMethod =
            ("POST".equals(methodType)) ? new HttpPost(requestUri) : new HttpPut(requestUri);

        if (request.getPostBodyLength() > 0) {
          enclosingMethod.setEntity(
              new InputStreamEntity(request.getPostBody(), request.getPostBodyLength()));
        }
        httpMethod = enclosingMethod;
      } else if ("GET".equals(methodType)) {
        httpMethod = new HttpGet(requestUri);
      } else if ("HEAD".equals(methodType)) {
        httpMethod = new HttpHead(requestUri);
      } else if ("DELETE".equals(methodType)) {
        httpMethod = new HttpDelete(requestUri);
      }
      for (Map.Entry<String, List<String>> entry : request.getHeaders().entrySet()) {
        httpMethod.addHeader(entry.getKey(), StringUtils.join(entry.getValue(), ','));
      }

      // Disable following redirects.
      if (!request.getFollowRedirects()) {
        httpMethod.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false);
      }

      // HttpClient doesn't handle all cases when breaking url (specifically '_' in domain)
      // So lets pass it the url parsed:
      response = FETCHER.execute(host, httpMethod);

      if (response == null) {
        throw new IOException("Unknown problem with request");
      }

      long now = System.currentTimeMillis();
      if (now - started > slowResponseWarning) {
        slowResponseWarning(request, started, now);
      }

      return makeResponse(response);

    } catch (Exception e) {
      long now = System.currentTimeMillis();

      // Find timeout exceptions, respond accordingly
      if (TIMEOUT_EXCEPTIONS.contains(e.getClass())) {
        LOG.info(
            "Timeout for "
                + request.getUri()
                + " Exception: "
                + e.getClass().getName()
                + " - "
                + e.getMessage()
                + " - "
                + (now - started)
                + "ms");
        return HttpResponse.timeout();
      }

      LOG.log(
          Level.INFO,
          "Got Exception fetching " + request.getUri() + " - " + (now - started) + "ms",
          e);

      // Separate shindig error from external error
      throw new GadgetException(
          GadgetException.Code.INTERNAL_SERVER_ERROR,
          e,
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    } finally {
      // cleanup any outstanding resources..
      if (httpMethod != null)
        try {
          httpMethod.abort();
        } catch (UnsupportedOperationException e) {
          // ignore
        }
    }
  }
Beispiel #23
0
  /**
   * @Title: main @Description: TODO(这里用一句话描述这个方法的作用)
   *
   * @param @param args 设定文件
   * @return void 返回类型
   * @throws
   */
  public static void main(String[] args) throws IOException {
    //		String input    = "d:\\20111202";      //文件路径
    //      String mainName ="淘宝房产";      //报表名称
    String input = args[0]; // 文件路径
    String mainName = args[1]; // 报表名称
    String tableName = "fangpvuv";
    String tableTitle = "PVUV";

    String zufang = "zufang",
        ershoufang = "ershoufang",
        all = "all",
        detail = "detail",
        qmfq = "qmfq",
        alluv = "unrepeatuv";

    if (!new File(input).exists()) {
      System.out.println("File Not Exist ! => " + input);
      return;
    }
    Report report = Report.newReport(mainName + "每日PV、UV数据");
    List<String> lines = Utils.readWithCharset(input, "utf-8");
    Table table = null;
    int allPV = 0;
    if (lines != null && lines.size() > 0) {
      for (String line : lines) {
        if (line.startsWith(zufang)) {
          tableName = "zufangpvuv";
          tableTitle = "租房频道当日PV、UV";
        } else if (line.startsWith(ershoufang)) {
          tableName = "ershoufangpvuv";
          tableTitle = "二手房频道当日PV、UV";
        } else if (line.startsWith(all)) {
          tableName = "houseall";
          tableTitle = "House下当日PV、UV";
        } else if (line.startsWith(detail)) {
          tableName = "detailpvuv";
          tableTitle = "Detail当日PV、UV";
        } else if (line.startsWith(qmfq)) {
          tableName = "qmfqpvuv";
          tableTitle = "全民疯抢当日PV、UV";
        } else if (line.startsWith(alluv)) {
          tableName = "allpvuv";
          tableTitle = "整站去重UV";
        }
        String[] _cols = StringUtils.splitPreserveAllTokens(line, CTRL_A);
        if (_cols.length > 0) {
          if (tableName.equals("allpvuv")) {
            table = report.newTable(tableName, mainName + "总PV、UV(去重)");
            table.addCol("allpv", "总PV", String.valueOf(allPV));
            table.addCol("vpv", "访客UV", _cols[1]);
            table.addCol("uuv", "会员UV", _cols[2]);
            table.addCol(
                "alluv",
                "总UV",
                String.valueOf(Integer.valueOf(_cols[1]) + Integer.valueOf(_cols[2])));
            break;
          } else {
            table = report.newTable(tableName, mainName + tableTitle);
            table.addCol("vpv", "访客PV", _cols[1]);
            table.addCol("upv", "会员PV", _cols[2]);
            if (!tableName.equals("qmfqpvuv") && !tableName.equals("alluv")) {
              allPV = allPV + Integer.valueOf(_cols[1]) + Integer.valueOf(_cols[2]);
            }
            table.addCol("vuv", "访客UV", _cols[3]);
            table.addCol("uuv", "会员UV", _cols[4]);
          }
        }
        table.sort(Table.SORT_VALUE);
      }
    }
    XmlReportFactory.dump(report, new FileOutputStream(input + ".xml"));
  }