javax.xml.stream.XMLStreamException : ParseError at [row,col]:[x,xx]

Problem

Created a JAX-WS handler to inject a mac address into the client side SOAP request header automatically :

File : MacAddressInjectHandler.java


public class MacAddressInjectHandler implements SOAPHandler<SOAPMessageContext>{

   @Override
   public boolean handleMessage(SOAPMessageContext context) {

	//......
	//get mac address
	String mac = getMACAddress();
		
	//add a soap header, name as "mac address"
	QName qname = new QName("http://ws.mkyong.com/", "mac address");
	SOAPHeaderElement soapHeaderElement = soapHeader.addHeaderElement(qname);

	soapHeaderElement.setActor(SOAPConstants.URI_SOAP_ACTOR_NEXT);
	soapHeaderElement.addTextNode(mac);
	soapMsg.saveChanges();
        //......
	          
   }
   //......
}

When SOAP message is generated and sent to service’s provider (or server), it return the following error message immediately :


com.sun.xml.internal.ws.streaming.XMLStreamReaderException: 
   XML reader error: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,110]
   Message: Attribute name "address" associated with 
   an element type "mac" must be followed by the ' = ' character.
   //...
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,110]
   Message: Attribute name "address" associated with an element type 
   "mac" must be followed by the ' = ' character.
   //...

Solution

The XMLStreamException is saying that you’re trying to send an invalid SOAP message that contains invalid format. From SOAP client above, you may generate similar SOAP message as following :


<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Header>
	<mac address xmlns="http://ws.mkyong.com/" 
		xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
		SOAP-ENV:actor="http://schemas.xmlsoap.org/soap/actor/next">
			90-4C-E5-44-B9-8F
	</mac address>
  </S:Header>
  <S:Body>
	<ns2:getServerName xmlns:ns2="http://ws.mkyong.com/"/>
  </S:Body>
</S:Envelop

And notice the “mac address” attribute? The “space” in between is causing the “address” became an attribute for “mac” element.

To fix it, just delete the spaces like this :


QName qname = new QName("http://ws.mkyong.com/", "macaddress");

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
0 Comment authors
javax.xml.stream.XMLStreamException : ParseError at [row,col]:[x,xx] Recent comment authors
newest oldest most voted
trackback
javax.xml.stream.XMLStreamException : ParseError at [row,col]:[x,xx]

[…] class MacAddressInjectHandler implements SOAPHandler<SOAPMessageContext>{  … [full post] mkyong Mkyong Dot Com jax-wsweb services 0 0 0 0 0 […]