2015-08-21 122 views

回答

2

我遇到了同樣的問題,什麼工作對我來說是在pom.xml設置系統參數在神火-插件配置:

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.17</version> 
      <configuration> 
       <systemPropertyVariables> 
        <sun.net.http.allowRestrictedHeaders>true</sun.net.http.allowRestrictedHeaders> 
       </systemPropertyVariables> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 
0

的根本原因在詹金斯的工作不工作可能是你Jenkins實例使用OpenJDK構建項目。

在OpenJDK 7的以下源代碼中,它顯示它使用靜態塊來設置allowedRestrictedHeaders系統屬性,並且在初始化HttpURLConnection後不會被重置。

如果您設置了除了pom.xml解決方案之外的JVM arg,它也可以工作。

「-Dsun.net.http.allowRestrictedHeaders =真」

static { 
    maxRedirects = java.security.AccessController.doPrivileged(
      new sun.security.action.GetIntegerAction(
        "http.maxRedirects", defaultmaxRedirects)).intValue(); 
    version = java.security.AccessController.doPrivileged(
      new sun.security.action.GetPropertyAction("java.version")); 
    String agent = java.security.AccessController.doPrivileged(
      new sun.security.action.GetPropertyAction("http.agent")); 
    if (agent == null) { 
     agent = "Java/" + version; 
    } else { 
     agent = agent + " Java/" + version; 
    } 
    userAgent = agent; 
    validateProxy = java.security.AccessController.doPrivileged(
      new sun.security.action.GetBooleanAction(
        "http.auth.digest.validateProxy")).booleanValue(); 
    validateServer = java.security.AccessController.doPrivileged(
      new sun.security.action.GetBooleanAction(
        "http.auth.digest.validateServer")).booleanValue(); 

    enableESBuffer = java.security.AccessController.doPrivileged(
      new sun.security.action.GetBooleanAction(
        "sun.net.http.errorstream.enableBuffering")).booleanValue(); 
    timeout4ESBuffer = java.security.AccessController.doPrivileged(
      new sun.security.action.GetIntegerAction(
        "sun.net.http.errorstream.timeout", 300)).intValue(); 
    if (timeout4ESBuffer <= 0) { 
     timeout4ESBuffer = 300; // use the default 
    } 

    bufSize4ES = java.security.AccessController.doPrivileged(
      new sun.security.action.GetIntegerAction(
        "sun.net.http.errorstream.bufferSize", 4096)).intValue(); 
    if (bufSize4ES <= 0) { 
     bufSize4ES = 4096; // use the default 
    } 

    allowRestrictedHeaders = ((Boolean) java.security.AccessController.doPrivileged(
      new sun.security.action.GetBooleanAction(
        "sun.net.http.allowRestrictedHeaders"))).booleanValue(); 
    if (!allowRestrictedHeaders) { 
     restrictedHeaderSet = new HashSet<String>(restrictedHeaders.length); 
     for (int i = 0; i < restrictedHeaders.length; i++) { 
      restrictedHeaderSet.add(restrictedHeaders[i].toLowerCase()); 
     } 
    } else { 
     restrictedHeaderSet = null; 
    } 
}