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 di...@apache.org on 2007/03/16 13:58:08 UTC
svn commit: r518959 - in /webservices/axis2/trunk/java/modules/saaj:
src/org/apache/axis2/saaj/SOAPFaultImpl.java
test/org/apache/axis2/saaj/SAAJResultTest.java
test/org/apache/axis2/saaj/SOAPFaultTest.java
Author: dims
Date: Fri Mar 16 05:58:06 2007
New Revision: 518959
URL: http://svn.apache.org/viewvc?view=rev&rev=518959
Log:
Few more fixes from sumedha for AXIS2-1956 - SAAJ 1.3 implementation
Modified:
webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFaultImpl.java
webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SAAJResultTest.java
webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultTest.java
Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFaultImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFaultImpl.java?view=diff&rev=518959&r1=518958&r2=518959
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFaultImpl.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFaultImpl.java Fri Mar 16 05:58:06 2007
@@ -51,7 +51,6 @@
import org.apache.axiom.soap.impl.dom.soap11.SOAP11FaultDetailImpl;
import org.apache.axiom.soap.impl.dom.soap11.SOAP11FaultReasonImpl;
import org.apache.axiom.soap.impl.dom.soap11.SOAP11FaultRoleImpl;
-import org.apache.axiom.soap.impl.dom.soap11.SOAP11FaultTextImpl;
import org.apache.axiom.soap.impl.dom.soap12.SOAP12Factory;
import org.apache.axiom.soap.impl.dom.soap12.SOAP12FaultDetailImpl;
import org.apache.axiom.soap.impl.dom.soap12.SOAP12FaultRoleImpl;
@@ -90,30 +89,26 @@
*/
public void setFaultCode(String faultCode) throws SOAPException {
org.apache.axiom.soap.SOAPFactory soapFactory = null;
- boolean isSoap11 = this.element.getNamespace().getNamespaceURI()
- .equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+ SOAPFaultCode soapFaultCode = null;
//It must be of the form "prefix:localName" where the prefix has been defined in a
//namespace declaration.
if(faultCode.indexOf(":") == -1){
throw new SOAPException("faultCode must be of the form prefix:localName");
- }else{
- String prefix,localName ="";
- prefix = faultCode.substring(0, faultCode.indexOf(":"));
- localName = faultCode.substring(faultCode.indexOf(":")+1);
}
+// else{
+// String prefix,localName ="";
+// prefix = faultCode.substring(0, faultCode.indexOf(":"));
+// localName = faultCode.substring(faultCode.indexOf(":")+1);
+// }
- if(isSoap11){
- soapFactory = DOOMAbstractFactory.getSOAP11Factory();
- } else {
- soapFactory = DOOMAbstractFactory.getSOAP12Factory();
- }
-
- SOAPFaultCode soapFaultCode = soapFactory.createSOAPFaultCode(fault);
-
- if(isSoap11) {
+ if(this.element.getOMFactory() instanceof SOAP11Factory) {
+ soapFactory = (SOAP11Factory)this.element.getOMFactory();
+ soapFaultCode = soapFactory.createSOAPFaultCode(fault);
soapFaultCode.setText(faultCode);
- } else {
+ } else if(this.element.getOMFactory() instanceof SOAP12Factory) {
+ soapFactory = (SOAP12Factory)this.element.getOMFactory();
+ soapFaultCode = soapFactory.createSOAPFaultCode(fault);
SOAPFaultValue soapFaultValue = soapFactory.createSOAPFaultValue(soapFaultCode);
soapFaultCode.setValue(soapFaultValue);
soapFaultValue.setText(faultCode);
@@ -130,10 +125,17 @@
* @see #setFaultCode(java.lang.String) setFaultCode(java.lang.String)
*/
public String getFaultCode() {
- if (fault != null && fault.getCode() != null && fault.getCode().getValue() != null) {
- return fault.getCode().getValue().getText();
- }
- return null;
+ if(fault != null && fault.getCode() != null){
+ if(this.element.getOMFactory() instanceof SOAP11Factory){
+ return fault.getCode().getText();
+ }else if(this.element.getOMFactory() instanceof SOAP12Factory){
+ return fault.getCode().getValue().getText();
+ }else{
+ return null;
+ }
+ }else{
+ return null;
+ }
}
@@ -323,36 +325,29 @@
*@see getFaultString()
*/
- //TODO : check the implementation
public void setFaultString(String faultString, Locale locale) throws SOAPException {
- boolean isSoap11 = this.element.getNamespace().getNamespaceURI()
- .equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-
- if (this.fault.getReason() != null) {
- SOAPFaultReason reason = this.fault.getReason();
- if(isSoap11) {
- reason.setText(faultString);
- } else {
- if (reason.getFirstSOAPText() != null) {
- reason.getFirstSOAPText().setText(faultString);
- reason.getFirstSOAPText().setLang(locale.toString());
- } else {
- addFaultReasonText(faultString, locale);
- }
- }
-
- } else {
-
- if(isSoap11) {
- SOAPFaultReason reason = new SOAP11FaultReasonImpl(this.fault,
- (SOAPFactory) this.element.getOMFactory());
- reason.setText(faultString);
- }else if(this.element.getOMFactory() instanceof SOAP12Factory){
- addFaultReasonText(faultString, locale);
- }
-
- }
- this.faultReasonLocale = locale;
+ if (this.fault.getReason() != null) {
+ SOAPFaultReason reason = this.fault.getReason();
+ if(this.element.getOMFactory() instanceof SOAP11Factory) {
+ reason.setText(faultString);
+ }else if(this.element.getOMFactory() instanceof SOAP12Factory){
+ if (reason.getFirstSOAPText() != null) {
+ reason.getFirstSOAPText().setText(faultString);
+ reason.getFirstSOAPText().setLang(locale.toString());
+ } else {
+ addFaultReasonText(faultString, locale);
+ }
+ }
+ }else{
+ if(this.element.getOMFactory() instanceof SOAP11Factory) {
+ SOAPFaultReason reason = new SOAP11FaultReasonImpl(this.fault,
+ (SOAPFactory) this.element.getOMFactory());
+ reason.setText(faultString);
+ }else if(this.element.getOMFactory() instanceof SOAP12Factory){
+ addFaultReasonText(faultString, locale);
+ }
+ }
+ this.faultReasonLocale = locale;
}
/**
@@ -509,17 +504,15 @@
* <p/>
*/
public QName getFaultCodeAsQName() {
- boolean isSoap11 = this.element.getNamespace().getNamespaceURI()
- .equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
SOAPFaultCode soapFaultCode = this.fault.getCode();
if (soapFaultCode != null) {
String prefix = "";
String localPart = "";
String uri = "";
String text = "";
- if(isSoap11) {
+ if(this.element.getOMFactory() instanceof SOAP11Factory) {
text = soapFaultCode.getText();
- } else {
+ } else if(this.element.getOMFactory() instanceof SOAP12Factory){
text = soapFaultCode.getValue().getText();
}
@@ -527,9 +520,9 @@
prefix = text.substring(0, text.indexOf(":"));
localPart = text.substring(text.indexOf(":") + 1);
- if(isSoap11) {
- uri = fault.findNamespaceURI(prefix).getNamespaceURI();
- } else {
+ if(this.element.getOMFactory() instanceof SOAP11Factory){
+ uri = soapFaultCode.findNamespaceURI(prefix).getNamespaceURI();
+ } else if(this.element.getOMFactory() instanceof SOAP12Factory){
OMNamespace namespace = soapFaultCode.getValue().getNamespace();
if (namespace != null) {
uri = soapFaultCode.getValue().getNamespace().getNamespaceURI();
@@ -770,47 +763,44 @@
* @see getFaultCodeAsQName(), setFaultCode(Name), getFaultCodeAsQName()
*/
public void setFaultCode(QName qname) throws SOAPException {
- boolean isSoap11 = this.element.getNamespace().getNamespaceURI()
- .equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-
- if (qname.getNamespaceURI() == null
- || qname.getNamespaceURI().trim().length() == 0) {
- throw new SOAPException("Unqualified QName object : " + qname);
- }
- org.apache.axiom.soap.SOAPFactory soapFactory = null;
- if (this.element.getOMFactory() instanceof SOAP11Factory) {
- soapFactory = (SOAPFactory) this.element.getOMFactory();
- } else if (this.element.getOMFactory() instanceof SOAP12Factory) {
- if (!(qname.getNamespaceURI()
- .equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE))) {
- throw new SOAPException("Incorrect URI"
- + qname.getNamespaceURI());
- }
- soapFactory = (SOAPFactory) this.element.getOMFactory();
- } else {
- throw new SOAPException();
- }
- SOAPFaultCode soapFaultCode = soapFactory
- .createSOAPFaultCode(this.fault);
-
- String prefix = ((qname.getPrefix() != null) && !qname.getPrefix()
- .equals("")) ? qname.getPrefix() : this.fault.getQName()
- .getPrefix();
-
- if(isSoap11) {
- soapFaultCode.setText(prefix + ":" + qname.getLocalPart());
- OMNamespace omNamespace = new OMNamespaceImpl(qname.getNamespaceURI(),
- qname.getPrefix());
- soapFaultCode.setNamespace(omNamespace);
- } else {
- SOAPFaultValue soapFaultValue = soapFactory.createSOAPFaultValue(soapFaultCode);
- // don't just use the default prefix, use the passed one or the parent's
-
- soapFaultValue.setText(prefix + ":" + qname.getLocalPart());
- OMNamespace omNamespace = new OMNamespaceImpl(qname.getNamespaceURI(),
- qname.getPrefix());
- soapFaultValue.setNamespace(omNamespace);
- }
+ if (qname.getNamespaceURI() == null
+ || qname.getNamespaceURI().trim().length() == 0) {
+ throw new SOAPException("Unqualified QName object : " + qname);
+ }
+
+ org.apache.axiom.soap.SOAPFactory soapFactory = null;
+ if (this.element.getOMFactory() instanceof SOAP11Factory) {
+ soapFactory = (SOAPFactory) this.element.getOMFactory();
+ } else if (this.element.getOMFactory() instanceof SOAP12Factory) {
+ if (!(qname.getNamespaceURI()
+ .equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE))) {
+ throw new SOAPException("Incorrect URI"
+ + qname.getNamespaceURI());
+ }
+ soapFactory = (SOAPFactory) this.element.getOMFactory();
+ } else {
+ throw new SOAPException("Invalid SOAP version");
+ }
+ SOAPFaultCode soapFaultCode = soapFactory.createSOAPFaultCode(this.fault);
+
+ String prefix = ((qname.getPrefix() != null) && !qname.getPrefix()
+ .equals("")) ? qname.getPrefix() : this.fault.getQName()
+ .getPrefix();
+
+ if(this.element.getOMFactory() instanceof SOAP11Factory) {
+ soapFaultCode.setText(prefix + ":" + qname.getLocalPart());
+ OMNamespace omNamespace = new OMNamespaceImpl(qname.getNamespaceURI(),
+ qname.getPrefix());
+ soapFaultCode.setNamespace(omNamespace);
+ soapFaultCode.declareNamespace(omNamespace);
+ } else if (this.element.getOMFactory() instanceof SOAP12Factory) {
+ SOAPFaultValue soapFaultValue = soapFactory.createSOAPFaultValue(soapFaultCode);
+ // don't just use the default prefix, use the passed one or the parent's
+ soapFaultValue.setText(prefix + ":" + qname.getLocalPart());
+ OMNamespace omNamespace = new OMNamespaceImpl(qname.getNamespaceURI(),
+ qname.getPrefix());
+ soapFaultValue.setNamespace(omNamespace);
+ }
}
/**
Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SAAJResultTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SAAJResultTest.java?view=diff&rev=518959&r1=518958&r2=518959
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SAAJResultTest.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SAAJResultTest.java Fri Mar 16 05:58:06 2007
@@ -1,64 +1,61 @@
-/*
- * 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.saaj;
-
-import javax.xml.soap.MessageFactory;
-import javax.xml.soap.Node;
-import javax.xml.soap.SAAJResult;
-import javax.xml.soap.SOAPBody;
-import javax.xml.soap.SOAPEnvelope;
-import javax.xml.soap.SOAPHeader;
-import javax.xml.soap.SOAPHeaderElement;
-import javax.xml.soap.SOAPMessage;
-import javax.xml.soap.SOAPPart;
-
-import junit.framework.TestCase;
-
-/**
- *
- */
-public class SAAJResultTest extends TestCase {
- private SOAPMessage msg = null;
- private SOAPPart sp = null;
- private SOAPBody body = null;
- private SOAPEnvelope envelope = null;
- private SOAPHeader header = null;
- private SOAPHeaderElement headerEle = null;
-
- protected void setUp() throws Exception {
- msg = MessageFactory.newInstance().createMessage();
- sp = msg.getSOAPPart();
- envelope = sp.getEnvelope();
- body = envelope.getBody();
- header = envelope.getHeader();
- headerEle = header.addHeaderElement(envelope.createName("foo", "f", "foo-URI"));
- headerEle.setActor("actor-URI");
- }
-
-
- public void testGetResult() {
- try
- {
- SAAJResult sr = new SAAJResult();
- Node node = sr.getResult();
- assertNull(node);
- } catch (Exception e) {
- fail("Exception: " + e);
- }
- }
-
-
-}
+/*
+ * 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.saaj;
+
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.Node;
+import javax.xml.soap.SAAJResult;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPHeaderElement;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.SOAPPart;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class SAAJResultTest extends TestCase {
+ private SOAPMessage msg = null;
+ private SOAPPart sp = null;
+ private SOAPBody body = null;
+ private SOAPEnvelope envelope = null;
+ private SOAPHeader header = null;
+ private SOAPHeaderElement headerEle = null;
+
+ protected void setUp() throws Exception {
+ msg = MessageFactory.newInstance().createMessage();
+ sp = msg.getSOAPPart();
+ envelope = sp.getEnvelope();
+ body = envelope.getBody();
+ header = envelope.getHeader();
+ headerEle = header.addHeaderElement(envelope.createName("foo", "f", "foo-URI"));
+ headerEle.setActor("actor-URI");
+ }
+
+
+ public void testGetResult() {
+ try{
+ SAAJResult sr = new SAAJResult();
+ Node node = sr.getResult();
+ assertNull(node);
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+ }
+}
Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultTest.java?view=diff&rev=518959&r1=518958&r2=518959
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultTest.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultTest.java Fri Mar 16 05:58:06 2007
@@ -802,4 +802,122 @@
fail("Exception: " + e);
}
}
+
+
+ public void testFaultCodeWithPrefix1(){
+ try {
+ MessageFactory fac = MessageFactory.newInstance();
+ SOAPMessage soapMessage = fac.createMessage();
+ SOAPPart soapPart = soapMessage.getSOAPPart();
+ SOAPEnvelope envelope = soapPart.getEnvelope();
+ SOAPBody body = envelope.getBody();
+ SOAPFault sf = body.addFault();
+
+ String prefix = "wso2";
+ sf.setFaultCode(prefix+":Server");
+ String result=sf.getFaultCode();
+
+ assertNotNull(result);
+ assertEquals(prefix+":Server", result);
+ } catch(Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ public void testFaultCodeWithPrefix2(){
+ try {
+ MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+ SOAPMessage soapMessage = fac.createMessage();
+ SOAPPart soapPart = soapMessage.getSOAPPart();
+ SOAPEnvelope envelope = soapPart.getEnvelope();
+ SOAPBody body = envelope.getBody();
+ SOAPFault sf = body.addFault();
+
+ String prefix = "wso2";
+ sf.setFaultCode(prefix+":Server");
+ String result=sf.getFaultCode();
+
+ assertNotNull(result);
+ assertEquals(prefix+":Server", result);
+ } catch(Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ public void testSetGetFaultCodeAsName1(){
+ try {
+ SOAPFactory fac = SOAPFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
+ SOAPFault sf = fac.createFault();
+
+ Name name = fac.createName("myfault", "flt", "http://example.com");
+ sf.setFaultCode(name);
+ Name name2 = sf.getFaultCodeAsName();
+ assertNotNull(name2);
+ assertEquals(name2.getLocalName(),name.getLocalName());
+ assertEquals(name2.getPrefix(),name.getPrefix());
+ assertEquals(name2.getURI(),name.getURI());
+ } catch(Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+
+ public void testSetGetFaultCodeAsName2(){
+ try {
+ QName qname = SOAPConstants.SOAP_SENDER_FAULT;
+ SOAPFactory fac = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+ Name name = fac.createName(qname.getLocalPart(),
+ qname.getPrefix(), qname.getNamespaceURI());
+ SOAPFault sf = fac.createFault();
+ sf.setFaultCode(name);
+ Name name2 = sf.getFaultCodeAsName();
+ assertNotNull(name2);
+ assertEquals(name2.getLocalName(),name.getLocalName());
+ assertEquals(name2.getPrefix(),name.getPrefix());
+ assertEquals(name2.getURI(),name.getURI());
+ } catch(Exception e) {
+ fail(e.getMessage());
+ }
+
+ }
+
+
+ public void testSetGetFaultCodeAsQName1() {
+ try {
+ SOAPFactory fac = SOAPFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
+ SOAPFault sf = fac.createFault();
+
+ QName name = new QName("http://example.com", "myfault", "flt");
+ sf.setFaultCode(name);
+ QName name2 = sf.getFaultCodeAsQName();
+
+ assertNotNull(name2);
+ assertEquals(name2.getLocalPart(), name.getLocalPart());
+ assertEquals(name2.getPrefix(), name.getPrefix());
+ assertEquals(name2.getNamespaceURI(), name.getNamespaceURI());
+ }catch(Exception e){
+ fail(e.getMessage());
+ }
+ }
+
+
+
+ public void testSetGetFaultCodeAsQName2() {
+ try{
+ QName name = SOAPConstants.SOAP_SENDER_FAULT;
+ SOAPFactory fac = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+ SOAPFault sf = fac.createFault();
+ sf.setFaultCode(name);
+ QName name2 = sf.getFaultCodeAsQName();
+
+ assertNotNull(name2);
+ assertEquals(name2.getLocalPart(),name.getLocalPart());
+ assertEquals(name2.getPrefix(),name.getPrefix());
+ assertEquals(name2.getNamespaceURI(),name.getNamespaceURI());
+ }catch(Exception e){
+ fail(e.getMessage());
+ }
+ }
+
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org