Problem finding resource bundle when running servlet in ServletRunner
"Simmons, James D." <[email protected]> Wed, 14 Mar 2012 19:04:39 +0000
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Message-ID | <7EC8F5E7586FB646841E059187D0A0496A354737@DMS-S8MP-3MB.wagresources.walgreens.local> |
--===============0364892840534283908==
Content-Type: multipart/alternative;
boundary="_000_7EC8F5E7586FB646841E059187D0A0496A354737DMSS8MP3MBwagre_"
Content-Language: en-US
--_000_7EC8F5E7586FB646841E059187D0A0496A354737DMSS8MP3MBwagre_
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="us-ascii"
I am trying to test our servlet development framework with ServletUnit. I =
am using the code below as a starting point:
package walgreens.test.bounce;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import javax.servlet.ServletException;
import org.xml.sax.SAXException;
import com.meterware.httpunit.PostMethodWebRequest;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
import com.meterware.servletunit.InvocationContext;
import com.meterware.servletunit.ServletRunner;
import com.meterware.servletunit.ServletUnitClient;
public class TestValidation {
@org.junit.Test
public void testRequiredField() {
File webXml =3D new File("WebContent/WEB-IN=
F/web.xml");
try {
ServletRunner sr =3D new Se=
rvletRunner(webXml, "/bOunceFrameworkTest");
ServletUnitClient sc =3D sr=
.newClient();
WebRequest request =3D new =
PostMethodWebRequest(
=
"http://test.walgreens.com/bOunceFrameworkTest/StandardProxy");
InvocationContext ic =3D sc=
.newInvocation(request);
ic.service();
WebResponse response =3D ic=
.getServletResponse();
System.out.println(response=
.getText());
assertTrue(response.getTitl=
e()
=
.equals("Test Server Side Validation"));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ServletException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Now this code runs our StandardProxy servlet just fine *except* for one thi=
ng. This code in the init() method of the servlet:
applicationResources =3D ResourceBundle
.getBundle("/ApplicationResources");
*cannot* find the file named ApplicationResources.properties. When I run t=
he application under WebSphere or Tomcat there is no such problem and never=
has been. The file in question is in the root of the source directory for=
the application, just as it would be in Struts 2. It is only when using S=
ervletRunner that there is a problem.
I have tried copying the file to various places (root of the project, root =
of WebContent) but the file just will not be found. Is there some way to w=
ork around this problem?
James Simmons
--_000_7EC8F5E7586FB646841E059187D0A0496A354737DMSS8MP3MBwagre_
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="us-ascii"
<html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr=
osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D"http:=
//www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii"=
>
<meta name=3D"Generator" content=3D"Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=3D"EN-US" link=3D"blue" vlink=3D"purple">
<div class=3D"WordSection1">
<p class=3D"MsoNormal">I am trying to test our servlet development framewor=
k with ServletUnit. I am using the code below as a starting point:<o:=
p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">package walgreens.test.bounce;<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">import static org.junit.Assert.assertTrue;<o:p></o:p=
></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">import java.io.File;<o:p></o:p></p>
<p class=3D"MsoNormal">import java.io.IOException;<o:p></o:p></p>
<p class=3D"MsoNormal">import java.net.MalformedURLException;<o:p></o:p></p=
>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">import javax.servlet.ServletException;<o:p></o:p></p=
>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">import org.xml.sax.SAXException;<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">import com.meterware.httpunit.PostMethodWebRequest;<=
o:p></o:p></p>
<p class=3D"MsoNormal">import com.meterware.httpunit.WebRequest;<o:p></o:p>=
</p>
<p class=3D"MsoNormal">import com.meterware.httpunit.WebResponse;<o:p></o:p=
></p>
<p class=3D"MsoNormal">import com.meterware.servletunit.InvocationContext;<=
o:p></o:p></p>
<p class=3D"MsoNormal">import com.meterware.servletunit.ServletRunner;<o:p>=
</o:p></p>
<p class=3D"MsoNormal">import com.meterware.servletunit.ServletUnitClient;<=
o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">public class TestValidation {<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; @org.junit.Test<o:p></o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; public void testRequiredField() {<o:=
p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; File webXml =3D=
new File("WebContent/WEB-INF/web.xml");<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; try {<o:p></o:p=
></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; &nbs=
p; &=
nbsp; ServletRunner sr =3D new ServletRunner(webXml, "/bOunceFramework=
Test");<o:p></o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; &nbs=
p; &=
nbsp; ServletUnitClient sc =3D sr.newClient();<o:p></o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; &nbs=
p; &=
nbsp; WebRequest request =3D new PostMethodWebRequest(<o:p></o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; &nbs=
p; &=
nbsp; &nbs=
p; &=
nbsp; "http://test.walgreens=
.com/bOunceFrameworkTest/StandardProxy");<o:p></o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; &nbs=
p; &=
nbsp; InvocationContext ic =3D sc.newInvocation(request);<o:p></o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; &nbs=
p; &=
nbsp; ic.service();<o:p></o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; &nbs=
p; &=
nbsp; WebResponse response =3D ic.getServletResponse();<o:p></o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; &nbs=
p; &=
nbsp; System.out.println(response.getText());<o:p></o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; &nbs=
p; &=
nbsp; assertTrue(response.getTitle()<o:p></o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; &nbs=
p; &=
nbsp; &nbs=
p; &=
nbsp; .equals("Test Server S=
ide Validation"));<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; } catch (Malfor=
medURLException e) {<o:p></o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; &nbs=
p; &=
nbsp; e.printStackTrace();<o:p></o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; } catch (Servle=
tException e) {<o:p></o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; &nbs=
p; &=
nbsp; e.printStackTrace();<o:p></o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; } catch (SAXExc=
eption e) {<o:p></o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; &nbs=
p; &=
nbsp; e.printStackTrace();<o:p></o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; } catch (IOExce=
ption e) {<o:p></o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; &nbs=
p; &=
nbsp; e.printStackTrace();<o:p></o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; }<o:p></o:p></p=
>
<p class=3D"MsoNormal"> &nbs=
p; }<o:p></o:p></p>
<p class=3D"MsoNormal">}<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">Now this code runs our StandardProxy servlet just fi=
ne *<b>except</b>* for one thing. This code in the init() method of t=
he servlet:<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; applicationReso=
urces =3D ResourceBundle<o:p></o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; .getBundle(&quo=
t;/ApplicationResources");<o:p></o:p></p>
<p class=3D"MsoNormal"> &nbs=
p; &=
nbsp; <o:p></o:p></p>
<p class=3D"MsoNormal">*<b>cannot</b>* find the file named ApplicationResou=
rces.properties. When I run the application under WebSphere or Tomcat=
there is no such problem and never has been. The file in question is=
in the root of the source directory for the
application, just as it would be in Struts 2. It is only when using =
ServletRunner that there is a problem.<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">I have tried copying the file to various places (roo=
t of the project, root of WebContent) but the file just will not be found.&=
nbsp; Is there some way to work around this problem?<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">James Simmons<o:p></o:p></p>
</div>
</body>
</html>
--_000_7EC8F5E7586FB646841E059187D0A0496A354737DMSS8MP3MBwagre_--
--===============0364892840534283908==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
--===============0364892840534283908==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Httpunit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/httpunit-develop
--===============0364892840534283908==--