1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.transport.http;
18
19 import java.io.IOException;
20
21 import org.apache.commons.httpclient.HttpClient;
22 import org.apache.commons.httpclient.methods.GetMethod;
23 import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
24 import org.apache.commons.httpclient.methods.PostMethod;
25
26 import org.springframework.core.io.ClassPathResource;
27 import org.springframework.core.io.Resource;
28 import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
29 import org.springframework.ws.transport.TransportConstants;
30
31 public class WebServiceHttpHandlerIntegrationTest extends AbstractDependencyInjectionSpringContextTests {
32
33 private HttpClient client;
34
35 protected String[] getConfigLocations() {
36 return new String[]{"classpath:org/springframework/ws/transport/http/httpserver-applicationContext.xml"};
37 }
38
39 protected void onSetUp() throws Exception {
40 client = new HttpClient();
41 }
42
43 public void testInvalidMethod() throws IOException {
44 GetMethod getMethod = new GetMethod("http://localhost:8888/service");
45 client.executeMethod(getMethod);
46 assertEquals("Invalid Response Code", HttpTransportConstants.STATUS_METHOD_NOT_ALLOWED,
47 getMethod.getStatusCode());
48 assertEquals("Response retrieved", 0, getMethod.getResponseContentLength());
49 }
50
51 public void testNoResponse() throws IOException {
52 PostMethod postMethod = new PostMethod("http://localhost:8888/service");
53 postMethod.addRequestHeader(HttpTransportConstants.HEADER_CONTENT_TYPE, "text/xml");
54 postMethod.addRequestHeader(TransportConstants.HEADER_SOAP_ACTION,
55 "http://springframework.org/spring-ws/NoResponse");
56 Resource soapRequest = new ClassPathResource("soapRequest.xml", WebServiceHttpHandlerIntegrationTest.class);
57 postMethod.setRequestEntity(new InputStreamRequestEntity(soapRequest.getInputStream()));
58 client.executeMethod(postMethod);
59 assertEquals("Invalid Response Code", HttpTransportConstants.STATUS_ACCEPTED, postMethod.getStatusCode());
60 assertEquals("Response retrieved", 0, postMethod.getResponseContentLength());
61 }
62
63 public void testResponse() throws IOException {
64 PostMethod postMethod = new PostMethod("http://localhost:8888/service");
65 postMethod.addRequestHeader(HttpTransportConstants.HEADER_CONTENT_TYPE, "text/xml");
66 postMethod.addRequestHeader(TransportConstants.HEADER_SOAP_ACTION,
67 "http://springframework.org/spring-ws/Response");
68 Resource soapRequest = new ClassPathResource("soapRequest.xml", WebServiceHttpHandlerIntegrationTest.class);
69 postMethod.setRequestEntity(new InputStreamRequestEntity(soapRequest.getInputStream()));
70 client.executeMethod(postMethod);
71 assertEquals("Invalid Response Code", HttpTransportConstants.STATUS_OK, postMethod.getStatusCode());
72 assertTrue("No Response retrieved", postMethod.getResponseContentLength() > 0);
73 }
74
75 public void testNoEndpoint() throws IOException {
76 PostMethod postMethod = new PostMethod("http://localhost:8888/service");
77 postMethod.addRequestHeader(HttpTransportConstants.HEADER_CONTENT_TYPE, "text/xml");
78 postMethod.addRequestHeader(TransportConstants.HEADER_SOAP_ACTION,
79 "http://springframework.org/spring-ws/NoEndpoint");
80 Resource soapRequest = new ClassPathResource("soapRequest.xml", WebServiceHttpHandlerIntegrationTest.class);
81 postMethod.setRequestEntity(new InputStreamRequestEntity(soapRequest.getInputStream()));
82 client.executeMethod(postMethod);
83 assertEquals("Invalid Response Code", HttpTransportConstants.STATUS_NOT_FOUND, postMethod.getStatusCode());
84 assertEquals("Response retrieved", 0, postMethod.getResponseContentLength());
85 }
86
87 public void testFault() throws IOException {
88 PostMethod postMethod = new PostMethod("http://localhost:8888/service");
89 postMethod.addRequestHeader(HttpTransportConstants.HEADER_CONTENT_TYPE, "text/xml");
90 postMethod
91 .addRequestHeader(TransportConstants.HEADER_SOAP_ACTION, "http://springframework.org/spring-ws/Fault");
92 Resource soapRequest = new ClassPathResource("soapRequest.xml", WebServiceHttpHandlerIntegrationTest.class);
93 postMethod.setRequestEntity(new InputStreamRequestEntity(soapRequest.getInputStream()));
94 client.executeMethod(postMethod);
95 assertEquals("Invalid Response Code", HttpTransportConstants.STATUS_INTERNAL_SERVER_ERROR,
96 postMethod.getStatusCode());
97 assertTrue("No Response retrieved", postMethod.getResponseContentLength() > 0);
98 }
99
100 }