01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.jaxws.proxy.soap12.server;
20:
21: import org.apache.axis2.jaxws.TestLogger;
22:
23: import javax.xml.ws.BindingType;
24: import javax.xml.ws.Provider;
25: import javax.xml.ws.Service.Mode;
26: import javax.xml.ws.ServiceMode;
27: import javax.xml.ws.WebServiceProvider;
28: import javax.xml.ws.soap.SOAPBinding;
29:
30: @ServiceMode(Mode.MESSAGE)
31: @BindingType(SOAPBinding.SOAP12HTTP_BINDING)
32: @WebServiceProvider(targetNamespace="http://jaxws.axis2.apache.org/proxy/soap12",wsdlLocation="META-INF/SOAP12Echo.wsdl")
33: public class SOAP12EchoImpl implements Provider<String> {
34:
35: private static final String SOAP11_NS_URI = "http://schemas.xmlsoap.org/soap/envelope/";
36: private static final String SOAP12_NS_URI = "http://www.w3.org/2003/05/soap-envelope";
37:
38: private static final String SEND_SOAP11_RESPONSE = "RESPONSE-SOAP11";
39: private static final String SEND_SOAP12_RESPONSE = "RESPONSE-SOAP12";
40:
41: public static final String SOAP11_ENVELOPE_HEAD = "<?xml version='1.0' encoding='utf-8'?>"
42: + "<soapenv:Envelope xmlns:soapenv=\""
43: + SOAP11_NS_URI
44: + "\">" + "<soapenv:Header />" + "<soapenv:Body>";
45:
46: public static final String SOAP12_ENVELOPE_HEAD = "<?xml version='1.0' encoding='utf-8'?>"
47: + "<soapenv:Envelope xmlns:soapenv=\""
48: + SOAP12_NS_URI
49: + "\">" + "<soapenv:Header />" + "<soapenv:Body>";
50:
51: public static final String SOAP11_ENVELOPE_TAIL = "</soapenv:Body>"
52: + "</soapenv:Envelope>";
53:
54: public static final String SOAP12_ENVELOPE_TAIL = "</soapenv:Body>"
55: + "</soapenv:Envelope>";
56:
57: public String invoke(String input) {
58: TestLogger.logger.debug("received request [" + input + "]");
59:
60: // check the request to see if it contains the SOAP 1.1 namespace
61: // URI. if so, then that is an error and we should respond with
62: // a failure.
63: String status = "FAIL";
64: if (input.indexOf(SOAP12_NS_URI) > 0) {
65: status = "PASS";
66: TestLogger.logger
67: .debug("the request contains the SOAP 1.2 namespace as expected.");
68: } else {
69: TestLogger.logger
70: .debug("the request did NOT contain the SOAP 1.2 namespace.");
71: TestLogger.logger.debug("sending back a failure");
72: }
73:
74: // the contents of the response should contain the status
75: String responseBody = "<echoResponse xmlns=\"http://jaxws.axis2.apache.org/proxy/soap12\">"
76: + "<response>"
77: + status
78: + "</response>"
79: + "</echoResponse>";
80:
81: // build up the appropriate envelope type for the response
82: // based on what was the client requested.
83: StringBuffer response = new StringBuffer();
84: if (input.indexOf(SEND_SOAP11_RESPONSE) > 0) {
85: response.append(SOAP11_ENVELOPE_HEAD);
86: response.append(responseBody);
87: response.append(SOAP11_ENVELOPE_TAIL);
88: } else if (input.indexOf(SEND_SOAP12_RESPONSE) > 0) {
89: response.append(SOAP12_ENVELOPE_HEAD);
90: response.append(responseBody);
91: response.append(SOAP12_ENVELOPE_TAIL);
92: }
93:
94: TestLogger.logger.debug("sending response [" + response + "]");
95: return response.toString();
96: }
97: }
|