Skip to content

Commit 88b56cd

Browse files
AXIS2-5975 More specific Runtime Exceptions instead of just 'Input values do not follow defined XSD restrictions'
1 parent d663fc5 commit 88b56cd

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate-bean.xsl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@
162162
protected void validate<xsl:value-of select="$javaName"/>(<xsl:value-of select="$propertyType"/> param){
163163
<xsl:if test="not(@unbound) and @array">
164164
if ((param != null) &amp;&amp; (param.length &gt; <xsl:value-of select="@maxOccurs"/>)){
165-
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions");
165+
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions, not unbound and array found XSL condition 'param != null' and param.length greater than maxOccurs");
166166
}
167167
</xsl:if>
168168
<xsl:if test="$min!=0 and @array">
169169
if ((param != null) &amp;&amp; (param.length &lt; <xsl:value-of select="$min"/>)){
170-
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions");
170+
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions, min!=0 and array found XSL condition 'param != null' and param.length less than min");
171171
}
172172
</xsl:if>
173173
}
@@ -334,12 +334,12 @@
334334
protected void validate<xsl:value-of select="$javaName"/>(<xsl:value-of select="$propertyType"/> param){
335335
<xsl:if test="not(@unbound)">
336336
if ((param != null) &amp;&amp; (param.length &gt; <xsl:value-of select="@maxOccurs"/>)){
337-
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions");
337+
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions, not unbound found XSL condition 'param != null' and param.length greater than maxOccurs");
338338
}
339339
</xsl:if>
340340
<xsl:if test="$min!=0">
341341
if ((param != null) &amp;&amp; (param.length &lt; <xsl:value-of select="$min"/>)){
342-
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions");
342+
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions, min!=0 found XSL condition 'param != null' and param.length less than min");
343343
}
344344
</xsl:if>
345345
}
@@ -463,23 +463,23 @@
463463

464464
}
465465
else {
466-
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions");
466+
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions, on restrictionBaseType with maxLenFacet and minLenFacet and patternFacet failed XSL 'if' condition 'org.apache.axis2.databinding.utils.ConverterUtil.convertToString(param).matches()'");
467467
}
468468
</xsl:when>
469469
<xsl:when test="(@patternFacet)">
470470
if (org.apache.axis2.databinding.utils.ConverterUtil.convertToString(param).matches("<xsl:value-of select="$patternFacet"/>")) {
471471
this.<xsl:value-of select="$varName"/>=param;
472472
}
473473
else {
474-
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions");
474+
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions, on restrictionBaseType with patternFacet failed XSL 'if' condition 'org.apache.axis2.databinding.utils.ConverterUtil.convertToString(param).matches(patternFacet)'");
475475
}
476476
</xsl:when>
477477
<xsl:when test="(@lenFacet)">
478478
if (org.apache.axis2.databinding.utils.ConverterUtil.convertToString(param).length() == <xsl:value-of select="@lenFacet"/> ) {
479479
this.<xsl:value-of select="$varName"/>=param;
480480
}
481481
else {
482-
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions");
482+
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions, on restrictionBaseType with lenFacet failed XSL 'if' condition 'org.apache.axis2.databinding.utils.ConverterUtil.convertToString(param).length() == lenFacet)'");
483483
}
484484
</xsl:when>
485485
<xsl:when test="(@maxLenFacet) or (@minLenFacet)">
@@ -488,7 +488,7 @@
488488
this.<xsl:value-of select="$varName"/>=param;
489489
}
490490
else {
491-
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions");
491+
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions, on restrictionBaseType with maxLenFacet or minLenFacetlen failed XSL 'if' condition 'org.apache.axis2.databinding.utils.ConverterUtil.convertToString(param).length() == maxLenFacet)'");
492492
}
493493
</xsl:when>
494494
<xsl:when test="(@totalDigitsFacet)">
@@ -497,7 +497,7 @@
497497
this.<xsl:value-of select="$varName"/>=param;
498498
}
499499
else {
500-
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions");
500+
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions, on restrictionBaseType with totalDigitsFacet failed XSL 'if' condition 'org.apache.axis2.databinding.utils.ConverterUtil.compare(param, totalDigitsDecimal) less than zero'");
501501
}
502502
</xsl:when>
503503
<xsl:when test="@maxExFacet or @minExFacet or @maxInFacet or @minInFacet">
@@ -506,31 +506,31 @@
506506
this.<xsl:value-of select="$varName"/>=param;
507507
}
508508
else {
509-
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions");
509+
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions, on restrictionBaseType with maxExFacet failed XSL 'if' condition 'org.apache.axis2.databinding.utils.ConverterUtil.compare(param, maxExFacet)' less than zero");
510510
}
511511
</xsl:if>
512512
<xsl:if test="@minExFacet">
513513
if (org.apache.axis2.databinding.utils.ConverterUtil.compare(param, "<xsl:value-of select="$minExFacet"/>") &gt; 0){
514514
this.<xsl:value-of select="$varName"/>=param;
515515
}
516516
else {
517-
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions");
517+
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions, on restrictionBaseType with minExFacet failed XSL 'if' condition 'org.apache.axis2.databinding.utils.ConverterUtil.compare(param, minExFacet) greater than zero'");
518518
}
519519
</xsl:if>
520520
<xsl:if test="@maxInFacet">
521521
if (org.apache.axis2.databinding.utils.ConverterUtil.compare(param, "<xsl:value-of select="$maxInFacet"/>") &lt;= 0){
522522
this.<xsl:value-of select="$varName"/>=param;
523523
}
524524
else {
525-
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions");
525+
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions, on restrictionBaseType with maxInFacet failed XSL 'if' condition 'org.apache.axis2.databinding.utils.ConverterUtil.compare(param, maxInFacet) less than or equal zero'");
526526
}
527527
</xsl:if>
528528
<xsl:if test="@minInFacet">
529529
if (org.apache.axis2.databinding.utils.ConverterUtil.compare(param, "<xsl:value-of select="$minInFacet"/>") &gt;= 0){
530530
this.<xsl:value-of select="$varName"/>=param;
531531
}
532532
else {
533-
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions");
533+
throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions, on restrictionBaseType with minInFacet failed XSL 'if' condition 'org.apache.axis2.databinding.utils.ConverterUtil.compare(param, minInFacet) greater than or equal zero'");
534534
}
535535
</xsl:if>
536536
</xsl:when>

modules/adb-tests/src/test/java/org/apache/axis2/schema/restriction/SchemaRestrictionTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void testLimitedStringParse2() throws Exception {
6565
LimitedStringE.Factory.parse(element.getXMLStreamReader());
6666
fail("This should throw RuntimeException");
6767
} catch (RuntimeException e) {
68-
assertEquals(toString(e), ERROR_MSG, e.getMessage());
68+
assertTrue(e.getMessage().contains(ERROR_MSG));
6969

7070
}
7171
}
@@ -79,7 +79,7 @@ public void testLimitedStringParse3() throws Exception {
7979
LimitedString.Factory.parse(element.getXMLStreamReader());
8080
fail("This should throw RuntimeException");
8181
} catch (RuntimeException e) {
82-
assertEquals(toString(e), ERROR_MSG, e.getMessage());
82+
assertTrue(e.getMessage().contains(ERROR_MSG));
8383

8484
}
8585
}
@@ -93,7 +93,7 @@ public void testLimitedStringParse4() throws Exception {
9393
LimitedString.Factory.parse(element.getXMLStreamReader());
9494
fail("This should throw RuntimeException");
9595
} catch (RuntimeException e) {
96-
assertEquals(toString(e), ERROR_MSG, e.getMessage());
96+
assertTrue(e.getMessage().contains(ERROR_MSG));
9797

9898
}
9999
}
@@ -107,7 +107,7 @@ public void testLimitedStringParse5() throws Exception {
107107
LimitedString.Factory.parse(element.getXMLStreamReader());
108108
fail("This should throw RuntimeException");
109109
} catch (RuntimeException e) {
110-
assertEquals(toString(e), ERROR_MSG, e.getMessage());
110+
assertTrue(e.getMessage().contains(ERROR_MSG));
111111

112112
}
113113
}
@@ -121,7 +121,7 @@ public void testLimitedStringParse6() throws Exception {
121121
LimitedString.Factory.parse(element.getXMLStreamReader());
122122
fail("This should throw RuntimeException");
123123
} catch (RuntimeException e) {
124-
assertEquals(toString(e), ERROR_MSG, e.getMessage());
124+
assertTrue(e.getMessage().contains(ERROR_MSG));
125125

126126
}
127127
}
@@ -143,7 +143,7 @@ public void testRatingParse2() throws Exception {
143143
Rating.Factory.parse(element.getXMLStreamReader());
144144
fail("This should throw RuntimeException");
145145
} catch (RuntimeException e) {
146-
assertEquals(toString(e), ERROR_MSG, e.getMessage());
146+
assertTrue(e.getMessage().contains(ERROR_MSG));
147147

148148
}
149149
}
@@ -157,7 +157,7 @@ public void testRatingParse3() throws Exception {
157157
Rating.Factory.parse(element.getXMLStreamReader());
158158
fail("This should throw RuntimeException");
159159
} catch (RuntimeException e) {
160-
assertEquals(toString(e), ERROR_MSG, e.getMessage());
160+
assertTrue(e.getMessage().contains(ERROR_MSG));
161161

162162
}
163163
}
@@ -171,7 +171,7 @@ public void testRatingParse4() throws Exception {
171171
Rating.Factory.parse(element.getXMLStreamReader());
172172
fail("This should throw RuntimeException");
173173
} catch (RuntimeException e) {
174-
assertEquals(toString(e), ERROR_MSG, e.getMessage());
174+
assertTrue(e.getMessage().contains(ERROR_MSG));
175175

176176
}
177177
}
@@ -185,7 +185,7 @@ public void testRatingParse5() throws Exception {
185185
Rating.Factory.parse(element.getXMLStreamReader());
186186
fail("This should throw RuntimeException");
187187
} catch (RuntimeException e) {
188-
assertEquals(toString(e), ERROR_MSG, e.getMessage());
188+
assertTrue(e.getMessage().contains(ERROR_MSG));
189189

190190
}
191191
}
@@ -199,7 +199,7 @@ public void testRatingParse6() throws Exception {
199199
Rating.Factory.parse(element.getXMLStreamReader());
200200
fail("This should throw RuntimeException");
201201
} catch (RuntimeException e) {
202-
assertEquals(toString(e), ERROR_MSG, e.getMessage());
202+
assertTrue(e.getMessage().contains(ERROR_MSG));
203203

204204
}
205205
}

0 commit comments

Comments
 (0)