レスポンスの内容をSpring Securityフィルタで変更したいと思います。Springセキュリティフィルタのレスポンスコンテンツの変更
public class SecurityFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
filterChain.doFilter(request, response);
//response.getWriter().write("a");
PrintWriter p = new PrintWriter(response.getOutputStream());
p.println("Hello");
p.flush();
p.close();
}
}
フィルタの背後には、フィルタの後ろにストリングのリストを取得するRESTサービスがあります。 getOutputStream()を使用して書き込むと、クライアントの文字列リスト(String 'Hello'ではなく)を作成できます。私はにgetWriter()を使用している場合は、私は次のエラーを取得する:
2017-08-10 09:10:42,900 ERROR [org.springframework.boot.web.support.ErrorPageFilter] (default task-7) Forwarding to error page from request [/worker/system/urmlprod30] due to exception [UT010006:
Cannot call getWriter(), getOutputStream() already called]: java.lang.IllegalStateException: UT010006: Cannot call getWriter(), getOutputStream() already called
は、どのように私は春のセキュリティフィルタで応答内容を変更することができますか? 私はwildfly10を使用しますが、TomcatとWeblogic12cでも動作します。私は春のブートを使用します。
securityContext.xmlから関連部分:
<security:csrf disabled="true" />
<security:custom-filter ref="securityFilter" after="FORM_LOGIN_FILTER"/>
</security:http>
私は私のコンテンツを作成したいが、私はそれについて何ができる場合の応答がすでに送信され推測?
いずれの回答も高く評価されます。
おかげで、V.
----- UPDATE ------ は、私はそれを操作したいと私はRESTサービスからの応答が必要であることを言及するのを忘れてしまいました。
ニース、それは働いています!私はこのHttpServletResponseWrapperを試したことを覚えていますが、エラーが発生しました...とにかく、ありがとう! – Viktor