WebServiceMessageReceiverHandlerAdapter extends WebServiceMessageReceiverObjectSupport implements HandlerAdapter { @Override public ModelAndView handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object handler) throws Exception { if (HttpTransportConstants.METHOD_POST.equals(httpServletRequest.getMethod())) { WebServiceConnection connection = new HttpServletConnection(httpServletRequest, httpServletResponse); try { handleConnection(connection, (WebServiceMessageReceiver) handler); } catch (InvalidXmlException ex) { handleInvalidXmlException(httpServletRequest, httpServletResponse, handler, ex); } } else { handleNonPostMethod(httpServletRequest, httpServletResponse, handler); } return null; }  @Override long getLastModified(HttpServletRequest request, Object handler); @Override ModelAndView handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
			Object handler); @Override boolean supports(Object handler);  }
@Test public void testHandleNonPost() throws Exception { httpRequest.setMethod(HttpTransportConstants.METHOD_GET); replayMockControls(); WebServiceMessageReceiver endpoint = new WebServiceMessageReceiver() { @Override public void receive(MessageContext messageContext) throws Exception {} }; adapter.handle(httpRequest, httpResponse, endpoint); Assert.assertEquals("METHOD_NOT_ALLOWED expected", HttpServletResponse.SC_METHOD_NOT_ALLOWED, httpResponse.getStatus()); verifyMockControls(); }
@Test public void testHandlePostNoResponse() throws Exception { httpRequest.setMethod(HttpTransportConstants.METHOD_POST); httpRequest.setContent(REQUEST.getBytes("UTF-8")); httpRequest.setContentType("text/xml; charset=\"utf-8\""); httpRequest.setCharacterEncoding("UTF-8"); expect(factoryMock.createWebServiceMessage(isA(InputStream.class))).andReturn(responseMock); replayMockControls(); WebServiceMessageReceiver endpoint = new WebServiceMessageReceiver() { @Override public void receive(MessageContext messageContext) throws Exception {} }; adapter.handle(httpRequest, httpResponse, endpoint); Assert.assertEquals("Invalid status code on response", HttpServletResponse.SC_ACCEPTED, httpResponse.getStatus()); Assert.assertEquals("Response written", 0, httpResponse.getContentAsString().length()); verifyMockControls(); }
@Test public void testHandlePostResponse() throws Exception { httpRequest.setMethod(HttpTransportConstants.METHOD_POST); httpRequest.setContent(REQUEST.getBytes("UTF-8")); httpRequest.setContentType("text/xml; charset=\"utf-8\""); httpRequest.setCharacterEncoding("UTF-8"); expect(factoryMock.createWebServiceMessage(isA(InputStream.class))).andReturn(requestMock); expect(factoryMock.createWebServiceMessage()).andReturn(responseMock); expect(responseMock.getFaultCode()).andReturn(null); responseMock.writeTo(isA(OutputStream.class)); replayMockControls(); WebServiceMessageReceiver endpoint = new WebServiceMessageReceiver() { @Override public void receive(MessageContext messageContext) throws Exception { messageContext.getResponse(); } }; adapter.handle(httpRequest, httpResponse, endpoint); Assert.assertEquals("Invalid status code on response", HttpServletResponse.SC_OK, httpResponse.getStatus()); verifyMockControls(); }
@Test public void testHandlePostFault() throws Exception { httpRequest.setMethod(HttpTransportConstants.METHOD_POST); httpRequest.setContent(REQUEST.getBytes("UTF-8")); httpRequest.setContentType("text/xml; charset=\"utf-8\""); httpRequest.setCharacterEncoding("UTF-8"); expect(factoryMock.createWebServiceMessage(isA(InputStream.class))).andReturn(requestMock); expect(factoryMock.createWebServiceMessage()).andReturn(responseMock); expect(responseMock.getFaultCode()).andReturn(SoapVersion.SOAP_11.getServerOrReceiverFaultName()); responseMock.writeTo(isA(OutputStream.class)); replayMockControls(); WebServiceMessageReceiver endpoint = new WebServiceMessageReceiver() { @Override public void receive(MessageContext messageContext) throws Exception { messageContext.getResponse(); } }; adapter.handle(httpRequest, httpResponse, endpoint); Assert.assertEquals("Invalid status code on response", HttpServletResponse.SC_INTERNAL_SERVER_ERROR, httpResponse.getStatus()); verifyMockControls(); }
@Test public void testHandleNotFound() throws Exception { httpRequest.setMethod(HttpTransportConstants.METHOD_POST); httpRequest.setContent(REQUEST.getBytes("UTF-8")); httpRequest.setContentType("text/xml; charset=\"utf-8\""); httpRequest.setCharacterEncoding("UTF-8"); expect(factoryMock.createWebServiceMessage(isA(InputStream.class))).andReturn(requestMock); replayMockControls(); WebServiceMessageReceiver endpoint = new WebServiceMessageReceiver() { @Override public void receive(MessageContext messageContext) throws Exception { throw new NoEndpointFoundException(messageContext.getRequest()); } }; adapter.handle(httpRequest, httpResponse, endpoint); Assert.assertEquals("No 404 returned", HttpServletResponse.SC_NOT_FOUND, httpResponse.getStatus()); verifyMockControls(); }
@Test public void testHandleInvalidXml() throws Exception { httpRequest.setMethod(HttpTransportConstants.METHOD_POST); httpRequest.setContent(REQUEST.getBytes("UTF-8")); httpRequest.setContentType("text/xml; charset=\"utf-8\""); httpRequest.setCharacterEncoding("UTF-8"); expect(factoryMock.createWebServiceMessage(isA(InputStream.class))).andThrow(new InvalidXmlException(null, null)); replayMockControls(); WebServiceMessageReceiver endpoint = new WebServiceMessageReceiver() { @Override public void receive(MessageContext messageContext) throws Exception {} }; adapter.handle(httpRequest, httpResponse, endpoint); Assert.assertEquals("No 400 returned", HttpServletResponse.SC_BAD_REQUEST, httpResponse.getStatus()); verifyMockControls(); }