From scm-return-46200-apmail-geronimo-scm-archive=geronimo.apache.org@geronimo.apache.org Tue May 10 04:34:18 2011 Return-Path: X-Original-To: apmail-geronimo-scm-archive@www.apache.org Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1A1195D50 for ; Tue, 10 May 2011 04:34:18 +0000 (UTC) Received: (qmail 31507 invoked by uid 500); 10 May 2011 04:34:16 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 31468 invoked by uid 500); 10 May 2011 04:34:15 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 31461 invoked by uid 99); 10 May 2011 04:34:15 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 May 2011 04:34:15 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 May 2011 04:34:09 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 29E2723889EA; Tue, 10 May 2011 04:33:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1101307 - in /geronimo/bundles/trunk/axis2: pom.xml src/main/java/org/apache/axis2/jaxws/BindingProvider.java src/main/java/org/apache/axis2/jaxws/context/ src/main/java/org/apache/axis2/jaxws/context/WebServiceContextImpl.java Date: Tue, 10 May 2011 04:33:47 -0000 To: scm@geronimo.apache.org From: xuhaihong@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110510043347.29E2723889EA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: xuhaihong Date: Tue May 10 04:33:46 2011 New Revision: 1101307 URL: http://svn.apache.org/viewvc?rev=1101307&view=rev Log: Try AXIS2-5021 from Geronimo side Added: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/BindingProvider.java (with props) geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/context/ geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/context/WebServiceContextImpl.java (with props) Modified: geronimo/bundles/trunk/axis2/pom.xml Modified: geronimo/bundles/trunk/axis2/pom.xml URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/axis2/pom.xml?rev=1101307&r1=1101306&r2=1101307&view=diff ============================================================================== --- geronimo/bundles/trunk/axis2/pom.xml (original) +++ geronimo/bundles/trunk/axis2/pom.xml Tue May 10 04:33:46 2011 @@ -209,10 +209,67 @@ + + org.apache.geronimo.specs + geronimo-jaxws_2.2_spec + 1.0 + + + org.apache.geronimo.specs + geronimo-jaxb_2.2_spec + 1.0.1 + + + org.apache.geronimo.specs + geronimo-saaj_1.3_spec + 1.1 + + maven-dependency-plugin + + + generate-resources + + copy + + + + + org.apache.geronimo.specs + geronimo-jaxb_2.2_spec + + + org.apache.geronimo.specs + geronimo-saaj_1.3_spec + + + org.apache.geronimo.specs + geronimo-jaxws_2.2_spec + + + true + ${project.build.directory}/endorsed + true + + + + + + maven-compiler-plugin + true + + + -Xbootclasspath/p:${project.build.directory}/endorsed/geronimo-jaxws_2.2_spec.jar${path.separator}${project.build.directory}/endorsed/geronimo-saaj_1.3_spec.jar${path.separator}${project.build.directory}/endorsed/geronimo-jaxb_2.2_spec.jar + + 1.5 + 1.5 + 1.5 + + + org.apache.felix maven-bundle-plugin @@ -257,7 +314,10 @@ org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl$4.class=target/classes/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl$4.class, org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl$5.class=target/classes/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl$5.class, org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl$6.class=target/classes/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl$6.class, - org/apache/axis2/transport/http/AbstractHTTPSender.class=target/classes/org/apache/axis2/transport/http/AbstractHTTPSender.class + org/apache/axis2/transport/http/AbstractHTTPSender.class=target/classes/org/apache/axis2/transport/http/AbstractHTTPSender.class, + org/apache/axis2/jaxws/context/WebServiceContextImpl.class=target/classes/org/apache/axis2/jaxws/context/WebServiceContextImpl.class, + org/apache/axis2/jaxws/BindingProvider.class=target/classes/org/apache/axis2/jaxws/BindingProvider.class, + org/apache/axis2/jaxws/BindingProvider$ValidatingClientContext.class=target/classes/org/apache/axis2/jaxws/BindingProvider$ValidatingClientContext.class true Added: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/BindingProvider.java URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/BindingProvider.java?rev=1101307&view=auto ============================================================================== --- geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/BindingProvider.java (added) +++ geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/BindingProvider.java Tue May 10 04:33:46 2011 @@ -0,0 +1,480 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.axis2.jaxws; + +import org.apache.axiom.om.OMElement; +import org.apache.axis2.addressing.AddressingConstants; +import org.apache.axis2.addressing.AddressingHelper; +import org.apache.axis2.description.AxisEndpoint; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.jaxws.addressing.util.EndpointReferenceUtils; +import org.apache.axis2.jaxws.binding.BindingUtils; +import org.apache.axis2.jaxws.binding.SOAPBinding; +import org.apache.axis2.jaxws.client.PropertyValidator; +import org.apache.axis2.jaxws.core.InvocationContext; +import org.apache.axis2.jaxws.core.MessageContext; +import org.apache.axis2.jaxws.description.EndpointDescription; +import org.apache.axis2.jaxws.description.ServiceDescription; +import org.apache.axis2.jaxws.handler.HandlerResolverImpl; +import org.apache.axis2.jaxws.i18n.Messages; +import org.apache.axis2.jaxws.spi.ServiceDelegate; +import org.apache.axis2.transport.http.HTTPConstants; +import org.apache.axis2.util.LoggingControl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.xml.namespace.QName; +import javax.xml.ws.Binding; +import javax.xml.ws.EndpointReference; +import javax.xml.ws.WebServiceException; +import javax.xml.ws.WebServiceFeature; +import javax.xml.ws.handler.HandlerResolver; +import javax.xml.ws.soap.AddressingFeature.Responses; +import javax.xml.ws.wsaddressing.W3CEndpointReference; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; + +public class BindingProvider implements org.apache.axis2.jaxws.spi.BindingProvider { + private static final Log log = LogFactory.getLog(BindingProvider.class); + + protected Map requestContext; + + protected Map responseContext; + + protected EndpointDescription endpointDesc; + + // NOTE this reference to the ServiceDelegate MUST be a strong reference to keep the delegate + // from being GC'd when the Service instance in the client goes out of scope but ports under + // that service are still in use. + protected ServiceDelegate serviceDelegate; + + private org.apache.axis2.jaxws.spi.Binding binding; + + public static final String BINDING_PROVIDER = "org.apache.axis2.jaxws.BindingProvider"; + + public BindingProvider(ServiceDelegate svcDelegate, + EndpointDescription epDesc, + org.apache.axis2.addressing.EndpointReference epr, + String addressingNamespace, + WebServiceFeature... features) { + this.endpointDesc = epDesc; + this.serviceDelegate = svcDelegate; + + initialize(epr, addressingNamespace, features); + } + + /* + * Initialize any objects needed by the BindingProvider + */ + private void initialize(org.apache.axis2.addressing.EndpointReference epr, + String addressingNamespace, + WebServiceFeature... features) { + requestContext = new ValidatingClientContext(); + responseContext = new ValidatingClientContext(); + + // Setting standard property defaults for the request context + requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, Boolean.FALSE); + requestContext.put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE); + + // Addressing is disabled by default unless it is turned on in the WSDL + String addressingFlagFromWSDL = AddressingHelper.getAddressingRequirementParemeterValue(endpointDesc.getAxisService()); + if(AddressingConstants.ADDRESSING_UNSPECIFIED.equals(addressingFlagFromWSDL)){ + requestContext.put(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES, Boolean.TRUE); + } + + // Set the endpoint address + String endpointAddress = (epr != null ) ? epr.getAddress() : endpointDesc.getEndpointAddress(); + if (endpointAddress != null && !"".equals(endpointAddress)) { + requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress); + } + + // JAXWS 9.2.1.1 requires that we go ahead and create the binding object + // so we can also set the handlerchain + binding = (org.apache.axis2.jaxws.spi.Binding) BindingUtils.createBinding(endpointDesc); + if(log.isDebugEnabled()){ + log.debug("Lookign for Handler Resolver"); + } + // TODO should we allow the ServiceDelegate to figure out the default handlerresolver? Probably yes, since a client app may look for one there. + HandlerResolver handlerResolver = null; + if(serviceDelegate.getHandlerResolver() != null){ + if(log.isDebugEnabled()){ + log.debug("Reading default Handler Resolver "); + } + handlerResolver = serviceDelegate.getHandlerResolver(); + } + else{ + handlerResolver = new HandlerResolverImpl(endpointDesc.getServiceDescription(), serviceDelegate); + if(log.isDebugEnabled()){ + log.debug("Creating new Handler Resolver using HandlerResolverImpl"); + } + } + + // See if the metadata from creating the service indicates that MTOM, Addressing and/or RespectBinding should be enabled + if (binding instanceof SOAPBinding) { + configureBindingFromMetadata(); + } + + // check for properties that need to be set on the BindingProvider + String seiName = null; + if(endpointDesc.getEndpointInterfaceDescription() != null + && + endpointDesc.getEndpointInterfaceDescription().getSEIClass() != null) { + seiName = endpointDesc.getEndpointInterfaceDescription().getSEIClass().getName(); + } + String portQNameString = endpointDesc.getPortQName().toString(); + String key = seiName + ":" + portQNameString; + Map bProps = endpointDesc.getServiceDescription().getBindingProperties(serviceDelegate, key); + if(bProps != null) { + if(log.isDebugEnabled()) { + log.debug("Setting binding props with size: " + bProps.size() + " on " + + "BindingProvider RequestContext"); + } + requestContext.putAll(bProps); + } + + binding.setHandlerChain(handlerResolver.getHandlerChain(endpointDesc.getPortInfo())); + + //Set JAX-WS 2.1 related properties. + try { + binding.setAxis2EndpointReference(epr); + binding.setAddressingNamespace(addressingNamespace); + binding.setFeatures(features); + } + catch (Exception e) { + throw ExceptionFactory.makeWebServiceException(e); + } + } + + /** + * Configure the binding from the Metadata for WebService Features. + */ + private void configureBindingFromMetadata() { + // MTOM can be enabled either at the ServiceDescription level (via the WSDL binding type) or + // at the EndpointDescription level via the binding type used to create a Dispatch. + boolean enableMTOMFromMetadata = false; + int mtomThreshold = 0; + boolean isAddressingConfiguredViaMetadata = false; + boolean enableRespectBindingdFromMetadata = false; + boolean enableAddressingFromMetadata = false; + boolean requireAddressingFromMetadata = false; + Responses addressingResponses = null; + + // if we have an SEI for the port, then we'll use it in order to search for WebService Feature configuration + if(endpointDesc.getEndpointInterfaceDescription() != null + && + endpointDesc.getEndpointInterfaceDescription().getSEIClass() != null) { + enableMTOMFromMetadata = endpointDesc.getServiceDescription().isMTOMEnabled(serviceDelegate, + endpointDesc.getEndpointInterfaceDescription().getSEIClass()); + mtomThreshold = getMTOMThreshold(endpointDesc.getServiceDescription(), serviceDelegate, + endpointDesc.getEndpointInterfaceDescription().getSEIClass()); + + enableRespectBindingdFromMetadata = isRespectBindingEnabled(endpointDesc.getServiceDescription(), serviceDelegate, + endpointDesc.getEndpointInterfaceDescription().getSEIClass()); + + isAddressingConfiguredViaMetadata = isAddressingConfigured(endpointDesc.getServiceDescription(), serviceDelegate, + endpointDesc.getEndpointInterfaceDescription().getSEIClass()); + if (isAddressingConfiguredViaMetadata) { + enableAddressingFromMetadata = isAddressingEnabled(endpointDesc.getServiceDescription(), serviceDelegate, + endpointDesc.getEndpointInterfaceDescription().getSEIClass()); + requireAddressingFromMetadata = isAddressingRequired(endpointDesc.getServiceDescription(), serviceDelegate, + endpointDesc.getEndpointInterfaceDescription().getSEIClass()); + addressingResponses = getAddressingResponses(endpointDesc.getServiceDescription(), serviceDelegate, + endpointDesc.getEndpointInterfaceDescription().getSEIClass()); + } + + + } + else { + enableMTOMFromMetadata = endpointDesc.getServiceDescription().isMTOMEnabled(serviceDelegate); + // MTOM.Threshold, RespectBinding, and Addressing does not need to be set here based on the sparse composite + // (i.e. depolyment descriptor) since it can only be applied to a port injection (i.e. an SEI) using a DD. + } + if (!enableMTOMFromMetadata) { + String bindingType = endpointDesc.getClientBindingID(); + enableMTOMFromMetadata = (bindingType.equals(SOAPBinding.SOAP11HTTP_MTOM_BINDING) || + bindingType.equals(SOAPBinding.SOAP12HTTP_MTOM_BINDING)); + } + + if (enableMTOMFromMetadata) { + ((SOAPBinding) binding).setMTOMEnabled(true); + ((SOAPBinding) binding).setMTOMThreshold(mtomThreshold); + } + + if (enableRespectBindingdFromMetadata) { + ((SOAPBinding) binding).setRespectBindingEnabled(true); + } + + if (isAddressingConfiguredViaMetadata) { + ((SOAPBinding) binding).setAddressingConfigured(true); + ((SOAPBinding) binding).setAddressingEnabled(enableAddressingFromMetadata); + ((SOAPBinding) binding).setAddressingRequired(requireAddressingFromMetadata); + ((SOAPBinding) binding).setAddressingResponses(addressingResponses); + } + } + + private boolean isRespectBindingEnabled(ServiceDescription serviceDescription, ServiceDelegate serviceDelegateKey, + Class seiClass) { + boolean isEnabled = serviceDescription.isRespectBindingEnabled(serviceDelegateKey, seiClass); + return isEnabled; + } + + + /** + * Answer if addressing was explicitly configured via metadata. Note that if Addressing was not explicitly configured, + * then the related methods will return default values. If Addressing was explicitly configured, the related + * methods will return values based on whatever configuration was specified. + * @see #isAddressingEnabled(ServiceDescription, ServiceDelegate, Class) + * @see #isAddressingRequired(ServiceDescription, ServiceDelegate, Class) + * @see #getAddressingResponses(ServiceDescription, ServiceDelegate, Class) + * @param serviceDescription + * @param serviceDelegateKey + * @param seiClass + * @return true if addressing was explicitly configured via metadata, false otherwise. + */ + private boolean isAddressingConfigured(ServiceDescription serviceDescription, ServiceDelegate serviceDelegateKey, + Class seiClass) { + boolean isConfigured = serviceDescription.isAddressingConfigured(serviceDelegateKey, seiClass); + return isConfigured; + } + + private boolean isAddressingEnabled(ServiceDescription serviceDescription, ServiceDelegate serviceDelegateKey, + Class seiClass) { + boolean isEnabled = serviceDescription.isAddressingEnabled(serviceDelegateKey, seiClass); + return isEnabled; + } + + private boolean isAddressingRequired(ServiceDescription serviceDescription, ServiceDelegate serviceDelegateKey, + Class seiClass) { + boolean isRequired = serviceDescription.isAddressingRequired(serviceDelegateKey, seiClass); + return isRequired; + } + private Responses getAddressingResponses(ServiceDescription serviceDescription, ServiceDelegate serviceDelegateKey, + Class seiClass) { + Responses responses = serviceDescription.getAddressingResponses(serviceDelegateKey, seiClass); + return responses; + } + + private int getMTOMThreshold(ServiceDescription serviceDescription, ServiceDelegate serviceDelegate, Class seiClass) { + int threshold = serviceDescription.getMTOMThreshold(serviceDelegate, seiClass); + + return threshold; + } + + public ServiceDelegate getServiceDelegate() { + return serviceDelegate; + } + + public EndpointDescription getEndpointDescription() { + return endpointDesc; + } + + public Binding getBinding() { + return binding; + } + + public Map getRequestContext() { + return requestContext; + } + + public Map getResponseContext() { + return responseContext; + } + + /** + * Check for maintain session state enablement either in the + * MessageContext.isMaintainSession() or in the ServiceContext properties. + * + * @param mc + * @param ic + */ + protected void checkMaintainSessionState(MessageContext mc, InvocationContext ic) { + Map properties = ic.getServiceClient().getServiceContext().getProperties(); + boolean bValue = false; + + if (properties != null + && properties + .containsKey(javax.xml.ws.BindingProvider.SESSION_MAINTAIN_PROPERTY)) { + bValue = (Boolean) properties + .get(javax.xml.ws.BindingProvider.SESSION_MAINTAIN_PROPERTY); + } + if (mc.isMaintainSession() || bValue == true) { + setupSessionContext(properties); + } + } + + /* + * Ensure that the next request context contains the session value returned + * from previous request + */ + protected void setupSessionContext(Map properties) { + String sessionKey = null; + Object sessionValue = null; + + if (properties == null) { + throw ExceptionFactory.makeWebServiceException(Messages.getMessage("NoMaintainSessionProperty")); + } else if (properties.containsKey(HTTPConstants.HEADER_LOCATION)) { + sessionKey = HTTPConstants.HEADER_LOCATION; + sessionValue = properties.get(sessionKey); + if (sessionValue != null && !"".equals(sessionValue)) { + requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, sessionValue); + } + } else if (properties.containsKey(HTTPConstants.HEADER_COOKIE)) { + sessionKey = HTTPConstants.HEADER_COOKIE; + sessionValue = properties.get(sessionKey); + if (sessionValue != null && !"".equals(sessionValue)) { + requestContext.put(HTTPConstants.COOKIE_STRING, sessionValue); + } + } else if (properties.containsKey(HTTPConstants.HEADER_COOKIE2)) { + sessionKey = HTTPConstants.HEADER_COOKIE2; + sessionValue = properties.get(sessionKey); + if (sessionValue != null && !"".equals(sessionValue)) { + requestContext.put(HTTPConstants.COOKIE_STRING, sessionValue); + } + } else { + throw ExceptionFactory + .makeWebServiceException(Messages.getMessage("NoMaintainSessionProperty")); + } + + if (sessionValue == null) { + throw ExceptionFactory.makeWebServiceException( + Messages.getMessage("NullValueForMaintainSessionProperty", sessionKey)); + } + } + + /** + * Returns a boolean value representing whether or not a SOAPAction header should be sent with + * the request. + */ + protected boolean useSoapAction() { + //TODO: Add some bit of validation for this property so that we know + // it is actually a Boolean and not a String. + Boolean use = (Boolean)requestContext.get(BindingProvider.SOAPACTION_USE_PROPERTY); + if (use != null) { + if (use.booleanValue()) { + return true; + } else { + return false; + } + } else { + // If the value is not set, then just default to sending a SOAPAction + return true; + } + } + + /* + * (non-Javadoc) + * @see javax.xml.ws.BindingProvider#getEndpointReference() + */ + public EndpointReference getEndpointReference() { + return getEndpointReference(W3CEndpointReference.class); + } + + /* + * (non-Javadoc) + * @see javax.xml.ws.BindingProvider#getEndpointReference(java.lang.Class) + */ + public T getEndpointReference(Class clazz) { + EndpointReference jaxwsEPR = null; + String addressingNamespace = EndpointReferenceUtils.getAddressingNamespace(clazz); + + try { + org.apache.axis2.addressing.EndpointReference epr = binding.getAxis2EndpointReference(); + + if (epr == null) { + String address = + (String) requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY); + if (address == null) + address = endpointDesc.getEndpointAddress(); + QName service = endpointDesc.getServiceQName(); + QName port = endpointDesc.getPortQName(); + String wsdlLocation = "?wsdl"; // let the webcontainer redirect us to the real WSDL URL; it knows where it is + + epr = EndpointReferenceUtils.createAxis2EndpointReference(address, service, port, wsdlLocation, addressingNamespace); + + // Add reference parameters from WSDL to the EPR + AxisService axisService = endpointDesc.getAxisService(); + if (axisService != null) { + AxisEndpoint axisEndpoint = axisService.getEndpoint(axisService.getEndpointName()); + + if(axisEndpoint != null){ + ArrayList referenceParameters = (ArrayList) axisEndpoint.getParameterValue(AddressingConstants.REFERENCE_PARAMETER_PARAMETER); + if (LoggingControl.debugLoggingAllowed && log.isTraceEnabled()) { + log.trace("getEndpointReference: Adding reference parameters to EPR from WSDL: axisService = " + axisService + ", axisEndpoint = " + axisEndpoint.getName() + ", referenceParameters = " + referenceParameters); + } + if(referenceParameters!=null){ + Iterator iterator = referenceParameters.iterator(); + HashMap refParamMap = new HashMap(); + while (iterator.hasNext()) { + OMElement omElement = (OMElement)iterator.next(); + refParamMap.put(omElement.getQName(), omElement); + } + epr.setReferenceParameters(refParamMap); + } + } + } + } + else if (!addressingNamespace.equals(binding.getAddressingNamespace())) { + throw ExceptionFactory. + makeWebServiceException(Messages.getMessage("bindingProviderErr1", + binding.getAddressingNamespace(), + addressingNamespace)); + } + + jaxwsEPR = EndpointReferenceUtils.convertFromAxis2(epr, addressingNamespace); + } catch (UnsupportedOperationException e) { + throw e; + } catch (WebServiceException e) { + throw e; + } catch (Exception e) { + throw ExceptionFactory. + makeWebServiceException(Messages.getMessage("endpointRefConstructionFailure3", + e.toString())); + } + + return clazz.cast(jaxwsEPR); + } + + /* + * An inner class used to validate properties as they are set by the client. + */ + class ValidatingClientContext extends Hashtable { + private static final long serialVersionUID = 3485112205801917858L; + + @Override + public synchronized Object put(String key, Object value) { + // super.put rightly throws a NullPointerException if key or value is null, so don't continue if that's the case + if (value == null) + return null; + if (PropertyValidator.validate(key, value)) { + return super.put(key, value); + } else { + throw ExceptionFactory.makeWebServiceException( + Messages.getMessage("invalidPropValue", key, value.getClass().getName(), + PropertyValidator.getExpectedValue(key).getName())); + } + } + } + + +} Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/BindingProvider.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/BindingProvider.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/BindingProvider.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/context/WebServiceContextImpl.java URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/context/WebServiceContextImpl.java?rev=1101307&view=auto ============================================================================== --- geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/context/WebServiceContextImpl.java (added) +++ geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/context/WebServiceContextImpl.java Tue May 10 04:33:46 2011 @@ -0,0 +1,181 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.axis2.jaxws.context; + +import org.apache.axis2.jaxws.ExceptionFactory; +import org.apache.axis2.jaxws.addressing.util.EndpointReferenceUtils; +import org.apache.axis2.jaxws.i18n.Messages; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.w3c.dom.Element; + +import javax.servlet.http.HttpServletRequest; +import javax.xml.namespace.QName; +import javax.xml.ws.EndpointReference; +import javax.xml.ws.WebServiceContext; +import javax.xml.ws.handler.MessageContext; +import javax.xml.ws.wsaddressing.W3CEndpointReference; + +import java.net.URI; +import java.security.Principal; + +public class WebServiceContextImpl implements WebServiceContext { + + private static final Log log = LogFactory.getLog(WebServiceContext.class); + + private MessageContext soapMessageContext; + + public WebServiceContextImpl() { + super(); + } + + /* (non-Javadoc) + * @see javax.xml.ws.WebServiceContext#getMessageContext() + */ + public MessageContext getMessageContext() { + + // Note that the MessageContext might not be set up yet, or it + // may have been released because the lifetime of the WebServiceContext is completed. + if (log.isDebugEnabled()) { + if (soapMessageContext == null) { + log.debug("The MessageContext is not available"); + } + } + return soapMessageContext; + } + + /* (non-Javadoc) + * @see javax.xml.ws.WebServiceContext#getUserPrincipal() + */ + public Principal getUserPrincipal() { + + // Note that the MessageContext might not be set up yet, or it + // may have been released because the lifetime of the WebServiceContext is completed. + if (log.isDebugEnabled()) { + if (soapMessageContext == null) { + log.debug("The MessageContext is not available"); + } + } + + if (soapMessageContext != null) { + HttpServletRequest request = (HttpServletRequest) soapMessageContext.get(MessageContext.SERVLET_REQUEST); + if (request != null) { + if (log.isDebugEnabled()) { + log.debug("Access to the user Principal was requested."); + } + return request.getUserPrincipal(); + } + else { + if (log.isDebugEnabled()) { + log.debug("No HttpServletRequest object was found, so no Principal can be found."); + } + } + } + + return null; + } + + /* (non-Javadoc) + * @see javax.xml.ws.WebServiceContext#isUserInRole(java.lang.String) + */ + public boolean isUserInRole(String user) { + + // Note that the MessageContext might not be set up yet, or it + // may have been released because the lifetime of the WebServiceContext is completed. + if (log.isDebugEnabled()) { + if (soapMessageContext == null) { + log.debug("The MessageContext is not available"); + } + } + + if (soapMessageContext != null) { + HttpServletRequest request = (HttpServletRequest) soapMessageContext.get(MessageContext.SERVLET_REQUEST); + if (request != null) { + if (log.isDebugEnabled()) { + log.debug("Checking to see if the user in the role."); + } + return request.isUserInRole(user); + } + else { + if (log.isDebugEnabled()) { + log.debug("No HttpServletRequest object was found, so no role check can be performed."); + } + } + } + + return false; + } + + public void setSoapMessageContext(MessageContext soapMessageContext) { + this.soapMessageContext = soapMessageContext; + } + + public T getEndpointReference(Class clazz, Element... referenceParameters) { + + // Note that the MessageContext might not be set up yet, or it + // may have been released because the lifetime of the WebServiceContext is completed. + if (log.isDebugEnabled()) { + if (soapMessageContext == null) { + log.debug("The MessageContext is not available"); + } + } + + EndpointReference jaxwsEPR = null; + String addressingNamespace = EndpointReferenceUtils.getAddressingNamespace(clazz); + + if (soapMessageContext != null) { + QName service = (QName) soapMessageContext.get(MessageContext.WSDL_SERVICE); + QName endpoint = (QName) soapMessageContext.get(MessageContext.WSDL_PORT); + String wsdlLocation = "?wsdl"; // let the webcontainer redirect us to the real WSDL URL; it knows where it is + + org.apache.axis2.addressing.EndpointReference axis2EPR = + EndpointReferenceUtils.createAxis2EndpointReference(null, service, endpoint, wsdlLocation, addressingNamespace); + + try { + EndpointReferenceUtils.addReferenceParameters(axis2EPR, referenceParameters); + jaxwsEPR = EndpointReferenceUtils.convertFromAxis2(axis2EPR, addressingNamespace); + } + catch (Exception e) { + throw ExceptionFactory.makeWebServiceException( + Messages.getMessage("endpointRefConstructionFailure3", e.toString())); + } + } + else { + throw new IllegalStateException( + Messages.getMessage("webServiceContextErr1")); + } + + return clazz.cast(jaxwsEPR); + } + + public EndpointReference getEndpointReference(Element... referenceParameters) { + return getEndpointReference(W3CEndpointReference.class, referenceParameters); + } + + /** + * Release objects held by WebServiceContext so that they can be garbage collected. + */ + public void releaseResources() { + if (log.isDebugEnabled()) { + log.debug("Releasing WebServiceContextImpl resources"); + } + soapMessageContext = null; // unlink the soapMessageContxt so that it can be gc'd + } +} Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/context/WebServiceContextImpl.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/context/WebServiceContextImpl.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/context/WebServiceContextImpl.java ------------------------------------------------------------------------------ svn:mime-type = text/plain