Re: Error on HTTP request: 404 No servlet mapping defined
Wolfgang Fahl <[email protected]> Mon, 12 Nov 2012 09:42:53 +0100
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Organization | BITPlan GmbH |
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--===============5566200227915736606==
Content-Type: multipart/alternative;
boundary="------------020606070008070400030207"
This is a multi-part message in MIME format.
--------------020606070008070400030207
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Dear Mostafa,
please find below a test case I just added to show what IMHO is happening.
You might want to register your servlet with the fully qualifying url.
If you register "validateLogin" but use "ISB/validateLogin"
you'll get the exception you are seeing (as shown by the JUnit test case
below.
You are kindly invited to post your question on stackoverflow.com with
the tag httpunit to let others know about this handling issue.
Yours
Wolfgang
@Test
/**
* Test added by WF 2012-11-12 to answer question on developers
mailing list
* @throws Exception
*/
public void testInvalidConfig() throws Exception {
final String resourceName = "something/interesting";
ServletRunner sr = new ServletRunner();
sr.registerServlet(resourceName, ConfigServlet.class.getName());
WebClient wc = sr.newClient();
try {
WebResponse response = wc.getResponse("http://localhost/" +
"ISB/"+ resourceName);
fail("No Exception thrown");
} catch (Throwable th) {
// com.meterware.httpunit.HttpNotFoundException:
// Error on HTTP request: 404 No servlet mapping defined
[http://localhost/ISB/something/interesting]
String expected="Error on HTTP request: 404 No servlet mapping
defined [http://localhost/ISB/something/interesting]";
assertTrue("HttpNotFoundException expected",th instanceof
HttpNotFoundException);
assertEquals("wrong exception message",expected,th.getMessage());
}
}
Am 12.11.12 01:38, schrieb mostafa kandil:
> Hi httpunit developers team:
> first i appreciate the work of httpunit framework, i have 4 weeks ago
> searching for a tool i can use to test java Servlet. so when i found
> your framework, i was so happy :D .
> i have downloaded last released, and tried a simple case:
>
> void test(){
> try {
> ServletRunner sr = new ServletRunner();
> sr.registerServlet("validateLogin",
> "validateLogin");
> // or
> sr.registerServlet("validateLogin",
> validateLogin.class.getName());
> ServletUnitClient sc = sr.newClient();
> WebRequest request = new
> PostMethodWebRequest("http://cuportal.cu.edu.eg:8080/ISB/validateLogin");
>
> request.setParameter("un", "user1");
> request.setParameter("pwd", "userpwd");
>
> WebResponse response = sc.getResponse(request);
> assertEquals("requested resource",
> "user_page.jsp", response.getText());
> } catch (Exception e) {
> System.err.println("ERROR: " + e);
> e.printStackTrace();
> }
> }
>
> Always i got exception at red line :
>
> ERROR: com.meterware.httpunit.HttpNotFoundException:
> Error on HTTP request: 404 No servlet mapping defined
> [http://cuportal.cu.edu.eg:8080/ISB/validateLogin]
> ___________________________________
> com.meterware.httpunit.HttpNotFoundException: Error on
> HTTP request: 404 No servlet mapping defined
> [http://cuportal.cu.edu.eg:8080/ISB/validateLogin]
> at
> com.meterware.servletunit.WebApplication$ServletRequestImpl.getServlet(WebApplication.java:772)
> at
> com.meterware.servletunit.InvocationContextImpl$ExecutionContext.getServlet(InvocationContextImpl.java:248)
> at
> com.meterware.servletunit.InvocationContextImpl.getServlet(InvocationContextImpl.java:86)
> at
> com.meterware.servletunit.InvocationContextImpl.service(InvocationContextImpl.java:76)
> at
> com.meterware.servletunit.ServletUnitClient.newResponse(ServletUnitClient.java:126)
> at
> com.meterware.httpunit.WebClient.createResponse(WebClient.java:647)
> at
> com.meterware.httpunit.WebWindow.getResource(WebWindow.java:220)
> at
> com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:181)
> at
> com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:158)
> at
> com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:125)
> at
> com.meterware.httpunit.WebClient.getResponse(WebClient.java:96)
> at myServletTest.testISB(myServletTest.java:65)
> at myServletTest.<init>(myServletTest.java:21)
> at myServletTest.main(myServletTest.java:81)
>
> i'm using 'Java EE 6 Web', and netbeans tool.
> i have added all libraries.
>
> Can you help me please solve that exception?
>
> thanks in advance
>
>
>
>
>
>
>
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_nov
>
>
> _______________________________________________
> Httpunit-develop mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/httpunit-develop
--
BITPlan - smart solutions
Wolfgang Fahl
Pater-Delp-Str. 1, D-47877 Willich Schiefbahn
Tel. +49 2154 811-480, Fax +49 2154 811-481
Web: http://www.bitplan.de
BITPlan GmbH, Willich - HRB 6820 Krefeld, Steuer-Nr.: 10258040548, Geschäftsführer: Wolfgang Fahl
--------------020606070008070400030207
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Dear Mostafa,<br>
<br>
please find below a test case I just added to show what IMHO is
happening.<br>
You might want to register your servlet with the fully qualifying
url. If you register "validateLogin" but use "ISB/validateLogin"<br>
you'll get the exception you are seeing (as shown by the JUnit test
case below.<br>
<br>
You are kindly invited to post your question on stackoverflow.com
with the tag httpunit to let others know about this handling issue.<br>
<br>
Yours<br>
Wolfgang <br>
<br>
@Test<br>
/**<br>
* Test added by WF 2012-11-12 to answer question on developers
mailing list<br>
* @throws Exception<br>
*/<br>
public void testInvalidConfig() throws Exception {<br>
final String resourceName = "something/interesting";<br>
<br>
ServletRunner sr = new ServletRunner();<br>
sr.registerServlet(resourceName,
ConfigServlet.class.getName());<br>
WebClient wc = sr.newClient();<br>
try {<br>
WebResponse response = wc.getResponse(<a class="moz-txt-link-rfc2396E" href="http://localhost/">"http://localhost/"</a>
+ "ISB/"+ resourceName);<br>
fail("No Exception thrown");<br>
} catch (Throwable th) {<br>
// com.meterware.httpunit.HttpNotFoundException: <br>
// Error on HTTP request: 404 No servlet mapping defined
[<a class="moz-txt-link-freetext" href="http://localhost/ISB/something/interesting">http://localhost/ISB/something/interesting</a>]<br>
String expected="Error on HTTP request: 404 No servlet
mapping defined [<a class="moz-txt-link-freetext" href="http://localhost/ISB/something/interesting">http://localhost/ISB/something/interesting</a>]";<br>
assertTrue("HttpNotFoundException expected",th instanceof
HttpNotFoundException);<br>
assertEquals("wrong exception
message",expected,th.getMessage());<br>
}<br>
}<br>
<br>
<br>
Am 12.11.12 01:38, schrieb mostafa kandil:<br>
<blockquote
cite="mid:[email protected]"
type="cite">
<div style="color:#000; background-color:#fff; font-family:times
new roman, new york, times, serif;font-size:14pt">
<div style="font-family: 'times new roman', 'new york', times,
serif; font-size: 14pt;">Hi httpunit developers team:</div>
<div><font size="4" face="times new roman, new york, times,
serif">first i </font><font face="times new roman, new york,
times, serif"><span style="font-size: 19px;">appreciate the
work of httpunit framework, i have 4 weeks ago searching
for a tool i can use to test java Servlet. so when i found
your framework, i was so happy :D . </span></font></div>
<div style="color: rgb(0, 0, 0); font-size: 19px; font-family:
'times new roman', 'new york', times, serif; background-color:
transparent; font-style: normal;"><font
style="background-color: transparent;" face="times new
roman, new york, times, serif">i have downloaded last </font><span
style="background-color: transparent;">released, and tried a
simple case:</span><br>
</div>
<blockquote style="border: none; padding: 0px;">
<blockquote style="border: none; padding: 0px;">
<blockquote style="border: none; padding: 0px;">
<div style="background-color: transparent;">
<div style="background-color: transparent;">
<div style="background-color: transparent;"><span
style="font-family: 'lucida console', sans-serif;
font-size: 13px;">void test(){</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'lucida console', sans-serif;
font-size: 13px;"> try {</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'lucida console', sans-serif;
font-size: 13px;"> ServletRunner sr =
new ServletRunner();</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'lucida console', sans-serif;
font-size: 13px;">
sr.registerServlet("validateLogin",
"validateLogin"); </span></div>
<div style="background-color: transparent; color:
rgb(0, 0, 0); font-size: 13px; font-family: 'lucida
console', sans-serif; font-style: normal;"><span
style="font-family: 'lucida console', sans-serif;
font-size: 13px;"> // or
sr.registerServlet("validateLogin",
validateLogin.class.getName());</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'lucida console', sans-serif;
font-size: 13px;"> ServletUnitClient sc
= sr.newClient();</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'lucida console', sans-serif;
font-size: 13px;"> WebRequest request =
new
PostMethodWebRequest(<a class="moz-txt-link-rfc2396E" href="http://cuportal.cu.edu.eg:8080/ISB/validateLogin">"http://cuportal.cu.edu.eg:8080/ISB/validateLogin"</a>);</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'lucida console', sans-serif;
font-size: 13px;"><br>
</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'lucida console', sans-serif;
font-size: 13px;">
request.setParameter("un", "user1");</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'lucida console', sans-serif;
font-size: 13px;">
request.setParameter("pwd", "userpwd"); </span></div>
<div style="background-color: transparent;"><span
style="font-family: 'lucida console', sans-serif;
font-size: 13px;"> </span></div>
<div style="background-color: transparent;"><span
style="font-weight: bold; color: rgb(255, 0, 0);
font-family: 'lucida console', sans-serif;
font-size: 13px;"> WebResponse response
= sc.getResponse(request);</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'lucida console', sans-serif;
font-size: 13px;">
assertEquals("requested resource",
"user_page.jsp", response.getText());</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'lucida console', sans-serif;
font-size: 13px;"> } catch (Exception e) {</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'lucida console', sans-serif;
font-size: 13px;">
System.err.println("ERROR: " + e);</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'lucida console', sans-serif;
font-size: 13px;"> e.printStackTrace();</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'lucida console', sans-serif;
font-size: 13px;"> }</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'lucida console', sans-serif;
font-size: 13px;">}</span></div>
</div>
</div>
</blockquote>
</blockquote>
</blockquote>
<span style="background-color: transparent; font-family: 'times
new roman', 'new york', times, serif; font-size: 18px;">Always
i got exception at red line :</span><br>
<blockquote style="border: none; padding: 0px;">
<blockquote style="border: none; padding: 0px;">
<blockquote style="border: none; padding: 0px;">
<div style="background-color: transparent;">
<div style="background-color: transparent;">
<div style="background-color: transparent;"><span
style="color: rgb(255, 0, 0);"><span
style="font-family: 'times new roman', 'new
york', times, serif; font-size: 16px;
font-style: normal;"><span style="font-family:
'times new roman', 'new york', times, serif;"> </span></span><span
style="background-color: transparent;
font-family: 'times new roman', 'new york',
times, serif;">ERROR:
com.meterware.httpunit.HttpNotFoundException:
Error on HTTP request: 404 No servlet mapping
defined
[<a class="moz-txt-link-freetext" href="http://cuportal.cu.edu.eg:8080/ISB/validateLogin">http://cuportal.cu.edu.eg:8080/ISB/validateLogin</a>]</span></span></div>
<div style="background-color: transparent;"><span
style="font-family: 'times new roman', 'new york',
times, serif; color: rgb(255, 0, 0);">___________________________________</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'times new roman', 'new york',
times, serif; color: rgb(255, 0, 0);">com.meterware.httpunit.HttpNotFoundException:
Error on HTTP request: 404 No servlet mapping
defined
[<a class="moz-txt-link-freetext" href="http://cuportal.cu.edu.eg:8080/ISB/validateLogin">http://cuportal.cu.edu.eg:8080/ISB/validateLogin</a>]</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'times new roman', 'new york',
times, serif; color: rgb(255, 0, 0);"><span
class="Apple-tab-span" style="white-space:pre">
</span>at
com.meterware.servletunit.WebApplication$ServletRequestImpl.getServlet(WebApplication.java:772)</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'times new roman', 'new york',
times, serif; color: rgb(255, 0, 0);"><span
class="Apple-tab-span" style="white-space:pre">
</span>at
com.meterware.servletunit.InvocationContextImpl$ExecutionContext.getServlet(InvocationContextImpl.java:248)</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'times new roman', 'new york',
times, serif; color: rgb(255, 0, 0);"><span
class="Apple-tab-span" style="white-space:pre">
</span>at
com.meterware.servletunit.InvocationContextImpl.getServlet(InvocationContextImpl.java:86)</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'times new roman', 'new york',
times, serif; color: rgb(255, 0, 0);"><span
class="Apple-tab-span" style="white-space:pre">
</span>at
com.meterware.servletunit.InvocationContextImpl.service(InvocationContextImpl.java:76)</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'times new roman', 'new york',
times, serif; color: rgb(255, 0, 0);"><span
class="Apple-tab-span" style="white-space:pre">
</span>at
com.meterware.servletunit.ServletUnitClient.newResponse(ServletUnitClient.java:126)</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'times new roman', 'new york',
times, serif; color: rgb(255, 0, 0);"><span
class="Apple-tab-span" style="white-space:pre">
</span>at
com.meterware.httpunit.WebClient.createResponse(WebClient.java:647)</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'times new roman', 'new york',
times, serif; color: rgb(255, 0, 0);"><span
class="Apple-tab-span" style="white-space:pre">
</span>at
com.meterware.httpunit.WebWindow.getResource(WebWindow.java:220)</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'times new roman', 'new york',
times, serif; color: rgb(255, 0, 0);"><span
class="Apple-tab-span" style="white-space:pre">
</span>at
com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:181)</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'times new roman', 'new york',
times, serif; color: rgb(255, 0, 0);"><span
class="Apple-tab-span" style="white-space:pre">
</span>at
com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:158)</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'times new roman', 'new york',
times, serif; color: rgb(255, 0, 0);"><span
class="Apple-tab-span" style="white-space:pre">
</span>at
com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:125)</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'times new roman', 'new york',
times, serif; color: rgb(255, 0, 0);"><span
class="Apple-tab-span" style="white-space:pre">
</span>at
com.meterware.httpunit.WebClient.getResponse(WebClient.java:96)</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'times new roman', 'new york',
times, serif; color: rgb(255, 0, 0);"><span
class="Apple-tab-span" style="white-space:pre">
</span>at
myServletTest.testISB(myServletTest.java:65)</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'times new roman', 'new york',
times, serif; color: rgb(255, 0, 0);"><span
class="Apple-tab-span" style="white-space:pre">
</span>at
myServletTest.<init>(myServletTest.java:21)</span></div>
<div style="background-color: transparent;"><span
style="font-family: 'times new roman', 'new york',
times, serif; color: rgb(255, 0, 0);"><span
class="Apple-tab-span" style="white-space: pre;">
</span>at
myServletTest.main(myServletTest.java:81)</span></div>
<div style="background-color: transparent; color:
rgb(255, 0, 0); font-size: 16px; font-family: 'times
new roman', 'new york', times, serif; font-style:
normal;"><span style="font-family: 'times new
roman', 'new york', times, serif; color: rgb(255,
0, 0);"><br>
</span></div>
</div>
</div>
</blockquote>
</blockquote>
</blockquote>
<span style="font-size: 18px; background-color: transparent;
font-family: 'times new roman', 'new york', times, serif;">i'm
using 'Java EE 6 Web', and </span><span style="font-size:
18px; background-color: transparent; font-family: 'times new
roman', 'new york', times, serif;">netbeans tool.</span>
<div><span><span style="font-family: 'times new roman', 'new
york', times, serif; font-size: 18px;">i have added
all libraries.</span></span></div>
<div><span><span style="font-family: 'times new roman', 'new
york', times, serif; font-size: 18px;"><br>
</span></span></div>
<div><span><span style="font-family: 'times new roman', 'new
york', times, serif; font-size: 18px;">Can you help me
please solve that exception? </span></span></div>
<div><br>
</div>
<div><span><span style="font-family: 'times new roman', 'new
york', times, serif; font-size: 18px;">thanks in advance<br>
</span></span>
<blockquote style="border: none; padding: 0px;">
<blockquote style="border: none; padding: 0px;">
<blockquote style="border: none; padding: 0px;">
<div style="background-color: transparent;">
<div style="background-color: transparent;">
<div style="background-color: transparent; color:
rgb(0, 0, 0); font-size: 16px; font-family: 'times
new roman', 'new york', times, serif; font-style:
normal;"><span><span style="font-family: 'times
new roman', 'new york', times, serif;"> </span></span></div>
</div>
</div>
</blockquote>
</blockquote>
</blockquote>
<div style="background-color: transparent;">
<div style="background-color: transparent; font-family:
'times new roman', 'new york', times, serif; font-style:
normal; color: rgb(192, 0, 0); font-size: 16px;"><font
face="times new roman, new york, times, serif"><span
style="color: rgb(192, 0, 0);"><br>
</span></font></div>
</div>
<div style="color: rgb(0, 0, 0); font-size: 19px; font-family:
'times new roman', 'new york', times, serif;
background-color: transparent; font-style: normal;"><br>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
<a class="moz-txt-link-freetext" href="http://p.sf.net/sfu/appdyn_d2d_nov">http://p.sf.net/sfu/appdyn_d2d_nov</a></pre>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Httpunit-develop mailing list
<a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<a class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/httpunit-develop">https://lists.sourceforge.net/lists/listinfo/httpunit-develop</a>
</pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
BITPlan - smart solutions
Wolfgang Fahl
Pater-Delp-Str. 1, D-47877 Willich Schiefbahn
Tel. +49 2154 811-480, Fax +49 2154 811-481
Web: <a class="moz-txt-link-freetext" href="http://www.bitplan.de">http://www.bitplan.de</a>
BITPlan GmbH, Willich - HRB 6820 Krefeld, Steuer-Nr.: 10258040548, Geschäftsführer: Wolfgang Fahl </pre>
</body>
</html>
--------------020606070008070400030207--
--===============5566200227915736606==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_nov
--===============5566200227915736606==
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
--===============5566200227915736606==--