<?xml version="1.0" encoding="Shift_JIS"?>

<!DOCTYPE document SYSTEM "./dtd/document-v10.dtd">

<document>
  <header>
    <title>FAQ</title>
    <authors>
      <person name="Vincent Massol" email="vmassol@apache.org"/>
    </authors>
    <translator>服部 隆二</translator>
  </header>

  <body>

    <s1 title="FAQ の内容/FAQ Content">
      <ul>
        <li>
          <jump anchor="faq1">"Can't find resource for cactus" error
          message</jump>
        </li>
	<li>
	  <jump anchor="faq1">"Can't find resource for cactus" エラーメッセージ</jump>
	</li>
        <li>
          <jump anchor="faq2">How can I have a web.xml that is valid both for
          testing and for production ?</jump>
        </li>
        <li>
          <jump anchor="faq2">テストにも実際の製品にも有効な web.xml を書くことは可能か？</jump>
        </li>
        <li>
          <jump anchor="faq3">I'm getting a
          <code>java.io.StreamCorruptedException: InputStream does not contain a
          serialized object</code> error. What does it mean ?</jump>
        </li>
        <li>
          <jump anchor="faq3">
	   <code>java.io.StreamCorruptedException: InputStream does not contain a serialized object</code>
	   と言うエラーに出くわした。これは何を意味するのか？</jump>
        </li>
        <li>
          <jump anchor="faq4">How can I test the chaining of several HTTP
          requests ?</jump>
        </li>
        <li>
          <jump anchor="faq4">
	  どのように幾つかの HTTP リクエストのチェイン（連鎖）をテストすれば良いのか。
          </jump>
        </li>
        <li>
          <jump anchor="faq5">The Ant runservertests task hangs when my server
          is started</jump>
        </li>
        <li>
          <jump anchor="faq5">Ant の runservertests タスクがサーバーが起動すると止まってしまう。 
	  </jump>
        </li>
      </ul>
    </s1>

    <anchor id="faq1"/>
    <s1 title="Can't find resource for cactus エラーメッセージ/Can't find resource for cactus error message">

      <p>
        If you get the following stack trace :
      </p>
      <p>
        もし以下のような スタックトレースを得たなら:
      </p>

<source><![CDATA[
java.lang.ExceptionInInitializerError: java.util.MissingResourceException:
  Can't find bundle for base name cactus, locale en_GB
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:707)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:679)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:546)
]]></source>

      <p>
        it simply means that you have not put the cactus.properties file in
        your CLASSPATH (i.e. the directory which contains this file should
        be in the CLASSPATH). This file is the Cactus configuration file and
        is required. Check the Cactus
        <link href="howto_config.html">Configuration Howto</link> page for
        more information.
      </p>
      <p>
        それは単純に cactus.properties ファイルをあなたの環境のクラスパスに置いていないだけです。
	（つまり このファイルを含むディレクトリは CLASSPATH の中にないといけません。） 
	このファイルは Cactus の設定ファイルであり必要な物です。
	更なる情報は Cactus の <link href="howto_config.html">設定 Howto</link> 
	のページをチェックしてください。 
      </p>
    </s1>

    <anchor id="faq2"/>
    <s1 title="テストにも実際の製品にも有効な web.xml を書くことは可能か？/How can I have a web.xml that is valid both for testing and for production ?">

      <s2 title="質問/Question">
        <p>
          Cactus needs to have a few entries set in the <code>web.xml</code>
          file (redirector definition and mappings mostly). The application to
          test also needs its own entries. What would be nice would be to be
          able to use the same <code>web.xml</code> file in the build process
          for both application testing and deployment to production.
        </p>
	<p>
	  Cactus では <code>web.xml</code> ファイルの中に 2,3 記述する項目を
	  追加する必要があります。（大抵はリダイレクタの定義とそのマッピング）
	  テストすべきアプリケーションもまたそれ自身の記述項目を持ちます。
	  アプリケーションのテスト及び本稼動の運用環境の両方の構築プロセスで
	  同じ <code>web.xml</code>  ファイルを使えるようにするには、何か良い
	  手立てはあるでしょうか。  	  
	</p>
      </s2>
      <s2 title="解答/Solution">
        <p>
            Here's how I accomplished conditional inclusion
            of Cactus web.xml configuration.  My web.xml file is capable of
            working standalone without requiring any filtered copy to work.
            In Ant I'm doing this:
        </p>
	<p>
	    ここに、どのように私が状況も考慮した Cactus の web.xml の設定を
	    成し遂げたかを示します。
	    <suspect> 私の web.xml ファイルは実行させるのに別のフィルタリングされた
	    コピーを一切必要とせず、それ単独で動作可能となっています。</suspect>
	    Ant で私は以下のようにしています：	    	    
	</p>
<source><![CDATA[
<!-- Activate the Cactus web.xml configuration -->
<!-- web.xml での Cactus の 設定を有効にする。 -->
<copy todir="${admin.build.dir}/WEB-INF"
      file="web/admin/WEB-INF/web.xml"
      overwrite="yes">
  <filterset>
    <filter token="start.cactus.config" value="--&gt;" />
    <filter token="end.cactus.config" value="&lt;!--" />
  </filterset>
</copy>]]></source>

        <p>
          In <code>web.xml</code> I have this:
        </p>
        <p>
          <code>web.xml</code> では以下のようにしています:
        </p>

<source><![CDATA[
<!-- Cactus configuration
Note: Do not place any XML comments in this Cactus configuration section
(Ant's filtered copy is used to activate this configuration when the test
web application is built)
-->
<!-- Cactus の設定
注意: この Cactus の設定部分の XML のコメントはどれもさわらない事。
(Ant のフィルターコピー機能がテスト時の Web アプリケーションをビルド
する時にこの設定を有効にするのに使われています。)
-->
<!-- Begin Cactus Configuration @start.cactus.config@
<servlet>
  <servlet-name>ServletRedirector</servlet-name>
  <servlet-class>org.apache.cactus.server.ServletTestRedirector</servlet-class>
</servlet>

<servlet>
    <servlet-name>JspRedirector</servlet-name>
    <jsp-file>/somewhere/jspRedirector.jsp</jsp-file>
</servlet>

<servlet-mapping>
    <servlet-name>ServletRedirector</servlet-name>
    <url-pattern>/ServletRedirector/</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>JspRedirector</servlet-name>
    <url-pattern>/JspRedirector/</url-pattern>
</servlet-mapping>

@end.cactus.config@ End Cactus Configuration -->
]]></source>

      </s2>

    </s1>

    <anchor id="faq3"/>
    <s1 title="java.io.StreamCorruptedException と言うエラーに出くわした。これは何を意味するのか？/I'm getting a java.io.StreamCorruptedException error. What does it mean ?">

      <note>
        This error only appears for Cactus 1.3dev (before 21/04/2002) and
        below. Cactus 1.3 no longer uses a serialized object to return test
        result. It uses an XML string.
      </note>

      <note>
        このエラーは Cactus 1.3 の開発版（2002/04/21 以前）やその前の物で
	発生します Cactus 1.3 ではテストの結果を戻すのにシリアライズされた
	オブジェクトを使っていません。XML の文字列を使っています。
      </note>

      <s2 title="解答/Solution">
        <p>
          This exception results when client-side Cactus code attempts to talk
          to a misconfigured installation of Cactus on the server side. The
          reason for the obscure exception is this: Cactus makes two requests
          to the server. In the first, the client-side test runner requests that
          such-and-such a test be run on the server (an oversimplification,
          please see: XXXX). Immediately after the response from the server
          the client code makes a second request, this time for the results of
          the server-side test. Cactus is supposed to send back a serialized
          Object containing the results. Cactus then attempts to deserialize
          this Object from the input stream in the response. If
          Cactus is installed properly on the server, this process
          works transparently. If not (for instance the second
          request does not even arrive at a Cactus redirector) then
          the response to the second request (which very well may be
          a 404 or 500 error) will not contain the object that
          client-cactus expects. This leads to the
          StreamCorruptedException.
        </p>
        <p>
	  この例外は クライアント側の Cactus のコードがサーバー側で設定に不備
	  があるままインストールされた Cactus とやり取りしようとした結果です。 
	  この良く分からない例外の理由はこうです：Cactus は二種類のリクエスト
	  をサーバーに送ります。最初は クライアント側で実行中のテストはつまり
	  いわいる test をサーバー上で実行するように要求します。（単純化しす
	  ぎですね。XXXX の部分を見てください）サーバーからレスポンスが返って
	  きてすぐにクライアント側から第二のリクエストが、この時はサーバー側
	  のテストの結果の為に発せられます。Cactus では シリアライズされたオ
	  ブジェクトにテストの結果を入れて返すようになっています。Cactus は
	  それからレスポンスの入力ストリームからこのオブジェクトをシリアライ
	  スより復元しようとします。もし Cactus が正常にサーバーにインストー
	  ルされているなら、このプロセスは素直に上手く行きます。もしそうで
	  ないなら（例えば２番目のリクエストが Cactus のリダイレクタにすら届
	  いていないとか。）２番目のリクエストへのレスポンス（多分に 404 か
	  500 のエラーでしょう。）はクライアント側の Cactus が期待したオブジ
	  ェクトを含んでいません。こうして StreamCorruptedException が発生し
	  ます。
        </p>

        <p>
          When troubleshooting this error, the most likely prospect
          is that the requests from client-Cactus are not even
          reaching server-Cactus. This can happen when the
          <code>cactus.properties</code> contains a bad entry. For instance, I
          have run into this problem when building several different
          testing-applications. I tried to run my tests against
          <code>http://localhost/webapp1/ServletRedirector/</code> when I needed
          to be running against
          <code>http://localhost/webapp2/ServletRedirector/</code>. This can
          also happen if your web.xml file contains an error, or does not
          properly map the URLs contained in cactus.properties to the
          Cactus redirectors.
        </p>
	<p>
	  このエラートラブル対策時に、最もそれらしく見込みのあるのはクライアント
	  側の Cactus からのリクエストがサーバー側に届いていない事でしょう。
	  これは <code>cactus.properties</code> が間違った設定を含んでいる時に
	  発生します。例えば幾つかの異なったテスト用のアプリケーションを構築し
	  ている時にこの問題にはまってしまいました。正確には 
	  <code>http://localhost/webapp2/ServletRedirector/</code> に対して実行
	  していなければならないのに、<code>http://localhost/webapp1/ServletRedirector/</code> 
	  に対してテストを実行していたのです。この件はまた、web.xml ファイルに
	  誤りが含まれている時や  cactus.properties に含まれる Cactus のリダイ
	  レクタへの URL が正しくマップされていない場合にも発生する事があります。
	</p>
        <p>
          A good way to check whether your requests are reaching a
          Cactus redirector is to manually enter in the URLs for all
          of the redirectors you use into the navigation bar of your
          web-browser. Actually the Cactus redirectors provide a URL just for
          that : <code>http://localhost/webapp/ServletRedirector?Cactus_Service=RUN_TEST</code>
          (this also works for the other redirectors).
        </p>
	<p>
	  リクエストが Cactus のリダイレクタへ届いているかどうかを確認する
	  為の良い方法は Web ブラウザのナビゲーションバーに利用する全ての
	  リダイレクタの URL を打ち込んで見ることです。実際に Cactus の
	  リダイレクタは単に次のような URL で呼び出すようになっています:
	   <code>http://localhost/webapp/ServletRedirector?Cactus_Service=RUN_TEST</code>
	   (これは他のリダイレクタも同様に動きます。)
	</p>
        <note>
          If you call <code>http://localhost/webapp/ServletRedirector</code>
          directly, you'll get a 500 error and get a stack trace (in the log or
          along with your error page) that says <code><![CDATA[Missing service
          name parameter [] in HTTP request.]]></code>. This is because the
          Cactus redirector expects HTTP parameter from the Cactus client side.
        </note>
	<note>
	  もし <code>http://localhost/webapp/ServletRedirector</code> を直接呼び
	  出した場合には、500 番のエラーと以下のようなスタックトレース（ログの中
	  にか、エラーページにか）が得られるでしょう。
	  <code><![CDATA[Missing service name parameter [] in HTTP request.]]></code>. 
	  これは Cactus のリダイレクタは Cactus クライアントからの HTTP パラメータ
	  を受け取るようになっているからです。 
	</note>

        <p>
          Another likely error is that your server-side classpath
          does not contain a copy of the cactus.jar. (Cactus is
          effectively not present on the server.) According to
          e-mails on the Cactus user list, the
          <code>StreamCorruptedException</code> could also result when you are
          using the wrong version of the servlet.jar in some area
          (any version prior to 2.2, or using servlet.jar 2.2 with a
          Cactus-2.3 installation).
        </p>
	<p>
	  他のよくあるエラーとしてはサーバー側のクラスパスが cactus.jar を
	  含んでいないことです。（サーバー上で Cactus が有効な状態になって
	  いない。）Cactus の ユーザーリストの e-mail によれば 
	  <code>StreamCorruptedException</code>  は servlet.jar の間違った
	  バージョンのものを使ったばあいにも発生するそうです。 
	</p>
      </s2>

    </s1>

    <anchor id="faq4"/>
    <s1 title="	  どのように幾つかの HTTP リクエストのチェイン（連鎖）をテストすれば良いのか。/How can I test the chaining of several HTTP requests ?">

      <s2 title="質問/Question">
        <p>
          Let's imagine that I have one servlet that performs an HTTP redirect
          to a JSP page (or to another servlet). How do I test it with Cactus ?
        </p>
      </s2>
      <s2 title="解答/Solution">
        <p>
          Short answer : you don't !
        </p>
	<p>
	  手短に：やめましょう。
	</p>
        <p>
          Long answer : Cactus is meant to be a unit testing tool, meaning it
          lets you perform tests for a given method and then it lets you
          assert the result from that method.
        </p>
	<p>
	  長めに答えると： Cactus は 単体テスト用のツールとして見なされています。
	  それはある一つのメソッドのテストを実行してそれからそのメソッドからの
	  結果を表明させます。
	</p>
        <p>
          In the above scenario, a typical Cactus test will consist in
          verifying that the return HTTP response is an HTTP redirect (by
          checking the HTTP response code - 302 - in the <code>endXXX()</code>
          method) and possibly also checking the URL of the redirect page.
        </p>
	<p>
	  上のシナリオでは、典型的な Cactus のテストにで 戻ってきた HTTP 
	  レスポンスが HTTP リダイレクトである事（<code> endXXX() </code> 
	  メソッドの中で HTTP レスポンスのコードが 302 であるのをチェックす
	  る事で）そして、また良くある事ですがリダイレクトページの URL を 
	  検証する物があります。
	</p>
        <p>
          Then, as a second test, you could (if you wish) verify that calling
          the URL of the JSP does return such HTML content (using HttpUnit
          integration for example). Note that this second test is rather a
          functional test than a unit test but it can still be viewed as
          unit testing the <code>doGet()</code> method of the JSP ...
        </p>
	<p>
	  それから、２番目のテストとしては（もし望むなら）JSP の URL を呼び出
	  すことで その HTML のコンテンツが返ってくる事を検証できるでしょう。
	  （例えば HttpUnit と統合する事で ）注意すべきなのは２番目のテストは
	  単体テストと言うよりむしろ機能テストなのですが、JSP の <code>doGet()</code> 
	  メソッドの単体テストとして見なす事もできるのです。
	</p>
      </s2>

    </s1>

    <anchor id="faq5"/>
    <s1 title="Ant の runservertests タスクがサーバーが起動すると止まってしまう。/The Ant runservertests task hangs when my server is started">

      <s2 title="質問/Question">
        <p>
          When I use the <code>runservertests</code> Cactus custom Ant task,
          it starts my server allright but then hangs and the tests are not
          executed. What is happening ?
        </p>
	<p>
	  Cactus 用の 拡張 ant タスクである <code>runservertests</code> を実行
	  した時にすぐにサーバーが起動するのですが、それから動かなくなりそして
	  テストが実行されません。何が起きたのでしょうか。
	</p>
      </s2>
      <s2 title="解答/Solution">
        <p>
          It means that the <code>testURL</code> attribute you've specified
          in <code>runservertests</code> is not a valid URL. It must be a URL
          that is valid when the server is up. To diagnosis the problem simply
          open a browser once your server is started (i.e. when the task hangs)
          and type the URL in your browser. An alternative to debug is also to
          run Ant in debug mode (<code>ant -debug [your target]</code>).
        </p>
	<p>
	  これは <code>runservertests</code> の中で定義する <code>testURL</code> 
	  が正しい URL でない事を意味します。それはサーバーが起動した時に必ず有効
	  な URL でなければいけません。この問題を簡単に診断するにはサーバーが起動
	  した時（つまりタスクが動かなくなった時に）にブラウザを開き、ブラウザに
	  その URL を打ち込んでみる事です。デバッグのための別の手段としては ant を
	  デバッグモードで立ち上げる事です。 (<code>ant -debug [your target]</code>).
	</p>
        <p>
          With Cactus 1.3, the correct URL to call is the following, which is
          always valid :
          <code>http://localhost:8080/webapp/ServletRedirector?Cactus_Service=RUN_TEST</code>.
          Of course replace <code>webapp</code> by your webapp context and
          replace the port by the one you're using.
        </p>
	<p>
	  Cactus 1.3 では呼び出す正しい URL は次のようになっており、これは常に有効となっています。  
	  <code>http://localhost:8080/webapp/ServletRedirector?Cactus_Service=RUN_TEST</code>.
	  もちろん <code>webapp</code> の部分は実際の Web アプリのコンテキストに置き換え、
	  ポート番号も実際に利用している物に置き換えてください。
	</p>
      </s2>

    </s1>

  </body>
</document>
