コード例 #1
0
  protected void addCorsHeaders(
      ServerHttpRequest request, ServerHttpResponse response, HttpMethod... httpMethods) {

    String origin = request.getHeaders().getFirst("origin");
    origin = ((origin == null) || origin.equals("null")) ? "*" : origin;

    response.getHeaders().add("Access-Control-Allow-Origin", origin);
    response.getHeaders().add("Access-Control-Allow-Credentials", "true");

    List<String> accessControllerHeaders =
        request.getHeaders().get("Access-Control-Request-Headers");
    if (accessControllerHeaders != null) {
      for (String header : accessControllerHeaders) {
        response.getHeaders().add("Access-Control-Allow-Headers", header);
      }
    }

    if (!ObjectUtils.isEmpty(httpMethods)) {
      response
          .getHeaders()
          .add(
              "Access-Control-Allow-Methods",
              StringUtils.arrayToDelimitedString(httpMethods, ", "));
      response.getHeaders().add("Access-Control-Max-Age", String.valueOf(ONE_YEAR));
    }
  }
コード例 #2
0
  private String convertListToDelimitedString(List<String> list) {

    String result = "";
    if (list != null) {
      result = StringUtils.arrayToDelimitedString(list.toArray(), ", ");
    }
    return result;
  }
コード例 #3
0
 public String toString() {
   StringBuffer sb = new StringBuffer(getClass().getName());
   sb.append(" defining beans [");
   sb.append(StringUtils.arrayToDelimitedString(getBeanDefinitionNames(), ","));
   sb.append("]; ");
   if (getParentBeanFactory() == null) {
     sb.append("root of BeanFactory hierarchy");
   } else {
     sb.append("parent: " + getParentBeanFactory());
   }
   return sb.toString();
 }
コード例 #4
0
  private void createSqlUninstaller(ArrayList<String> tables, String outPath) {

    String query = "DROP TABLE ";
    query += StringUtils.arrayToDelimitedString(tables.toArray(), ",\n");
    query += ";";
    try {
      BufferedWriter out = new BufferedWriter(new FileWriter(outPath));
      out.write(query);
      out.close();
    } catch (IOException ex) {
      Logger.getLogger(ControllerJFrameMain.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
コード例 #5
0
 /**
  * 生成索引键值
  *
  * @param clazz 索引数据类对象
  * @param indexName 索引名称
  * @param indexValues 索引值
  * @return
  */
 public static String buildIndexKey(Class<?> clazz, String indexName, Object... indexValues) {
   StringBuilder builder = new StringBuilder();
   if (clazz != null) {
     builder.append(clazz.getName()).append("&");
   }
   if (indexName != null) {
     builder.append(indexName).append("#");
   }
   if ((indexValues != null) && (indexValues.length > 0)) {
     return StringUtils.arrayToDelimitedString(indexValues, "^");
   }
   return builder.toString();
 }
コード例 #6
0
  protected void service(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    try {
      this.target.handleRequest(request, response);
    } catch (HttpRequestMethodNotSupportedException ex) {
      String[] supportedMethods =
          ((HttpRequestMethodNotSupportedException) ex).getSupportedMethods();
      if (supportedMethods != null) {
        response.setHeader("Allow", StringUtils.arrayToDelimitedString(supportedMethods, ", "));
      }
      response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, ex.getMessage());
    }
  }
コード例 #7
0
  protected File findIpLikeLibrary() {
    File topDir = ConfigurationTestUtils.getTopProjectDirectory();

    File ipLikeDir = new File(topDir, "opennms-iplike");
    assertTrue(
        "iplike directory exists at ../opennms-iplike: " + ipLikeDir.getAbsolutePath(),
        ipLikeDir.exists());

    File[] ipLikePlatformDirs =
        ipLikeDir.listFiles(
            new FileFilter() {
              @Override
              public boolean accept(File file) {
                if (file.getName().matches("opennms-iplike-.*") && file.isDirectory()) {
                  return true;
                } else {
                  return false;
                }
              }
            });
    assertTrue(
        "expecting at least one opennms iplike platform directory in "
            + ipLikeDir.getAbsolutePath()
            + "; got: "
            + StringUtils.arrayToDelimitedString(ipLikePlatformDirs, ", "),
        ipLikePlatformDirs.length > 0);

    File ipLikeFile = null;
    for (File ipLikePlatformDir : ipLikePlatformDirs) {
      assertTrue(
          "iplike platform directory does not exist but was listed in directory listing: "
              + ipLikePlatformDir.getAbsolutePath(),
          ipLikePlatformDir.exists());

      File ipLikeTargetDir = new File(ipLikePlatformDir, "target");
      if (!ipLikeTargetDir.exists() || !ipLikeTargetDir.isDirectory()) {
        // Skip this one
        continue;
      }

      File[] ipLikeFiles =
          ipLikeTargetDir.listFiles(
              new FileFilter() {
                @Override
                public boolean accept(File file) {
                  if (file.isFile() && file.getName().matches("opennms-iplike-.*\\.(so|dylib)")) {
                    return true;
                  } else {
                    return false;
                  }
                }
              });
      assertFalse(
          "expecting zero or one iplike file in "
              + ipLikeTargetDir.getAbsolutePath()
              + "; got: "
              + StringUtils.arrayToDelimitedString(ipLikeFiles, ", "),
          ipLikeFiles.length > 1);

      if (ipLikeFiles.length == 1) {
        ipLikeFile = ipLikeFiles[0];
      }
    }

    assertNotNull(
        "Could not find iplike shared object in a target directory in any of these directories: "
            + StringUtils.arrayToDelimitedString(ipLikePlatformDirs, ", "),
        ipLikeFile);

    return ipLikeFile;
  }
コード例 #8
0
 @Test
 public void testGetAllLocalIP() throws UnknownHostException {
   System.out.println(
       "all local ip:\r\n    "
           + StringUtils.arrayToDelimitedString(NetUtils.getAllLocalAddress(), "\r\n    "));
 }
コード例 #9
0
 public String toString() {
   PropertyValue[] pvs = getPropertyValues();
   StringBuffer sb = new StringBuffer("MutablePropertyValues: length=" + pvs.length + "; ");
   sb.append(StringUtils.arrayToDelimitedString(pvs, ","));
   return sb.toString();
 }