无法设置标头。响应已提交 - httpClient.execute错误

时间:2014-12-02 01:30:08

标签: java maven websphere-liberty

当唤起httpClient.execute来调用rest web服务时,我从主题中收到错误。我读了两篇有趣的帖子,其中有一些与我的案例类似的东西。从两个线程我相信通过增加websphere中的缓冲区8 Liberty配置文件可能帮助我看到问题的更好描述,但我不知道在WAS 8.5自由配置文件中有哪些增加它(没有管理控制台)。我不知道它是否相关,但我放置了(1)我用来指导我的线程,这是我在(2)applicationContext.xml中唯一重要的指令,(3)mvc-dispatcher-servlet.xml,( 4)用于休息Web服务的客户端和(5)POM.xml。遗憾的是,库有些问题,因为在将它转换为Maven Project之前,这个项目工作正常。有人能告诉我,如果我错过了POM中的一些不正确的事情吗?

1)     WebSphere response buffering     Cannot set header in JSP. Response already committed

2)
    applicationContext.xml中           ... 3)
    MVC-调度-servlet.xml中                                                                                                               / WEB-INF /页/                                                                .JSP                                    ... 4)

@Component
public class Lo_DisplayHandler extends Lo_Handler {


    HttpClient httpClient = HttpClientBuilder.create().build();
    HttpPost postRequest = new HttpPost("http://localhost:8080/MHE2/log/display/last"); //lastPageUrl);
    Map<String, String> map = new HashMap<String, String>(); //to map key & value
… //setting the parameters
ObjectMapper mapper = new ObjectMapper(); 
String strJson = mapper.writeValueAsString(map);     
StringEntity input = new StringEntity(strJson);
input.setContentType("application/json"); 
postRequest.setEntity(input);
HttpResponse response = httpClient.execute(postRequest);  //here I got the error [WARNING ] SRVE8094W: WARNING: Cannot set header. Response already committed.

5)POM

<modelVersion>4.0.0</modelVersion>
  <groupId>MHE_original</groupId>
  <artifactId>MHE_original</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
              <spring.version>4.1.2.RELEASE</spring.version>
              <java-version>1.6</java-version>
              <org.aspectj-version>1.7.4</org.aspectj-version>
              <org.slf4j-version>1.7.5</org.slf4j-version>
              <jackson.databind-version>2.2.3</jackson.databind-version>
       </properties>
       <dependencies>
              <dependency>
                     <groupId>org.apache.httpcomponents</groupId>
                     <artifactId>httpclient</artifactId>
                     <version>4.1.1</version>
              </dependency>
              <dependency>
                     <groupId>javax.servlet</groupId>
                     <artifactId>servlet-api</artifactId>
                     <version>2.5</version>
              </dependency>
              <dependency>
                  <groupId>org.codehaus.jackson</groupId>
                  <artifactId>jackson-mapper-asl</artifactId>
                  <version>1.9.12</version>
              </dependency>
              <dependency>
                     <groupId>org.springframework</groupId>
                     <artifactId>spring-core</artifactId>
                     <version>${spring.version}</version>
              </dependency>
              <dependency>
                     <groupId>org.springframework</groupId>
                     <artifactId>spring-web</artifactId>
                     <version>${spring.version}</version>
              </dependency>
              <dependency>
                     <groupId>org.springframework</groupId>
                     <artifactId>spring-webmvc</artifactId>
                     <version>${spring.version}</version>
              </dependency>
              <dependency>
                     <groupId>org.springframework</groupId>
                     <artifactId>spring-context</artifactId>
                     <version>${spring.version}</version>
              </dependency>
       </dependencies>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
        </configuration>
      </plugin>
    </plugins>
  </build>

1 个答案:

答案 0 :(得分:0)

查看你的pom.xml,我看到一个问题。由于servlet-api与liberty /任何其他应用程序服务器捆绑在一起,您可能希望将范围声明为提供,以便它不会与您的应用程序一起打包,从而导致冲突的jar。类似于下面的东西:

`        <rdependency>
                 <groupId>javax.servlet</groupId>
                 <artifactId>servlet-api</artifactId>
                 <version>3.0</version>
                 <scope>provided</scope>
          </dependency>
          `

至于响应已提交错误,无法确定rootcause没有太多信息但可能的原因可能是冲突的jar导致错误,如果定义了错误页面重定向发生并且响应已经在实际请求之前提交可以送达。