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



我在调用httpClient.execute调用rest Web服务时收到主题的错误。我读了两个有趣的帖子,它们与我的情况有些相似。从这两个线程中,我相信通过在 websphere 8 Liberty 配置文件中增加缓冲区可能会帮助我更好地描述问题,但我不知道在 WAS 8.5 liberty 配置文件中在哪里增加它(没有管理控制台(。我不知道它是否相关,但我将(1(我用来指导我的线程,我唯一重要的指令放在(2(applicationContext.xml,(3(mvc-dispatcher-servlet.xml,(4(用于休息Web服务的客户端和(5(POM.xml。我猜库有一些问题,因为在我将其转换为 Maven 项目之前,这样的项目运行良好。有人可以告诉我我是否在 POM 中缺少一些牵引力吗?

1( WebSphere 响应缓冲 无法在 JSP 中设置标头。响应已提交

2(
应用程序上下文.xml ...3(
MVC-dispatcher-servlet.xml /WEB-INF/pages/ 。.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( 聚甲醛

<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>

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

`        <rdependency>
                 <groupId>javax.servlet</groupId>
                 <artifactId>servlet-api</artifactId>
                 <version>3.0</version>
                 <scope>provided</scope>
          </dependency>
          `
至于响应已经提交的错误,

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

最新更新