포럼: Open Discussion (Thread #20103)

Client(.NET)とServer(Java)間でのレスポンスのヘッダの扱い (2008-10-07 16:35 by Anonymous #39180)

サーバ側で設定されたHTTPレスポンスのヘッダをClientFW for .NETで取得する方法はありますか?
また、ServerFW for Java(Rich)で、レスポンスヘッダに情報を設定する方法は、どのようなやり方が適当でしょうか?
自分でフィルタを作ってThreadLocal(ContextSupport)を使えばできそうですが、RequestContextHandlingFilter.doFilterメソッド内で、doFilter直後にHttpServletResponseを引数に持つ拡張ポイントがあれば、もっとヘッダの設定がやりやすいのではないかと思いました。

もし適当な方法があるのであれば、教えていただけると幸いです。

Reply to #39180×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

Client FW for .NETに関する質問の回答 (2008-10-08 11:25 by tatsumihr #39186)

Client FW for .NETでレスポンスヘッダの値を取得することはできます。

XML通信の例で説明しますが、DataSetXmlCommunicateBLogicクラスのCommunicateメソッドの戻り値が CommunicationResultクラスとなっています。このCommunicationResultクラスのResponseHeadersプロパティより、レスポンスヘッダの値を取得できます。

このレスポンスヘッダの値を画面に渡すには、DataSetXmlCommunicateBLogicクラスのAfterCommunicateメソッドをオーバーライドし、必要な値をBLogicResultクラスのItemsプロパティに設定してください。すると、ビジネスロジック実行後に、 EventControllerクラスのItemsプロパティより、値を取得することができます。

以下のような実装になります。

-----
例)DataSetXmlCommunicateBLogicの拡張例

public class DataSetXmlCommunicateBLogicEx<TResult> : DataSetXmlCommunicateBLogic<TResult>
where TResult : DataSet, new()
{
protected override void AfterCommunicate(CommunicationResult communicationResult, BLogicResult blogicResult)
{
base.AfterCommunicate(communicationResult, blogicResult);
if (communicationResult.ResponseHeaders.ContainsKey("someKey"))
{
blogicResult.Items["someKey"] = communicationResult.ResponseHeaders["someKey"];
}
}
}
-----
例)EventControllerからレスポンスヘッダの値を取得する例
ExecutionResult result = eventController1.Execute();
if (eventController1.Items.ContainsKey("someKey"))
{
string headerValue = eventController1.Items["someKey"];
}
-----
Reply to #39180

Reply to #39186×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

Server FW for Java(Rich)に関する質問の回答 (2008-10-08 11:25 by tatsumihr #39187)

レスポンスヘッダに情報を設定するには TerasolunaControllerを拡張して独自のコントローラを作成する方法があります。TerasolunaControllerを拡張する場合、通常は業務処理を行うexecuteServiceメソッドを実装しますが、この前処理としてpreServiceメソッド、後処理としてpostServiceメソッドがあります。ヘッダの設定であれば後処理のpostServiceメソッドをオーバーライドして、引数で渡される HttpServletResponse の addHeader メソッドを使ってヘッダを設定してください。

以下のような実装になります。

-----
public class TestController extends TerasolunaController<Input, Output> {
private BLogic<Input, Output> blogic = null;

public void setBlogic(BLogic<Input, Output> blogic) {
this.blogic = blogic;
}

@Override
protected Output executeService(Input command) throws Exception {

System.out.println("START Controller");
Output result = blogic.execute(command);
System.out.println("END Controller");
return result;
}

@Override
protected void postService(HttpServletRequest request,
HttpServletResponse response, Input command, Output
modelAndView)
throws Exception {
response.addHeader("hogeName", "hogeValue");
}
}
-----
Reply to #39180

Reply to #39187×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: Client(.NET)とServer(Java)間でのレスポンスのヘッダの扱い (2008-10-10 13:11 by Anonymous #39219)

ご回答ありがとうございました。
BLogicからTerasolunaControllerを継承したControllerに、どうやって各レスポンスに共通のデータを渡すかについて少し悩みましたが、DTOのスーパークラスを作成することでとりあえず解決しました。
Reply to #39180

Reply to #39219×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login