You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by "Onur Ulusu (Garanti Teknoloji)" <On...@garanti.com.tr> on 2012/08/24 13:32:11 UTC

NullPointerException in isSecurityFault method

Hi,

We have same problem mentioned below, getTextAsQName() method returns null in our example, so we are getting nullPointerException from isSecurityFault() method. faultCode variable returned from service is "<faultcode>{HATA KODU:}K060</faultcode>" in our case. We are using Rampart version 1.6.2 in our project.

Is there any fixed versions for this case, if not, do you have any suggestion as a workaround?

Thanks,

Onur


if (soapVersionURI.equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
                  // This is a fault processing the security header
                  if (faultCode.getTextAsQName().getNamespaceURI().equals(WSConstants.WSSE_NS)) {
                        return true;
                  }


java.lang.NullPointerException
      at org.apache.rampart.RampartEngine.isSecurityFault(RampartEngine.java:311)
      at org.apache.rampart.RampartEngine.process(RampartEngine.java:77)
      at org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:92)





   [
https://issues.apache.org/jira/browse/RAMPART-358?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]



Sagara Gunathunga  updated RAMPART-358:

---------------------------------------



    Fix Version/s:     (was: 1.6.2)

                   1.7.0



Moved to next release.



Possible NullPointerException in
RampartEngine.isSecurityFault(RampartMessageData)

----------------------------------------------------------------------------------



                Key: RAMPART-358

                URL: https://issues.apache.org/jira/browse/RAMPART-358

            Project: Rampart

         Issue Type: Bug

         Components: rampart-core

           Reporter: Filippo Ortolan

            Fix For: 1.7.0



  Original Estimate: 10m

Remaining Estimate: 10m



in RampartEngine class I get a NullPointerException in line 369 (method:
isSecurityFault). Seems that this line:

if (faultCode.getTextAsQName().getNamespaceURI().equals(WSConstants.WSSE_NS)) {

                                               return true;

                                   }

throws the exception because getTextAsQName() can return null and this should be
handled.

Solution:

QName faultCodeQName = faultCode.getTextAsQName();

if (faultCodeQName == null) {

// handle exception

   return false; // ?

} else {

   if (faultCodeQName.getNamespaceURI().equals(WSConstants.WSSE_NS)) {

      return true;

   }

}



--

This message is automatically generated by JIRA.

If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa

For more information on JIRA, see: http://www.atlassian.com/software/jira



---------------------------------------------------------------------

To unsubscribe, e-mail: java...@axis.apache.org

For additional commands, e-mail: java...@axis.apache.org


Re: NullPointerException in isSecurityFault method

Posted by Andreas Veithen <an...@gmail.com>.
There are two problems here:

1. faultcode is expected to be an xsd:QName. In your case it is not.
Therefore the service is not SOAP compliant.
2. OMElement#getTextAsQName() may return null. That behavior is
documented, and as noted in RAMPART-358, Rampart should take that into
account.

Andreas

On Fri, Aug 24, 2012 at 4:01 PM, Onur Ulusu (Garanti Teknoloji)
<On...@garanti.com.tr> wrote:
> Actually, ElementImpl class (public class ElementImpl extends ParentNode
> implements Element, OMElementEx, OMNodeEx, NamedNode, OMConstants) of
> axiom-dom-1.2.13 seems to implement getTextAsQName as below, when I step
> into getTextAsQName method, debugger steps to lines.
>
>
>
> I think the problem is “:” character in the faultcode returned from service
> (“<faultcode>{HATA KODU:}K060</faultcode>”). When I remove “:” char from
> service response in debugger, no exception occurs.
>
>
>
>
>
> public QName getTextAsQName() {
>
>         String childText = getText().trim();
>
>         return childText.length() == 0 ? null : resolveQName(childText);
>
>     }
>
>
>
> public QName resolveQName(String qname) {
>
>         int idx = qname.indexOf(':');
>
>         if (idx == -1) {
>
>             OMNamespace ns = getDefaultNamespace();
>
>             return ns == null ? new QName(qname) : new
> QName(ns.getNamespaceURI(), qname, "");
>
>         } else {
>
>             String prefix = qname.substring(0, idx);
>
>             OMNamespace ns = findNamespace(null, prefix);
>
>             return ns == null ? null : new QName(ns.getNamespaceURI(),
> qname.substring(idx+1), prefix);
>
>         }
>
>     }
>
> From: Martin Gainty [mailto:mgainty@hotmail.com]
> Sent: Friday, August 24, 2012 4:08 PM
> To: java-dev@axis.apache.org; Onur Ulusu (Garanti Teknoloji)
> Subject: RE: NullPointerException in isSecurityFault method
>
>
>
> apparently getTextAsQName was never implemented in SOAPFaultCode.java
>
> package org.apache.axis.soap;
> import org.apache.axis.om.OMElement;
> /**
>  * Copyright 2001-2004 The Apache Software Foundation.
>  * <p/>
>  * Licensed 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
>  * <p/>
>  * http://www.apache.org/licenses/LICENSE-2.0
>  * <p/>
>  * 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.
>  * <p/>
>  */
> public interface SOAPFaultCode extends OMElement{
>     /**
>      * Eran Chinthaka (chinthaka@apache.org)
>      */
>
>     /**
>      * @param value
>      */
>     public void addValue(SOAPFaultCodeValue value);
>
>     /**
>      * @return
>      */
>     public SOAPFaultCodeValue getValue();
>
>     /**
>      * @param value
>      */
>     public void addSubCode(SOAPFaultSubCode value);
>
>     /**
>      * @return
>      */
>     public SOAPFaultSubCode getSubCode();
>
> }
>
> //Implementor forgot to override getTextAsQName
> /*
>  * Copyright 2004,2005 The Apache Software Foundation.
>  *
>  * Licensed 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.soap.impl.dom;
>
> import org.apache.ws.commons.om.OMXMLParserWrapper;
> import org.apache.ws.commons.om.impl.OMOutputImpl;
> import org.apache.ws.commons.om.impl.llom.OMSerializerUtil;
> import
> org.apache.ws.commons.om.impl.serialize.StreamWriterToContentHandlerConverter;
> import org.apache.ws.commons.om.util.ElementHelper;
> import org.apache.ws.commons.soap.SOAP12Constants;
> import org.apache.ws.commons.soap.SOAPFactory;
> import org.apache.ws.commons.soap.SOAPFault;
> import org.apache.ws.commons.soap.SOAPFaultCode;
> import org.apache.ws.commons.soap.SOAPFaultSubCode;
> import org.apache.ws.commons.soap.SOAPFaultValue;
> import org.apache.ws.commons.soap.SOAPProcessingException;
>
> import javax.xml.stream.XMLStreamException;
>
> public abstract class SOAPFaultCodeImpl  extends SOAPElement implements
> SOAPFaultCode{
>
>     /**
>      * Constructor OMElementImpl
>      *
>      * @param parent
>      * @param builder
>      */
>     public SOAPFaultCodeImpl(SOAPFault parent, OMXMLParserWrapper builder,
>             SOAPFactory factory) {
>         super(parent, SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME, builder,
>                 factory);
>     }
>
>     /**
>      * @param parent
>      */
>     public SOAPFaultCodeImpl(SOAPFault parent,
>                              boolean extractNamespaceFromParent,
>                              SOAPFactory factory) throws
> SOAPProcessingException {
>         super(parent, SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME,
>                 extractNamespaceFromParent, factory);
>     }
>
>     /**
>      * Eran Chinthaka (chinthaka@apache.org)
>      */
>     public void setValue(SOAPFaultValue value) throws
> SOAPProcessingException {
>         ElementHelper.setNewElement(this, value, value);
>     }
>
>     public SOAPFaultValue getValue() {
>         return (SOAPFaultValue) ElementHelper.getChildWithName(this,
>                 SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME);
>     }
>
>     public void setSubCode(SOAPFaultSubCode value) throws
> SOAPProcessingException {
>         ElementHelper.setNewElement(this, getSubCode(), value);
>     }
>
>     public SOAPFaultSubCode getSubCode() {
>         return (SOAPFaultSubCode) ElementHelper.getChildWithName(this,
>                 SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME);
>     }
>
>     protected void serialize(OMOutputImpl omOutput, boolean cache) throws
> XMLStreamException {
>         // select the builder
>         short builderType = PULL_TYPE_BUILDER;    // default is pull type
>         if (builder != null) {
>             builderType = this.builder.getBuilderType();
>         }
>         if ((builderType == PUSH_TYPE_BUILDER)
>                 && (builder.getRegisteredContentHandler() == null)) {
>             builder.registerExternalContentHandler(new
> StreamWriterToContentHandlerConverter(omOutput));
>         }
>
>
>         if (!cache) {
>             //No caching
>             if (this.firstChild != null) {
>                 OMSerializerUtil.serializeStartpart(this, omOutput);
>                 firstChild.serializeAndConsume(omOutput);
>                 OMSerializerUtil.serializeEndpart(omOutput);
>             } else if (!this.done) {
>                 if (builderType == PULL_TYPE_BUILDER) {
>                     OMSerializerUtil.serializeByPullStream(this, omOutput);
>                 } else {
>                     OMSerializerUtil.serializeStartpart(this, omOutput);
>                     builder.setCache(cache);
>                     builder.next();
>                     OMSerializerUtil.serializeEndpart(omOutput);
>                 }
>             } else {
>                 OMSerializerUtil.serializeNormal(this, omOutput, cache);
>             }
>             // do not serialise the siblings
>
>
>         } else {
>             //Cached
>             OMSerializerUtil.serializeNormal(this, omOutput, cache);
>
>             // do not serialise the siblings
>         }
>
>
>     }
>
> }
>
> //SOAP11 concrete class missed getTextAsQName as well
> /*
>  * Copyright 2004,2005 The Apache Software Foundation.
>  *
>  * Licensed 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.soap.impl.dom.soap11;
>
> import org.apache.axis2.soap.impl.dom.SOAPFaultCodeImpl;
> import org.apache.ws.commons.om.OMElement;
> import org.apache.ws.commons.om.OMXMLParserWrapper;
> import org.apache.ws.commons.om.impl.llom.OMSerializerUtil;
> import
> org.apache.ws.commons.om.impl.serialize.StreamWriterToContentHandlerConverter;
> import org.apache.ws.commons.soap.SOAP11Constants;
> import org.apache.ws.commons.soap.SOAPFactory;
> import org.apache.ws.commons.soap.SOAPFault;
> import org.apache.ws.commons.soap.SOAPFaultSubCode;
> import org.apache.ws.commons.soap.SOAPFaultValue;
> import org.apache.ws.commons.soap.SOAPProcessingException;
>
> import javax.xml.stream.XMLStreamException;
> import javax.xml.stream.XMLStreamWriter;
>
> public class SOAP11FaultCodeImpl extends SOAPFaultCodeImpl {
>     /**
>      * Constructor OMElementImpl
>      *
>      * @param parent
>      * @param builder
>      */
>     public SOAP11FaultCodeImpl(SOAPFault parent, OMXMLParserWrapper builder,
>             SOAPFactory factory) {
>         super(parent, builder, factory);
>     }
>
>     /**
>      * @param parent
>      */
>     public SOAP11FaultCodeImpl(SOAPFault parent, SOAPFactory factory)
>             throws SOAPProcessingException {
>         super(parent, false, factory);
>     }
>
>
>     public void setSubCode(SOAPFaultSubCode subCode) throws
> SOAPProcessingException {
>         if (!(subCode instanceof SOAP11FaultSubCodeImpl)) {
>             throw new SOAPProcessingException(
>                     "Expecting SOAP 1.1 implementation of SOAP Fault Sub " +
>                     "Code. But received some other implementation");
>         }
>         super.setSubCode(subCode);
>     }
>
>     public void setValue(SOAPFaultValue value) throws
> SOAPProcessingException {
>         if (!(value instanceof SOAP11FaultValueImpl)) {
>             throw new SOAPProcessingException(
>                     "Expecting SOAP 1.1 implementation of SOAP Fault Value.
> " +
>                     "But received some other implementation");
>         }
>         super.setValue(value);
>     }
>
>     protected void checkParent(OMElement parent) throws
> SOAPProcessingException {
>         if (!(parent instanceof SOAP11FaultImpl)) {
>             throw new SOAPProcessingException(
>                     "Expecting SOAP 1.1 implementation of SOAP Fault as the
> " +
>                     "parent. But received some other implementation");
>         }
>     }
>
>     protected void serialize(
>             org.apache.ws.commons.om.impl.OMOutputImpl omOutput, boolean
> cache)
>             throws XMLStreamException {
>
>         // select the builder
>         short builderType = PULL_TYPE_BUILDER;    // default is pull type
>         if (builder != null) {
>             builderType = this.builder.getBuilderType();
>         }
>         if ((builderType == PUSH_TYPE_BUILDER)
>                 && (builder.getRegisteredContentHandler() == null)) {
>             builder.registerExternalContentHandler(
>                     new StreamWriterToContentHandlerConverter(omOutput));
>         }
>
>         XMLStreamWriter writer = omOutput.getXmlStreamWriter();
>         if (this.getNamespace() != null) {
>             String prefix = this.getNamespace().getPrefix();
>             String nameSpaceName = this.getNamespace().getName();
>             writer.writeStartElement(prefix,
> SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME,
>                     nameSpaceName);
>         } else {
>             writer.writeStartElement(
>                     SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME);
>         }
>
>         OMSerializerUtil.serializeAttributes(this, omOutput);
>         OMSerializerUtil.serializeNamespaces(this, omOutput);
>
>
>         String text = this.getValue().getText();
>         writer.writeCharacters(text);
>         writer.writeEndElement();
>     }
> }
>
> //getTextAsQName method is missing from SOAP12 implementor also
> /*
>  * Copyright 2004,2005 The Apache Software Foundation.
>  *
>  * Licensed 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.soap.impl.dom.soap12;
>
> import org.apache.axis2.soap.impl.dom.SOAPFaultCodeImpl;
> import org.apache.ws.commons.om.OMElement;
> import org.apache.ws.commons.om.OMXMLParserWrapper;
> import org.apache.ws.commons.soap.SOAPFactory;
> import org.apache.ws.commons.soap.SOAPFault;
> import org.apache.ws.commons.soap.SOAPFaultSubCode;
> import org.apache.ws.commons.soap.SOAPFaultValue;
> import org.apache.ws.commons.soap.SOAPProcessingException;
>
> public class SOAP12FaultCodeImpl extends SOAPFaultCodeImpl {
>     /**
>      * Constructor OMElementImpl
>      *
>      * @param parent
>      * @param builder
>      */
>     public SOAP12FaultCodeImpl(SOAPFault parent, OMXMLParserWrapper builder,
>             SOAPFactory factory) {
>         super(parent, builder, factory);
>     }
>
>     /**
>      * @param parent
>      */
>     public SOAP12FaultCodeImpl(SOAPFault parent, SOAPFactory factory)
>             throws SOAPProcessingException {
>         super(parent, true, factory);
>     }
>
>
>     public void setSubCode(SOAPFaultSubCode subCode)
>             throws SOAPProcessingException {
>         if (!(subCode instanceof SOAP12FaultSubCodeImpl)) {
>             throw new SOAPProcessingException(
>                     "Expecting SOAP 1.2 implementation of SOAP Fault " +
>                     "Sub Code. But received some other implementation");
>         }
>         super.setSubCode(subCode);
>     }
>
>     public void setValue(SOAPFaultValue value) throws
> SOAPProcessingException {
>         if (!(value instanceof SOAP12FaultValueImpl)) {
>             throw new SOAPProcessingException(
>                     "Expecting SOAP 1.2 implementation of SOAP Fault Value.
> " +
>                     "But received some other implementation");
>         }
>         super.setValue(value);
>     }
>
>     protected void checkParent(OMElement parent) throws
> SOAPProcessingException {
>         if (!(parent instanceof SOAP12FaultImpl)) {
>             throw new SOAPProcessingException(
>                     "Expecting SOAP 1.2 implementation of SOAP Fault as " +
>                     "the parent. But received some other implementation");
>         }
>     }
> }
>
> the problem is getTextAsQName is missing in all implementors of
> SOAPFaultCode, abstract classes which implement SOAPFaultCode and concrete
> classes which extend
> abstract classes which implement SOAPFaultCode in Axis
> Good Catch!
> Martin Gainty
> ______________________________________________
> Verzicht und Vertraulichkeitanmerkung
>
>
> Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene
> Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte
> Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht
> dient lediglich dem Austausch von Informationen und entfaltet keine
> rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von
> E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
>
>
>
>
>
> ________________________________
>
> From: OnurU@garanti.com.tr
> To: java-dev@axis.apache.org
> Subject: NullPointerException in isSecurityFault method
> Date: Fri, 24 Aug 2012 11:32:11 +0000
>
> Hi,
>
>
>
> We have same problem mentioned below, getTextAsQName() method returns null
> in our example, so we are getting nullPointerException from
> isSecurityFault() method. faultCode variable returned from service is
> “<faultcode>{HATA KODU:}K060</faultcode>” in our case. We are using Rampart
> version 1.6.2 in our project.
>
>
>
> Is there any fixed versions for this case, if not, do you have any
> suggestion as a workaround?
>
>
>
> Thanks,
>
>
>
> Onur
>
>
>
>
>
> if (soapVersionURI.equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
>
>                   // This is a fault processing the security header
>
>                   if
> (faultCode.getTextAsQName().getNamespaceURI().equals(WSConstants.WSSE_NS)) {
>
>                         return true;
>
>                   }
>
>
>
>
>
> java.lang.NullPointerException
>
>       at
> org.apache.rampart.RampartEngine.isSecurityFault(RampartEngine.java:311)
>
>       at org.apache.rampart.RampartEngine.process(RampartEngine.java:77)
>
>       at
> org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:92)
>
>
>
>
>
>
>
>
>
>    [
> https://issues.apache.org/jira/browse/RAMPART-358?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
> ]
>
>
>
> Sagara Gunathunga  updated RAMPART-358:
>
> ---------------------------------------
>
>
>
>     Fix Version/s:     (was: 1.6.2)
>
>                    1.7.0
>
>
>
> Moved to next release.
>
>
>
> Possible NullPointerException in
> RampartEngine.isSecurityFault(RampartMessageData)
>
> ----------------------------------------------------------------------------------
>
>
>
>                 Key: RAMPART-358
>
>                 URL: https://issues.apache.org/jira/browse/RAMPART-358
>
>             Project: Rampart
>
>          Issue Type: Bug
>
>          Components: rampart-core
>
>            Reporter: Filippo Ortolan
>
>             Fix For: 1.7.0
>
>
>
>   Original Estimate: 10m
>
> Remaining Estimate: 10m
>
>
>
> in RampartEngine class I get a NullPointerException in line 369 (method:
> isSecurityFault). Seems that this line:
>
> if
> (faultCode.getTextAsQName().getNamespaceURI().equals(WSConstants.WSSE_NS)) {
>
>                                                return true;
>
>                                    }
>
> throws the exception because getTextAsQName() can return null and this
> should be
> handled.
>
> Solution:
>
> QName faultCodeQName = faultCode.getTextAsQName();
>
> if (faultCodeQName == null) {
>
> // handle exception
>
>    return false; // ?
>
> } else {
>
>    if (faultCodeQName.getNamespaceURI().equals(WSConstants.WSSE_NS)) {
>
>       return true;
>
>    }
>
> }
>
>
>
> --
>
> This message is automatically generated by JIRA.
>
> If you think it was sent incorrectly, please contact your JIRA
> administrators:
> https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
>
> For more information on JIRA, see: http://www.atlassian.com/software/jira
>
>
>
> ---------------------------------------------------------------------
>
> To unsubscribe, e-mail: java...@axis.apache.org
>
> For additional commands, e-mail: java...@axis.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@axis.apache.org
For additional commands, e-mail: java-dev-help@axis.apache.org


RE: NullPointerException in isSecurityFault method

Posted by "Onur Ulusu (Garanti Teknoloji)" <On...@garanti.com.tr>.
Actually, ElementImpl class (public class ElementImpl extends ParentNode implements Element, OMElementEx, OMNodeEx, NamedNode, OMConstants) of axiom-dom-1.2.13 seems to implement getTextAsQName as below, when I step into getTextAsQName method, debugger steps to lines.

I think the problem is “:” character in the faultcode returned from service (“<faultcode>{HATA KODU:}K060</faultcode>”). When I remove “:” char from service response in debugger, no exception occurs.


public QName getTextAsQName() {
        String childText = getText().trim();
        return childText.length() == 0 ? null : resolveQName(childText);
    }

public QName resolveQName(String qname) {
        int idx = qname.indexOf(':');
        if (idx == -1) {
            OMNamespace ns = getDefaultNamespace();
            return ns == null ? new QName(qname) : new QName(ns.getNamespaceURI(), qname, "");
        } else {
            String prefix = qname.substring(0, idx);
            OMNamespace ns = findNamespace(null, prefix);
            return ns == null ? null : new QName(ns.getNamespaceURI(), qname.substring(idx+1), prefix);
        }
    }
From: Martin Gainty [mailto:mgainty@hotmail.com]
Sent: Friday, August 24, 2012 4:08 PM
To: java-dev@axis.apache.org; Onur Ulusu (Garanti Teknoloji)
Subject: RE: NullPointerException in isSecurityFault method

apparently getTextAsQName was never implemented in SOAPFaultCode.java

package org.apache.axis.soap;
import org.apache.axis.om.OMElement;
/**
 * Copyright 2001-2004 The Apache Software Foundation.
 * <p/>
 * Licensed 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
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * 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.
 * <p/>
 */
public interface SOAPFaultCode extends OMElement{
    /**
     * Eran Chinthaka (chinthaka@apache.org<ma...@apache.org>)
     */

    /**
     * @param value
     */
    public void addValue(SOAPFaultCodeValue value);

    /**
     * @return
     */
    public SOAPFaultCodeValue getValue();

    /**
     * @param value
     */
    public void addSubCode(SOAPFaultSubCode value);

    /**
     * @return
     */
    public SOAPFaultSubCode getSubCode();

}

//Implementor forgot to override getTextAsQName
/*
 * Copyright 2004,2005 The Apache Software Foundation.
 *
 * Licensed 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.soap.impl.dom;

import org.apache.ws.commons.om.OMXMLParserWrapper;
import org.apache.ws.commons.om.impl.OMOutputImpl;
import org.apache.ws.commons.om.impl.llom.OMSerializerUtil;
import org.apache.ws.commons.om.impl.serialize.StreamWriterToContentHandlerConverter;
import org.apache.ws.commons.om.util.ElementHelper;
import org.apache.ws.commons.soap.SOAP12Constants;
import org.apache.ws.commons.soap.SOAPFactory;
import org.apache.ws.commons.soap.SOAPFault;
import org.apache.ws.commons.soap.SOAPFaultCode;
import org.apache.ws.commons.soap.SOAPFaultSubCode;
import org.apache.ws.commons.soap.SOAPFaultValue;
import org.apache.ws.commons.soap.SOAPProcessingException;

import javax.xml.stream.XMLStreamException;

public abstract class SOAPFaultCodeImpl  extends SOAPElement implements SOAPFaultCode{

    /**
     * Constructor OMElementImpl
     *
     * @param parent
     * @param builder
     */
    public SOAPFaultCodeImpl(SOAPFault parent, OMXMLParserWrapper builder,
            SOAPFactory factory) {
        super(parent, SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME, builder,
                factory);
    }

    /**
     * @param parent
     */
    public SOAPFaultCodeImpl(SOAPFault parent,
                             boolean extractNamespaceFromParent,
                             SOAPFactory factory) throws SOAPProcessingException {
        super(parent, SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME,
                extractNamespaceFromParent, factory);
    }

    /**
     * Eran Chinthaka (chinthaka@apache.org<ma...@apache.org>)
     */
    public void setValue(SOAPFaultValue value) throws SOAPProcessingException {
        ElementHelper.setNewElement(this, value, value);
    }

    public SOAPFaultValue getValue() {
        return (SOAPFaultValue) ElementHelper.getChildWithName(this,
                SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME);
    }

    public void setSubCode(SOAPFaultSubCode value) throws SOAPProcessingException {
        ElementHelper.setNewElement(this, getSubCode(), value);
    }

    public SOAPFaultSubCode getSubCode() {
        return (SOAPFaultSubCode) ElementHelper.getChildWithName(this,
                SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME);
    }

    protected void serialize(OMOutputImpl omOutput, boolean cache) throws XMLStreamException {
        // select the builder
        short builderType = PULL_TYPE_BUILDER;    // default is pull type
        if (builder != null) {
            builderType = this.builder.getBuilderType();
        }
        if ((builderType == PUSH_TYPE_BUILDER)
                && (builder.getRegisteredContentHandler() == null)) {
            builder.registerExternalContentHandler(new StreamWriterToContentHandlerConverter(omOutput));
        }


        if (!cache) {
            //No caching
            if (this.firstChild != null) {
                OMSerializerUtil.serializeStartpart(this, omOutput);
                firstChild.serializeAndConsume(omOutput);
                OMSerializerUtil.serializeEndpart(omOutput);
            } else if (!this.done) {
                if (builderType == PULL_TYPE_BUILDER) {
                    OMSerializerUtil.serializeByPullStream(this, omOutput);
                } else {
                    OMSerializerUtil.serializeStartpart(this, omOutput);
                    builder.setCache(cache);
                    builder.next();
                    OMSerializerUtil.serializeEndpart(omOutput);
                }
            } else {
                OMSerializerUtil.serializeNormal(this, omOutput, cache);
            }
            // do not serialise the siblings


        } else {
            //Cached
            OMSerializerUtil.serializeNormal(this, omOutput, cache);

            // do not serialise the siblings
        }


    }

}

//SOAP11 concrete class missed getTextAsQName as well
/*
 * Copyright 2004,2005 The Apache Software Foundation.
 *
 * Licensed 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.soap.impl.dom.soap11;

import org.apache.axis2.soap.impl.dom.SOAPFaultCodeImpl;
import org.apache.ws.commons.om.OMElement;
import org.apache.ws.commons.om.OMXMLParserWrapper;
import org.apache.ws.commons.om.impl.llom.OMSerializerUtil;
import org.apache.ws.commons.om.impl.serialize.StreamWriterToContentHandlerConverter;
import org.apache.ws.commons.soap.SOAP11Constants;
import org.apache.ws.commons.soap.SOAPFactory;
import org.apache.ws.commons.soap.SOAPFault;
import org.apache.ws.commons.soap.SOAPFaultSubCode;
import org.apache.ws.commons.soap.SOAPFaultValue;
import org.apache.ws.commons.soap.SOAPProcessingException;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

public class SOAP11FaultCodeImpl extends SOAPFaultCodeImpl {
    /**
     * Constructor OMElementImpl
     *
     * @param parent
     * @param builder
     */
    public SOAP11FaultCodeImpl(SOAPFault parent, OMXMLParserWrapper builder,
            SOAPFactory factory) {
        super(parent, builder, factory);
    }

    /**
     * @param parent
     */
    public SOAP11FaultCodeImpl(SOAPFault parent, SOAPFactory factory)
            throws SOAPProcessingException {
        super(parent, false, factory);
    }


    public void setSubCode(SOAPFaultSubCode subCode) throws SOAPProcessingException {
        if (!(subCode instanceof SOAP11FaultSubCodeImpl)) {
            throw new SOAPProcessingException(
                    "Expecting SOAP 1.1 implementation of SOAP Fault Sub " +
                    "Code. But received some other implementation");
        }
        super.setSubCode(subCode);
    }

    public void setValue(SOAPFaultValue value) throws SOAPProcessingException {
        if (!(value instanceof SOAP11FaultValueImpl)) {
            throw new SOAPProcessingException(
                    "Expecting SOAP 1.1 implementation of SOAP Fault Value. " +
                    "But received some other implementation");
        }
        super.setValue(value);
    }

    protected void checkParent(OMElement parent) throws SOAPProcessingException {
        if (!(parent instanceof SOAP11FaultImpl)) {
            throw new SOAPProcessingException(
                    "Expecting SOAP 1.1 implementation of SOAP Fault as the " +
                    "parent. But received some other implementation");
        }
    }

    protected void serialize(
            org.apache.ws.commons.om.impl.OMOutputImpl omOutput, boolean cache)
            throws XMLStreamException {

        // select the builder
        short builderType = PULL_TYPE_BUILDER;    // default is pull type
        if (builder != null) {
            builderType = this.builder.getBuilderType();
        }
        if ((builderType == PUSH_TYPE_BUILDER)
                && (builder.getRegisteredContentHandler() == null)) {
            builder.registerExternalContentHandler(
                    new StreamWriterToContentHandlerConverter(omOutput));
        }

        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
        if (this.getNamespace() != null) {
            String prefix = this.getNamespace().getPrefix();
            String nameSpaceName = this.getNamespace().getName();
            writer.writeStartElement(prefix, SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME,
                    nameSpaceName);
        } else {
            writer.writeStartElement(
                    SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME);
        }

        OMSerializerUtil.serializeAttributes(this, omOutput);
        OMSerializerUtil.serializeNamespaces(this, omOutput);


        String text = this.getValue().getText();
        writer.writeCharacters(text);
        writer.writeEndElement();
    }
}

//getTextAsQName method is missing from SOAP12 implementor also
/*
 * Copyright 2004,2005 The Apache Software Foundation.
 *
 * Licensed 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.soap.impl.dom.soap12;

import org.apache.axis2.soap.impl.dom.SOAPFaultCodeImpl;
import org.apache.ws.commons.om.OMElement;
import org.apache.ws.commons.om.OMXMLParserWrapper;
import org.apache.ws.commons.soap.SOAPFactory;
import org.apache.ws.commons.soap.SOAPFault;
import org.apache.ws.commons.soap.SOAPFaultSubCode;
import org.apache.ws.commons.soap.SOAPFaultValue;
import org.apache.ws.commons.soap.SOAPProcessingException;

public class SOAP12FaultCodeImpl extends SOAPFaultCodeImpl {
    /**
     * Constructor OMElementImpl
     *
     * @param parent
     * @param builder
     */
    public SOAP12FaultCodeImpl(SOAPFault parent, OMXMLParserWrapper builder,
            SOAPFactory factory) {
        super(parent, builder, factory);
    }

    /**
     * @param parent
     */
    public SOAP12FaultCodeImpl(SOAPFault parent, SOAPFactory factory)
            throws SOAPProcessingException {
        super(parent, true, factory);
    }


    public void setSubCode(SOAPFaultSubCode subCode)
            throws SOAPProcessingException {
        if (!(subCode instanceof SOAP12FaultSubCodeImpl)) {
            throw new SOAPProcessingException(
                    "Expecting SOAP 1.2 implementation of SOAP Fault " +
                    "Sub Code. But received some other implementation");
        }
        super.setSubCode(subCode);
    }

    public void setValue(SOAPFaultValue value) throws SOAPProcessingException {
        if (!(value instanceof SOAP12FaultValueImpl)) {
            throw new SOAPProcessingException(
                    "Expecting SOAP 1.2 implementation of SOAP Fault Value. " +
                    "But received some other implementation");
        }
        super.setValue(value);
    }

    protected void checkParent(OMElement parent) throws SOAPProcessingException {
        if (!(parent instanceof SOAP12FaultImpl)) {
            throw new SOAPProcessingException(
                    "Expecting SOAP 1.2 implementation of SOAP Fault as " +
                    "the parent. But received some other implementation");
        }
    }
}

the problem is getTextAsQName is missing in all implementors of SOAPFaultCode, abstract classes which implement SOAPFaultCode and concrete classes which extend
abstract classes which implement SOAPFaultCode in Axis
Good Catch!
Martin Gainty
______________________________________________
Verzicht und Vertraulichkeitanmerkung

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.




________________________________
From: OnurU@garanti.com.tr<ma...@garanti.com.tr>
To: java-dev@axis.apache.org<ma...@axis.apache.org>
Subject: NullPointerException in isSecurityFault method
Date: Fri, 24 Aug 2012 11:32:11 +0000
Hi,

We have same problem mentioned below, getTextAsQName() method returns null in our example, so we are getting nullPointerException from isSecurityFault() method. faultCode variable returned from service is “<faultcode>{HATA KODU:}K060</faultcode>” in our case. We are using Rampart version 1.6.2 in our project.

Is there any fixed versions for this case, if not, do you have any suggestion as a workaround?

Thanks,

Onur


if (soapVersionURI.equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
                  // This is a fault processing the security header
                  if (faultCode.getTextAsQName().getNamespaceURI().equals(WSConstants.WSSE_NS)) {
                        return true;
                  }


java.lang.NullPointerException
      at org.apache.rampart.RampartEngine.isSecurityFault(RampartEngine.java:311)
      at org.apache.rampart.RampartEngine.process(RampartEngine.java:77)
      at org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:92)




   [
https://issues.apache.org/jira/browse/RAMPART-358?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Sagara Gunathunga  updated RAMPART-358:
---------------------------------------

    Fix Version/s:     (was: 1.6.2)
                   1.7.0

Moved to next release.

Possible NullPointerException in
RampartEngine.isSecurityFault(RampartMessageData)
----------------------------------------------------------------------------------

                Key: RAMPART-358
                URL: https://issues.apache.org/jira/browse/RAMPART-358
            Project: Rampart
         Issue Type: Bug
         Components: rampart-core
           Reporter: Filippo Ortolan
            Fix For: 1.7.0

  Original Estimate: 10m
Remaining Estimate: 10m

in RampartEngine class I get a NullPointerException in line 369 (method:
isSecurityFault). Seems that this line:
if (faultCode.getTextAsQName().getNamespaceURI().equals(WSConstants.WSSE_NS)) {
                                               return true;
                                   }
throws the exception because getTextAsQName() can return null and this should be
handled.
Solution:
QName faultCodeQName = faultCode.getTextAsQName();
if (faultCodeQName == null) {
// handle exception
   return false; // ?
} else {
   if (faultCodeQName.getNamespaceURI().equals(WSConstants.WSSE_NS)) {
      return true;
   }
}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa<https://issues.apache.org/jira/secure/ContactAdministrators%21default.jspa>
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: java...@axis.apache.org<ma...@axis.apache.org>
For additional commands, e-mail: java...@axis.apache.org<ma...@axis.apache.org>


RE: NullPointerException in isSecurityFault method

Posted by Martin Gainty <mg...@hotmail.com>.
apparently getTextAsQName was never implemented in SOAPFaultCode.java

package org.apache.axis.soap;
import org.apache.axis.om.OMElement;
/**
 * Copyright 2001-2004 The Apache Software Foundation.
 * <p/>
 * Licensed 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
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * 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.
 * <p/>
 */
public interface SOAPFaultCode extends OMElement{
    /**
     * Eran Chinthaka (chinthaka@apache.org)
     */

    /**
     * @param value
     */
    public void addValue(SOAPFaultCodeValue value);

    /**
     * @return
     */
    public SOAPFaultCodeValue getValue();

    /**
     * @param value
     */
    public void addSubCode(SOAPFaultSubCode value);

    /**
     * @return
     */
    public SOAPFaultSubCode getSubCode();

}

//Implementor forgot to override getTextAsQName
/*
 * Copyright 2004,2005 The Apache Software Foundation.
 *
 * Licensed 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.soap.impl.dom;

import org.apache.ws.commons.om.OMXMLParserWrapper;
import org.apache.ws.commons.om.impl.OMOutputImpl;
import org.apache.ws.commons.om.impl.llom.OMSerializerUtil;
import org.apache.ws.commons.om.impl.serialize.StreamWriterToContentHandlerConverter;
import org.apache.ws.commons.om.util.ElementHelper;
import org.apache.ws.commons.soap.SOAP12Constants;
import org.apache.ws.commons.soap.SOAPFactory;
import org.apache.ws.commons.soap.SOAPFault;
import org.apache.ws.commons.soap.SOAPFaultCode;
import org.apache.ws.commons.soap.SOAPFaultSubCode;
import org.apache.ws.commons.soap.SOAPFaultValue;
import org.apache.ws.commons.soap.SOAPProcessingException;

import javax.xml.stream.XMLStreamException;

public abstract class SOAPFaultCodeImpl  extends SOAPElement implements SOAPFaultCode{

    /**
     * Constructor OMElementImpl
     *
     * @param parent
     * @param builder
     */
    public SOAPFaultCodeImpl(SOAPFault parent, OMXMLParserWrapper builder,
            SOAPFactory factory) {
        super(parent, SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME, builder,
                factory);
    }

    /**
     * @param parent
     */
    public SOAPFaultCodeImpl(SOAPFault parent,
                             boolean extractNamespaceFromParent, 
                             SOAPFactory factory) throws SOAPProcessingException {
        super(parent, SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME,
                extractNamespaceFromParent, factory);
    }

    /**
     * Eran Chinthaka (chinthaka@apache.org)
     */
    public void setValue(SOAPFaultValue value) throws SOAPProcessingException {
        ElementHelper.setNewElement(this, value, value);
    }

    public SOAPFaultValue getValue() {
        return (SOAPFaultValue) ElementHelper.getChildWithName(this,
                SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME);
    }

    public void setSubCode(SOAPFaultSubCode value) throws SOAPProcessingException {
        ElementHelper.setNewElement(this, getSubCode(), value);
    }

    public SOAPFaultSubCode getSubCode() {
        return (SOAPFaultSubCode) ElementHelper.getChildWithName(this,
                SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME);
    }

    protected void serialize(OMOutputImpl omOutput, boolean cache) throws XMLStreamException {
        // select the builder
        short builderType = PULL_TYPE_BUILDER;    // default is pull type
        if (builder != null) {
            builderType = this.builder.getBuilderType();
        }
        if ((builderType == PUSH_TYPE_BUILDER)
                && (builder.getRegisteredContentHandler() == null)) {
            builder.registerExternalContentHandler(new StreamWriterToContentHandlerConverter(omOutput));
        }


        if (!cache) {
            //No caching
            if (this.firstChild != null) {
                OMSerializerUtil.serializeStartpart(this, omOutput);
                firstChild.serializeAndConsume(omOutput);
                OMSerializerUtil.serializeEndpart(omOutput);
            } else if (!this.done) {
                if (builderType == PULL_TYPE_BUILDER) {
                    OMSerializerUtil.serializeByPullStream(this, omOutput);
                } else {
                    OMSerializerUtil.serializeStartpart(this, omOutput);
                    builder.setCache(cache);
                    builder.next();
                    OMSerializerUtil.serializeEndpart(omOutput);
                }
            } else {
                OMSerializerUtil.serializeNormal(this, omOutput, cache);
            }
            // do not serialise the siblings


        } else {
            //Cached
            OMSerializerUtil.serializeNormal(this, omOutput, cache);

            // do not serialise the siblings
        }


    }

}

//SOAP11 concrete class missed getTextAsQName as well
/*
 * Copyright 2004,2005 The Apache Software Foundation.
 *
 * Licensed 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.soap.impl.dom.soap11;

import org.apache.axis2.soap.impl.dom.SOAPFaultCodeImpl;
import org.apache.ws.commons.om.OMElement;
import org.apache.ws.commons.om.OMXMLParserWrapper;
import org.apache.ws.commons.om.impl.llom.OMSerializerUtil;
import org.apache.ws.commons.om.impl.serialize.StreamWriterToContentHandlerConverter;
import org.apache.ws.commons.soap.SOAP11Constants;
import org.apache.ws.commons.soap.SOAPFactory;
import org.apache.ws.commons.soap.SOAPFault;
import org.apache.ws.commons.soap.SOAPFaultSubCode;
import org.apache.ws.commons.soap.SOAPFaultValue;
import org.apache.ws.commons.soap.SOAPProcessingException;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

public class SOAP11FaultCodeImpl extends SOAPFaultCodeImpl {
    /**
     * Constructor OMElementImpl
     *
     * @param parent
     * @param builder
     */
    public SOAP11FaultCodeImpl(SOAPFault parent, OMXMLParserWrapper builder,
            SOAPFactory factory) {
        super(parent, builder, factory);
    }

    /**
     * @param parent
     */
    public SOAP11FaultCodeImpl(SOAPFault parent, SOAPFactory factory)
            throws SOAPProcessingException {
        super(parent, false, factory);
    }


    public void setSubCode(SOAPFaultSubCode subCode) throws SOAPProcessingException {
        if (!(subCode instanceof SOAP11FaultSubCodeImpl)) {
            throw new SOAPProcessingException(
                    "Expecting SOAP 1.1 implementation of SOAP Fault Sub " +
                    "Code. But received some other implementation");
        }
        super.setSubCode(subCode);
    }

    public void setValue(SOAPFaultValue value) throws SOAPProcessingException {
        if (!(value instanceof SOAP11FaultValueImpl)) {
            throw new SOAPProcessingException(
                    "Expecting SOAP 1.1 implementation of SOAP Fault Value. " +
                    "But received some other implementation");
        }
        super.setValue(value);
    }

    protected void checkParent(OMElement parent) throws SOAPProcessingException {
        if (!(parent instanceof SOAP11FaultImpl)) {
            throw new SOAPProcessingException(
                    "Expecting SOAP 1.1 implementation of SOAP Fault as the " +
                    "parent. But received some other implementation");
        }
    }

    protected void serialize(
            org.apache.ws.commons.om.impl.OMOutputImpl omOutput, boolean cache)
            throws XMLStreamException {

        // select the builder
        short builderType = PULL_TYPE_BUILDER;    // default is pull type
        if (builder != null) {
            builderType = this.builder.getBuilderType();
        }
        if ((builderType == PUSH_TYPE_BUILDER)
                && (builder.getRegisteredContentHandler() == null)) {
            builder.registerExternalContentHandler(
                    new StreamWriterToContentHandlerConverter(omOutput));
        }

        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
        if (this.getNamespace() != null) {
            String prefix = this.getNamespace().getPrefix();
            String nameSpaceName = this.getNamespace().getName();
            writer.writeStartElement(prefix, SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME,
                    nameSpaceName);
        } else {
            writer.writeStartElement(
                    SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME);
        }

        OMSerializerUtil.serializeAttributes(this, omOutput);
        OMSerializerUtil.serializeNamespaces(this, omOutput);


        String text = this.getValue().getText();
        writer.writeCharacters(text);
        writer.writeEndElement();
    }
}

//getTextAsQName method is missing from SOAP12 implementor also
/*
 * Copyright 2004,2005 The Apache Software Foundation.
 *
 * Licensed 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.soap.impl.dom.soap12;

import org.apache.axis2.soap.impl.dom.SOAPFaultCodeImpl;
import org.apache.ws.commons.om.OMElement;
import org.apache.ws.commons.om.OMXMLParserWrapper;
import org.apache.ws.commons.soap.SOAPFactory;
import org.apache.ws.commons.soap.SOAPFault;
import org.apache.ws.commons.soap.SOAPFaultSubCode;
import org.apache.ws.commons.soap.SOAPFaultValue;
import org.apache.ws.commons.soap.SOAPProcessingException;

public class SOAP12FaultCodeImpl extends SOAPFaultCodeImpl {
    /**
     * Constructor OMElementImpl
     *
     * @param parent
     * @param builder
     */
    public SOAP12FaultCodeImpl(SOAPFault parent, OMXMLParserWrapper builder,
            SOAPFactory factory) {
        super(parent, builder, factory);
    }

    /**
     * @param parent
     */
    public SOAP12FaultCodeImpl(SOAPFault parent, SOAPFactory factory)
            throws SOAPProcessingException {
        super(parent, true, factory);
    }


    public void setSubCode(SOAPFaultSubCode subCode)
            throws SOAPProcessingException {
        if (!(subCode instanceof SOAP12FaultSubCodeImpl)) {
            throw new SOAPProcessingException(
                    "Expecting SOAP 1.2 implementation of SOAP Fault " +
                    "Sub Code. But received some other implementation");
        }
        super.setSubCode(subCode);
    }

    public void setValue(SOAPFaultValue value) throws SOAPProcessingException {
        if (!(value instanceof SOAP12FaultValueImpl)) {
            throw new SOAPProcessingException(
                    "Expecting SOAP 1.2 implementation of SOAP Fault Value. " +
                    "But received some other implementation");
        }
        super.setValue(value);
    }

    protected void checkParent(OMElement parent) throws SOAPProcessingException {
        if (!(parent instanceof SOAP12FaultImpl)) {
            throw new SOAPProcessingException(
                    "Expecting SOAP 1.2 implementation of SOAP Fault as " +
                    "the parent. But received some other implementation");
        }
    }
}

the problem is getTextAsQName is missing in all implementors of SOAPFaultCode, abstract classes which implement SOAPFaultCode and concrete classes which extend 
abstract classes which implement SOAPFaultCode in Axis
Good Catch!
Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.




From: OnurU@garanti.com.tr
To: java-dev@axis.apache.org
Subject: NullPointerException in isSecurityFault method
Date: Fri, 24 Aug 2012 11:32:11 +0000










Hi,
 
We have same problem mentioned below, getTextAsQName() method returns null in our example, so we are getting nullPointerException from isSecurityFault() method. faultCode variable
 returned from service is “<faultcode>{HATA KODU:}K060</faultcode>”
in our case. We are using Rampart version 1.6.2 in our project.
 
Is there any fixed versions for this case, if not, do you have any suggestion as a workaround?
 
Thanks,

 
Onur
 
 
if (soapVersionURI.equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI))
 {
                 
// This is a fault processing the security header
                 
if (faultCode.getTextAsQName().getNamespaceURI().equals(WSConstants.WSSE_NS))
 {
                       
return
true;
                  }
 
 
java.lang.NullPointerException
      at org.apache.rampart.RampartEngine.isSecurityFault(RampartEngine.java:311)
      at org.apache.rampart.RampartEngine.process(RampartEngine.java:77)
      at org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:92)
 

 

 
 
   [

https://issues.apache.org/jira/browse/RAMPART-358?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

]
 

Sagara Gunathunga  updated RAMPART-358:

---------------------------------------
 

    Fix Version/s:     (was: 1.6.2)
                   1.7.0
 

Moved to next release.
 
Possible NullPointerException in

RampartEngine.isSecurityFault(RampartMessageData)
----------------------------------------------------------------------------------
 
                Key: RAMPART-358
                URL:
https://issues.apache.org/jira/browse/RAMPART-358
            Project: Rampart
         Issue Type: Bug
         Components: rampart-core
           Reporter: Filippo Ortolan
            Fix For: 1.7.0
 
  Original Estimate: 10m
Remaining Estimate: 10m
 
in RampartEngine class I get a NullPointerException in line 369 (method:

isSecurityFault). Seems that this line:
if (faultCode.getTextAsQName().getNamespaceURI().equals(WSConstants.WSSE_NS)) {
                                               return true;
                                   }
throws the exception because getTextAsQName() can return null and this should be

handled.
Solution:
QName faultCodeQName = faultCode.getTextAsQName();
if (faultCodeQName == null) {
// handle exception
   return false; // ?
} else {
   if (faultCodeQName.getNamespaceURI().equals(WSConstants.WSSE_NS)) {
      return true;
   }
}
 
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:

https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see:
http://www.atlassian.com/software/jira
 
---------------------------------------------------------------------
To unsubscribe, e-mail: java...@axis.apache.org
For additional commands, e-mail: java...@axis.apache.org