Hi all,

I am having a problem when returning an array of errors on my Web
Service. I need to return more than one error for the client, my
service is supposed to receive a lot of info, and I don't want to halt
execution if one or more items are incorrect, I want to proccess the
correct ones and then return a list of errors occurred as an array of
String. What I am doing is:

I am using CXF 2.1 with JAXB and I have an annotated WebFault class
that extends a simple class of mine (WSException) and this class
extends Exception. WebFault-->WSException-->Exception

Inside my WSException I have a MensagemErro class that is my faultInfo
attribute.

This class is a JAXB annotated class with
@XmlAccessorType(XmlAccessType.FIELD) and @XmlType(name =
"mensagemErro") annotations.

Inside this class I have two attribbutes, a simple error String and an
array of Strings called erros.

So what's happening is that even when this array is populated with
only one String, on the client side this array is being parsed and
every word is considered one element of the array.

Suppose I have a String "Validation Error Occurred" as position 0 on
my array (erros[0] = "Validation Error Occurred") on the server side,
on the client side I get a String with 3 positions
erros[0]="Validation", erros[1]="Error" and erros[2]="Occured" as an
attribute of my faultInfo.

My classes:

@WebFault(name="AtualizaTeseDissertacaoFault")
public class AtualizaTeseDissertacaoFault extends WSException {

    public AtualizaTeseDissertacaoFault(String message, MensagemErro
faultInfo, Throwable cause) {
        super(message, faultInfo, cause);
    }

    public AtualizaTeseDissertacaoFault(String message, MensagemErro
faultInfo) {
        super(message, faultInfo);
    }

}


public abstract class WSException extends Exception {

    MensagemErro faultInfo;

    public WSException(String message, MensagemErro faultInfo) {
        super(message);
        this.faultInfo = faultInfo;
    }

    public WSException(String message, MensagemErro faultInfo,
            Throwable cause) {
        super(message, cause);
        this.faultInfo = faultInfo;
    }

    public MensagemErro getFaultInfo() {
        return faultInfo;
    }
}


@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "mensagemErro")
public class MensagemErro {

    public MensagemErro() {
        super();
    }

    public MensagemErro(String erro) {
        super();
        this.erro = erro;
    }

    public MensagemErro(String[] erros) {
        super();
        this.erros = erros;
    }

    @XmlAttribute
    protected String erro;

    @XmlAttribute
    protected String[] erros = new String[]{};

    public String getErro() {
        return erro;
    }

    public void setErro(String erro) {
        this.erro = erro;
    }

    public String[] getErros() {
        return erros;
    }

    public void setErros(String[] erros) {
        this.erros = erros;
    }

}


What happens is the erros attribute is being parsed incorrectly.

Reply via email to