Jetty always returning 400 status code on Java HttpServlet

I'm currently trying to get a unit test set up for an HttpServlet class I have in Java. However, the Jetty documentation is kind of lacking and I'm a little stuck. I'm fairly certain the contextPath is /hbc as I printed it out using getContextPath() in the servlet. However, I'm not certain what a) the second parameter to the addServlet() method should be and b) what the URI should be. The status code keeps returning back as 400 and the content is null. I'm not sure if it's because i'm not pointing to the right location (but I would think that would lead to a 404) or if something else is missing. The servlet has an init(), processRequest(), doGet(), and doPost() method. Thoughts? public class HBCUnitTests extends TestCase { private ServletTester tester; @BeforeClass public void setUp() throws Exception { tester = new ServletTester(); tester.setContextPath("/hbc"); tester.addServlet(HubCommServlet.class, "/"); tester.start(); } @AfterClass public void tearDown() throws Exception { tester.stop(); } @Test public void test() throws Exception { HttpTester request = new HttpTester(); request.setMethod("POST"); request.setVersion("HTTP/1.1"); request.setURI("/"); System.out.println(request.generate()); HttpTester response = new HttpTester(); response.parse(tester.getResponses(request.generate())); System.out.println(response.getContent()); System.out.println(response.getURI()); System.out.println(response.getReason()); assertEquals(200,response.getStatus()); assertEquals("

Hello Servlet

",response.getContent()); } }

以上就是Jetty always returning 400 status code on Java HttpServlet的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准