0

I've seen questions like this but so far they don't help.

I'm currently having an issue setting a prefix for an element within my SOAP body. The request I'm trying to build looks like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sen="http://company.org/sendmailaTTACH">
   <soapenv:Header/>
   <soapenv:Body>
      <sen:SendMail>
         <sen:plainbody>?</sen:plainbody>
      </sen:SendMail>
   </soapenv:Body>
</soapenv:Envelope>

Was able to build it to the point of the SendMail object by following this answer, but when it gets to the part of adding the prefix: <sen:plainbody> i.e adding the sen prefix to plainbody I get the error:

org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.

The SendMail object looks like this:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(
        name = "",
        propOrder = {"from", "displayname", "to", "cc", "bcc", "htmlbody", "plainbody", "subject", "imageurl"}
)
@XmlRootElement(
        name = "SendMail"
)
public class SendMail {
    protected String from;
    protected String displayname;
    protected String to;
    protected String cc;
    protected String bcc;
    protected String htmlbody;
    protected String plainbody;
    protected String subject;
    protected String imageurl;

    public SendMail() {
    }
.
.
.
//getters and setters

I'm guessing maybe it's because the plainbody and other fields there are String?

Is there any way around this?

Thank you!

Ayo K
  • 1,719
  • 2
  • 22
  • 34

1 Answers1

0

Figured out a solution:

Was able to work around it by annotating the class properties with @XmlElement and specifying the namespace

@XmlElement(namespace = "http://company.org/sendmailaTTACH")
protected String from;

@XmlElement(namespace = "http://company.org/sendmailaTTACH")
protected String displayname;

@XmlElement(namespace = "http://company.org/sendmailaTTACH")
protected String to;

@XmlElement(namespace = "http://company.org/sendmailaTTACH")
protected String cc;

@XmlElement(namespace = "http://company.org/sendmailaTTACH")
protected String bcc;

@XmlElement(namespace = "http://company.org/sendmailaTTACH")
protected String htmlbody;

@XmlElement(namespace = "http://company.org/sendmailaTTACH")
protected String plainbody;

@XmlElement(namespace = "http://company.org/sendmailaTTACH")
protected String subject;

@XmlElement(namespace = "http://company.org/sendmailaTTACH")
protected String imageurl;
Ayo K
  • 1,719
  • 2
  • 22
  • 34