001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.jaxws.description.validator;
020:
021: import org.apache.axis2.jaxws.description.EndpointDescription;
022: import org.apache.axis2.jaxws.description.EndpointDescriptionJava;
023: import org.apache.axis2.jaxws.description.EndpointDescriptionWSDL;
024: import org.apache.axis2.jaxws.description.EndpointInterfaceDescription;
025:
026: import javax.wsdl.Port;
027: import javax.wsdl.Service;
028: import javax.xml.ws.http.HTTPBinding;
029: import javax.xml.ws.soap.SOAPBinding;
030:
031: /**
032: *
033: */
034: public class EndpointDescriptionValidator extends Validator {
035: EndpointDescription endpointDesc;
036: EndpointDescriptionJava endpointDescJava;
037: EndpointDescriptionWSDL endpointDescWSDL;
038:
039: public EndpointDescriptionValidator(EndpointDescription toValidate) {
040: endpointDesc = toValidate;
041: endpointDescJava = (EndpointDescriptionJava) endpointDesc;
042: endpointDescWSDL = (EndpointDescriptionWSDL) endpointDesc;
043: }
044:
045: public boolean validate() {
046:
047: if (getValidationLevel() == ValidationLevel.OFF) {
048: return VALID;
049: }
050:
051: //The following phase II validation can only happen on the server side
052: if (endpointDesc.getServiceDescription().isServerSide()) {
053: if (!validateWSDLPort()) {
054: return INVALID;
055: }
056:
057: if (!validateWSDLBindingType()) {
058: return INVALID;
059: }
060: }
061:
062: if (!validateEndpointInterface()) {
063: return INVALID;
064: }
065: return VALID;
066: }
067:
068: private boolean validateWSDLBindingType() {
069: boolean isBindingValid = false;
070: String bindingType = endpointDesc.getBindingType();
071: String wsdlBindingType = endpointDescWSDL.getWSDLBindingType();
072: if (bindingType == null) {
073: // I don't think this can happen; the Description layer should provide a default
074: addValidationFailure(this ,
075: "Annotation binding type is null and did not have a default");
076: isBindingValid = false;
077: }
078: // Validate that the annotation value specified is valid.
079: else if (!SOAPBinding.SOAP11HTTP_BINDING.equals(bindingType)
080: && !SOAPBinding.SOAP11HTTP_MTOM_BINDING
081: .equals(bindingType)
082: && !SOAPBinding.SOAP12HTTP_BINDING.equals(bindingType)
083: && !SOAPBinding.SOAP12HTTP_MTOM_BINDING
084: .equals(bindingType)
085: && !HTTPBinding.HTTP_BINDING.equals(bindingType)) {
086: addValidationFailure(this ,
087: "Invalid annotation binding value specified: "
088: + bindingType);
089: isBindingValid = false;
090: }
091: // If there's no WSDL, then there will be no WSDL Binding Type to validate against
092: else if (wsdlBindingType == null) {
093: isBindingValid = true;
094: }
095: // Validate that the WSDL value is valid
096: else if (!EndpointDescriptionWSDL.SOAP11_WSDL_BINDING
097: .equals(wsdlBindingType)
098: && !EndpointDescriptionWSDL.SOAP12_WSDL_BINDING
099: .equals(wsdlBindingType)
100: && !EndpointDescriptionWSDL.HTTP_WSDL_BINDING
101: .equals(wsdlBindingType)) {
102: addValidationFailure(this ,
103: "Invalid wsdl binding value specified: "
104: + wsdlBindingType);
105: isBindingValid = false;
106: }
107: // Validate that the WSDL and annotations values indicate the same type of binding
108: else if (wsdlBindingType
109: .equals(EndpointDescriptionWSDL.SOAP11_WSDL_BINDING)
110: && (bindingType.equals(SOAPBinding.SOAP11HTTP_BINDING) || bindingType
111: .equals(SOAPBinding.SOAP11HTTP_MTOM_BINDING))) {
112: isBindingValid = true;
113: } else if (wsdlBindingType
114: .equals(EndpointDescriptionWSDL.SOAP12_WSDL_BINDING)
115: && (bindingType.equals(SOAPBinding.SOAP12HTTP_BINDING) || bindingType
116: .equals(SOAPBinding.SOAP12HTTP_MTOM_BINDING))) {
117: isBindingValid = true;
118: } else if (wsdlBindingType
119: .equals(EndpointDescriptionWSDL.HTTP_WSDL_BINDING)
120: && bindingType.equals(HTTPBinding.HTTP_BINDING)) {
121: isBindingValid = true;
122: }
123: // The HTTP binding is not valid on a Java Bean SEI-based endpoint; only on a Provider based one.
124: else if (wsdlBindingType
125: .equals(EndpointDescriptionWSDL.HTTP_WSDL_BINDING)
126: && endpointDesc.isEndpointBased()) {
127: addValidationFailure(this ,
128: "The HTTPBinding can not be specified for SEI-based endpoints");
129: isBindingValid = false;
130: } else {
131: addValidationFailure(this , "Invalid binding; wsdl = "
132: + wsdlBindingType + ", annotation = " + bindingType);
133: isBindingValid = false;
134: }
135: return isBindingValid;
136: }
137:
138: private boolean validateWSDLPort() {
139: // VALIDATION: If the service is specified in the WSDL, then the port must also be specified.
140: // If the service is NOT in the WSDL, then this is "partial wsdl" and there is nothing to validate
141: // against the WSDL
142: Service wsdlService = endpointDescWSDL.getWSDLService();
143: if (wsdlService != null) {
144: Port wsdlPort = endpointDescWSDL.getWSDLPort();
145: if (wsdlPort == null) {
146: addValidationFailure(
147: this ,
148: "Serivce exists in WSDL, but Port does not. Not a valid Partial WSDL. Service: "
149: + endpointDesc.getServiceQName()
150: + "; Port: "
151: + endpointDesc.getPortQName());
152: return INVALID;
153: }
154: }
155: return VALID;
156: }
157:
158: private boolean validateEndpointInterface() {
159: EndpointInterfaceDescription eid = endpointDesc
160: .getEndpointInterfaceDescription();
161: if (eid != null) {
162: EndpointInterfaceDescriptionValidator eidValidator = new EndpointInterfaceDescriptionValidator(
163: eid);
164: boolean isEndpointInterfaceValid = eidValidator.validate();
165: if (!isEndpointInterfaceValid) {
166: addValidationFailure(eidValidator,
167: "Invalid Endpoint Interface");
168: return INVALID;
169: }
170: }
171: return VALID;
172: }
173: }
|