[ https://issues.apache.org/jira/browse/AXIS2-5919?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16576378#comment-16576378 ]
Matheus Barbosa e Silva commented on AXIS2-5919: ------------------------------------------------ A possible workaround to this problem is to create a method that creates a QName and use string replacement to add a call to the method. The method to get the QName will look like this: {code:java} public static javax.xml.namespace.QName getQName(Object o, String localName) { String packageName = o.getClass().getPackage().getName(); String nsuri = javax.xml.XMLConstants.NULL_NS_URI; try { Class<?> packageInfoClass = Class.forName(packageName + ".package-info"); javax.xml.bind.annotation.XmlSchema xmlSchema = packageInfoClass.getAnnotation(javax.xml.bind.annotation.XmlSchema.class); if (xmlSchema != null) { nsuri = xmlSchema.namespace()); } } catch (ClassNotFoundException cnfe) { // log the exception or handle it } return new javax.xml.namespace.QName(nsuri, localName); }{code} This method checks for the {{package-info}} class to resolve the namespace uri for an object. If there is no {{package-info}} class, or the namespace qualifier is no present, the {{QName}} object is constructed using the constant {{XMLConstants.NULL_NS_URI}}. All the occurences of the code: {code:java} f.setDetail(toOM(e.getFaultMessage(),false)); {code} may be replaced with: {code:java} f.setDetail(toOM(e.getFaultMessage(), false, com.company.QNameResolver.getQName(e, (String) msgContext.getProperty(org.apache.axis2.Constants.FAULT_NAME)))); {code} To replace the string, one can use any technique such as Shell script, ANT, Gradle, etc... With ANT: {code:xml} <replace dir="${outputLocation}" value="f.setDetail(toOM(e.getFaultMessage(), false, com.company.QNameResolver.getQName(e, (String) msgContext.getProperty(org.apache.axis2.Constants.FAULT_NAME))));"> <include name="**/*MessageReceiver*.java"/> <replacetoken>f.setDetail(toOM(e.getFaultMessage(), false));</replacetoken> </replace> {code} With Gradle: {code:java} ant.replace(token: 'f.setDetail(toOM(e.getFaultMessage(),false));', value: 'f.setDetail(toOM(e.getFaultMessage(), false, com.company.QNameResolver.getQName(e, (String) msgContext.getProperty(org.apache.axis2.Constants.FAULT_NAME))));') { fileset(dir: "$buildDir", includes: '**/*MessageReceiver*.java') } {code} The replacement must be done after generating the server side code with WSLD2Java tool. > WSDL2Java not working properly when using jaxbri and WSDL with faults > --------------------------------------------------------------------- > > Key: AXIS2-5919 > URL: https://issues.apache.org/jira/browse/AXIS2-5919 > Project: Axis2 > Issue Type: Bug > Components: codegen, databinding > Affects Versions: 1.7.7, 1.7.8 > Reporter: Edi Obradovic > Priority: Blocker > Labels: codegen, jaxbri, wsdl2java > > We are currently unable to use newer version of Axis2 (1.7.7) because the > Java classes generated by axis2-codegen and axis2-jaxbri have missing > parameter errors. > When you generate Java classes from WSDL that contains faults you get errors > in the newly generated classes: "The method toOM(TestFaultStruct, boolean, > QName) in the type <class> is not applicable for the arguments > (TestFaultStruct, boolean)". The reason you get that is because the QName > parameter is missing when calling toOM in faults. > *The error happens because:* > - all toOM methods code is generated using JaxbRIDatabindingTemplate.xsl > (axis2-jaxbri) and they all have QName parameter defined > - all custom faults code is generated using MessageReceiverTemplate.xsl > (axis2-codegen) and if you look at the xsl code you can see that QName > parameter is not there: > {code:xml} > <xsl:for-each select="fault-list/fault"> > <xsl:if test="position()=1">}</xsl:if> catch (<xsl:value-of > select="@name"/> e) { > > msgContext.setProperty(org.apache.axis2.Constants.FAULT_NAME,"<xsl:value-of > select="@localname"/>"); > org.apache.axis2.AxisFault f = createAxisFault(e); > if (e.getFaultMessage() != null){ > f.setDetail(toOM(e.getFaultMessage(),false)); > } > throw f; > } > </xsl:for-each> > {code} > > *How to reproduce:* > - Download and extract axis2-1.7.7 > - Execute WSDL2Java: > {code:java} > java -Dfile.encoding=UTF-8 -Djavax.xml.accessExternalSchema=all -classpath > "c:\DevStudio\axis2-1.7.7\lib\*;" org.apache.axis2.wsdl.WSDL2Java -uri > "c:\DevStudio\axis2-1.7.7\samples\faulthandling\bank.wsdl" -o "%CD%\GEN" -d > jaxbri -ss -g -or -p com.company.generated > {code} > - Compile code (eclipse/ant ...) > {code:java} > Buildfile: C:\TEMP\Test\GEN\build.xml > init: > [mkdir] Created dir: C:\TEMP\Test\GEN\build > [mkdir] Created dir: C:\TEMP\Test\GEN\build\classes > [mkdir] Created dir: C:\TEMP\Test\GEN\build\lib > pre.compile.test: > [echo] JAX-B RI Availability = true > [echo] Stax Availability= true > [echo] Axis2 Availability= true > compile.src: > [javac] C:\TEMP\Test\GEN\build.xml:47: warning: 'includeantruntime' was > not set, defaulting to build.sysclasspat > h=last; set to false for repeatable builds > [javac] Compiling 12 source files to C:\TEMP\Test\GEN\build\classes > [javac] > C:\TEMP\Test\GEN\src\com\company\generated\BankServiceMessageReceiverInOut.java:89: > error: no suitable m > ethod found for toOM(AccountNotExistFault,boolean) > [javac] f.setDetail(toOM(e.getFaultMessage(), false)); > [javac] ^ > [javac] method > BankServiceMessageReceiverInOut.toOM(InsufficientFundFault,boolean,QName) is > not applicable > [javac] (actual and formal argument lists differ in length) > [javac] method > BankServiceMessageReceiverInOut.toOM(AccountNotExistFault,boolean,QName) is > not applicable > [javac] (actual and formal argument lists differ in length) > [javac] method > BankServiceMessageReceiverInOut.toOM(WithdrawResponse,boolean,QName) is not > applicable > [javac] (actual and formal argument lists differ in length) > [javac] method > BankServiceMessageReceiverInOut.toOM(Withdraw,boolean,QName) is not applicable > [javac] (actual and formal argument lists differ in length) > [javac] > C:\TEMP\Test\GEN\src\com\company\generated\BankServiceMessageReceiverInOut.java:100: > error: no suitable > method found for toOM(InsufficientFundFault,boolean) > [javac] f.setDetail(toOM(e.getFaultMessage(), false)); > [javac] ^ > [javac] method > BankServiceMessageReceiverInOut.toOM(InsufficientFundFault,boolean,QName) is > not applicable > [javac] (actual and formal argument lists differ in length) > [javac] method > BankServiceMessageReceiverInOut.toOM(AccountNotExistFault,boolean,QName) is > not applicable > [javac] (actual and formal argument lists differ in length) > [javac] method > BankServiceMessageReceiverInOut.toOM(WithdrawResponse,boolean,QName) is not > applicable > [javac] (actual and formal argument lists differ in length) > [javac] method > BankServiceMessageReceiverInOut.toOM(Withdraw,boolean,QName) is not applicable > [javac] (actual and formal argument lists differ in length) > [javac] Note: Some input files use unchecked or unsafe operations. > [javac] Note: Recompile with -Xlint:unchecked for details. > [javac] 2 errors > BUILD FAILED > C:\TEMP\Test\GEN\build.xml:47: Compile failed; see the compiler error output > for details. > Total time: 2 seconds > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005) --------------------------------------------------------------------- To unsubscribe, e-mail: java-dev-unsubscr...@axis.apache.org For additional commands, e-mail: java-dev-h...@axis.apache.org