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.message;
20:
21: import org.apache.commons.logging.Log;
22: import org.apache.commons.logging.LogFactory;
23:
24: import javax.xml.ws.http.HTTPBinding;
25: import javax.xml.ws.soap.SOAPBinding;
26:
27: /**
28: * Protocol Each message has a protocol (soap11, soap12, rest) This enum represents the protocol
29: * within the Message sub-component
30: */
31: public enum Protocol {
32: soap11, soap12, rest, unknown;
33:
34: private static final Log log = LogFactory.getLog(Protocol.class);
35:
36: // These namespaces are used in the WSDL document to indentify a
37: // SOAP 1.1 vs. a SOAP 1.2 binding
38: private static final String SOAP11_WSDL_BINDING = "http://schemas.xmlsoap.org/wsdl/soap";
39: private static final String SOAP12_WSDL_BINDING = "http://schemas.xmlsoap.org/wsdl/soap12";
40:
41: /**
42: * Return the right value for the Protocol based on the binding URL that was passed in.
43: *
44: * @param url
45: * @return Protocol or null
46: */
47: public static Protocol getProtocolForBinding(String url) {
48: boolean debug = log.isDebugEnabled();
49: if (debug) {
50: log.debug("Configuring message protocol for binding ["
51: + url + "]");
52: }
53:
54: if (namespaceEquals(Protocol.SOAP11_WSDL_BINDING, url)
55: || namespaceEquals(SOAPBinding.SOAP11HTTP_BINDING, url)
56: || namespaceEquals(SOAPBinding.SOAP11HTTP_MTOM_BINDING,
57: url)) {
58: if (debug) {
59: log.debug("SOAP 1.1 protocol configured for message");
60: }
61: return Protocol.soap11;
62: } else if (namespaceEquals(Protocol.SOAP12_WSDL_BINDING, url)
63: || namespaceEquals(SOAPBinding.SOAP12HTTP_BINDING, url)
64: || namespaceEquals(SOAPBinding.SOAP12HTTP_MTOM_BINDING,
65: url)) {
66: if (debug) {
67: log.debug("SOAP 1.2 protocol configured for message");
68: }
69: return Protocol.soap12;
70: } else if (namespaceEquals(HTTPBinding.HTTP_BINDING, url)) {
71: if (debug) {
72: log.debug("XML/HTTP protocol configured for message");
73: }
74: return Protocol.rest;
75: } else {
76: if (debug) {
77: log.debug("Protocol was not found for:" + url);
78: }
79: return null;
80: }
81: }
82:
83: /*
84: * Check to see if the two strings (namespaces) passed in are the same, but
85: * also accounts for any trailing "/" characters in the string.
86: */
87: private static boolean namespaceEquals(String target, String input) {
88: if (target.equals(input)) {
89: return true;
90: } else if ((target + "/").equals(input)) {
91: return true;
92: }
93:
94: return false;
95: }
96: }
|