You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Rebecca Searls (JIRA)" <ji...@apache.org> on 2013/10/25 15:48:31 UTC

[jira] [Commented] (CXF-5341) NPE in org.apache.cxf.jaxws.support.JaxWsEndpointImpl.checkRespectBindingFeature

    [ https://issues.apache.org/jira/browse/CXF-5341?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13805300#comment-13805300 ] 

Rebecca Searls commented on CXF-5341:
-------------------------------------

There are 2 issues with the code supporting RespectBinding in 2.6.x-fixes, 
2.7.x-fixes, and the current trunk. 
.

issue 1. In org.apache.cxf.jaxws.support.JaxWsEndpointImpl variable, this.wsFeatures,
         can be NULL.  Currently a value of NULL is not checked before executing the 
         "for" stmt at line 266 and a NPE will results.

260     private void checkRespectBindingFeature(List<ExtensibilityElement> bindingExtensors) {
261         if (bindingExtensors != null) {
262             Iterator<ExtensibilityElement> extensionElements = bindingExtensors.iterator();
263             while (extensionElements.hasNext()) {
264                 ExtensibilityElement ext = extensionElements.next();
265                 if (ext instanceof UnknownExtensibilityElement && Boolean.TRUE.equals(ext.getRequired())) {
266  **NPE**             for (WebServiceFeature feature : this.wsFeatures) {
267                         if (feature instanceof RespectBindingFeature && feature.isEnabled()) {
268
269                             org.apache.cxf.common.i18n.Message message =
270                                 new org.apache.cxf.common.i18n.Message("UNKONWN_REQUIRED_WSDL_BINDING", LOG);
271                             LOG.severe(message.toString());
272                             throw new WebServiceException(message.toString());
273                         }
274                     }
275                 }
276             }
277         }
278
279     }

Solution:  The solution to the NPE is to add a check for a NULL value at line 265 as follows.

    if (ext instanceof UnknownExtensibilityElement && Boolean.TRUE.equals(ext.getRequired())
                    && this.wsFeatures != null) {
       ......

    A NULL value for this.wsFeatures occurs when the service endpoint implementation class 
    does not contain a @MTOM, @ADDRESS, or @RespectBinding annotation.

    This particular NPE occurs when the scenario above occurs AND there is an {any} type
    stmt (see schema def) in the wsdl's "binding" "operation" that contains a 
    "wsdl:enable='true'" attribute.  (see line 124 below)

    [ from the wsdl schema, 
            <wsdl:operation	name = xs:NCName >
                Content: wsdl:documentation?, {any}*, wsdl:input?, wsdl:output?, wsdl:fault*
            </wsdl:operation>
    ]

120    <wsdl:binding name="HelloWorldServiceSoapBinding" type="tns:HelloWorldService">
121        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
122        <wsdl:operation name="sayHelloToName">            
123            <!-- Gives nullpointer exception EAP 6.1.1 -->
124  >>>>     <wsp:PolicyReference URI="#ForceMTOM" wsdl:required="true" />
125            <soap:operation soapAction="" style="document" />
126            <wsdl:input name="sayHelloToName">
127                <soap:body use="literal" />
128            </wsdl:input>
129            <wsdl:output name="sayHelloToNameResponse">
130                <soap:body use="literal" />
131            </wsdl:output>
132        </wsdl:operation>
133    </wsdl:binding>



issue 2. Currently 2.6.x-fixes, 2.7.x-fixes and the trunk is not checking for annotation @RespectBinding.
        Class org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.loadWSFeatureAnnotation
        checks for annotations @MTOM, @ADDRESS and sets up for wsFeatures to contain values.
        This seems the logical place to add the follow code to check for @RespectBinding.

        RespectBinding respectBinding = implInfo.getImplementorClass()
            .getAnnotation(RespectBinding.class);
        if (respectBinding == null && serviceClass != null) {
            respectBinding = serviceClass.getAnnotation(RespectBinding.class);
        }
        if (respectBinding != null) {
            features.add(new RespectBindingFeature(respectBinding.enabled()));
        }


-------

There are 5 input scenarios for the case of RespectBinding and an 
UnknownExtensibilityElement.

1.) There is no @RespectBinding annotation defined in the service endpoint 
     implementation class and there is an UnknownExtensibilityElement with a enabled="true"
     attribute set in the operation element of a binding.

     result: RespectBinding is not active because there is no def for it.
            The UnknownExtensibilityElement request for RespectBinding is ignored.
            
2.) There is a @RespectBinding annotation (using the default value of true or explicitly
     set to true) defined in the service endpoint implementation class and there is an 
     UnknownExtensibilityElement with a enabled="true" attribute set in the operation 
     element of a binding.

     result: A fatal exception is thrown at deployment time.  Error msg starts.
        "Unknown wsdl binding extension with required=true attribute found while 
            RespectBindingFeature enabled", .....

3.) There is a @RespectBinding annotation (set to false) defined in the service endpoint 
     implementation class and there is an UnknownExtensibilityElement with a enabled="true"
     attribute set in the operation element of a binding.

     result: RespectBinding is not active because it is set to false.
            The UnknownExtensibilityElement request for RespectBinding is ignored.
            
4.) There is a @RespectBinding annotation (set to false) defined in the service endpoint 
     implementation class and there is an UnknownExtensibilityElement with a enabled="false"
     or the attribute is not defined in the operation element of a binding.

     result: RespectBinding is not active because it is set to false.  The 
            UnknownExtensibilityElement's RespectBinding request is ignored  
            because the value is false or not present.   

5.) There is a @RespectBinding annotation (set to true) defined in the service endpoint 
     implementation class and there is an UnknownExtensibilityElement with a enabled="false"
     or the attribute is not defined in the operation element of a binding.

     result: The UnknownExtensibilityElement's RespectBinding request is ignored
             because the value is false or not present. RespectBinding is active 
             because it is set to true.


> NPE in org.apache.cxf.jaxws.support.JaxWsEndpointImpl.checkRespectBindingFeature
> --------------------------------------------------------------------------------
>
>                 Key: CXF-5341
>                 URL: https://issues.apache.org/jira/browse/CXF-5341
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-WS Runtime
>    Affects Versions: 2.6.8
>            Reporter: Alessio Soldano
>
> I'm getting a NPE when using a contract-first WS endpoint whose wsdl contains:
> <wsp:PolicyReference URI="#ForceMTOM" wsdl:required="true" />
> Caused by: java.lang.NullPointerException
> 	at org.apache.cxf.jaxws.support.JaxWsEndpointImpl.checkRespectBindingFeature(JaxWsEndpointImpl.java:267)
> 	at org.apache.cxf.jaxws.support.JaxWsEndpointImpl.extractWsdlExtensibilities(JaxWsEndpointImpl.java:227)
> 	at org.apache.cxf.jaxws.support.JaxWsEndpointImpl.<init>(JaxWsEndpointImpl.java:205)
> 	at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.createEndpoint(JaxWsServiceFactoryBean.java:237)
> 	at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.createEndpoints(ReflectionServiceFactoryBean.java:351)
> 	at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:283)
> 	at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:204)
> 	at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:102)
> 	at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:159)
> 	at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:211)
> 	at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:456)
> 	at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:334)
> 	... 13 more
> This looks related to the changes in CXF-4876.



--
This message was sent by Atlassian JIRA
(v6.1#6144)