Link to home
Start Free TrialLog in
Avatar of david_m_jacobson
david_m_jacobsonFlag for Afghanistan

asked on

An attempt was made to insert a node where it is not permitted

I am trying to add two new variables to a Java class that was originally created with a Spring framework.  I added the two variables and then I modified the mapping.xml file used for marshalling but I get the following error.  What am I missing?
org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted. 
org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted. 
	at org.apache.axiom.om.impl.dom.NodeImpl.insertBefore(NodeImpl.java:256)
	at org.apache.axiom.om.impl.dom.NodeImpl.appendChild(NodeImpl.java:235)
	at org.springframework.xml.dom.DomContentHandler.startElement(DomContentHandler.java:105)
	at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:1532)
	at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:836)
	at org.springframework.oxm.castor.CastorMarshaller.marshal(CastorMarshaller.java:359)
	at org.springframework.oxm.castor.CastorMarshaller.marshalSaxHandlers(CastorMarshaller.java:213)
	at org.springframework.oxm.castor.CastorMarshaller.marshalDomNode(CastorMarshaller.java:207)
	at org.springframework.oxm.AbstractMarshaller.marshalDomResult(AbstractMarshaller.java:190)
	at org.springframework.oxm.AbstractMarshaller.marshal(AbstractMarshaller.java:86)
	at org.springframework.ws.support.MarshallingUtils.marshal(MarshallingUtils.java:76)
	at org.springframework.ws.client.core.WebServiceTemplate$1.doWithMessage(WebServiceTemplate.java:259)
	at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:395)
	at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:256)
	at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:244)
	at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:236)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Venabili
Venabili
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of david_m_jacobson

ASKER

Venabili, thank you for the suggestions.  I am providing more info here...I added loginId and transactionKey variables to an AbstractCreditCardRequest class.  The values for the loginId and transactionKey were hardcoded in the file WEB-INF/spring-ws-servlet.xml.  I removed the two hardcoded values from WEB-INF/spring-ws-servlet.xml so that I could dynamically set these values in a CreditCardRequest object.  (Note that CreditCardRequest is inherited from AbstractCreditCardRequest.)

Then I added loginId and transactionKey to the following files:

- WEB-INF/creditcard.wsdl
- WEB-INF/CreditCardServices.xsd
- WEB-INF/classes/mapping.xml

Finally, note that I am running this using Tomcat.  I made the changes in Eclipse then created a new war file, deployed the war file in Tomcat and then ran the code.

Do you have any suggestions?  Do you see something wrong with the changes I made?
public abstract class AbstractCreditCardRequest {
	private int transactionId;
	private String loginId; //new field I just added
	private String transactionKey; ////new field I just added
 
//new getters and setters for the new variables
	public String getLoginId() {
		return loginId;
	}
 
	public void setLoginId(String loginId) {
		this.loginId = loginId;
	}
 
	public String getTransactionKey() {
		return transactionKey;
	}
 
	public void setTransactionKey(String transactionKey) {
		this.transactionKey = transactionKey;
	}
 
//changes to creditcard.wsdl
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="schemas:transactionId"/>
        <xs:element ref="schemas:loginId"/> <!--new element-->
        <xs:element ref="schemas:transactionKey"/> <!--new element-->
 
//changes to CreditCardServices.xsd
  <xs:element name="AuthorizeCreditCardRequest">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="schemas:transactionId"/>
        <xs:element ref="schemas:loginId"/> <!--new element-->
        <xs:element ref="schemas:transactionKey"/> <!--new element-->
 
//additional changes to CreditCardServices.xsd
  <xs:element name="loginId" type="xs:string"/>
  <xs:element name="transactionKey" type="xs:string"/>
 
//changes to WEB-INF/classes/mapping.xml
		<map-to xml="AuthorizeCreditCardRequest"/>
		<field name="transactionId" type="integer">
			<bind-xml name="transactionId" node="element"/>
		</field>
		<field name="loginId" type="java.lang.String">
			<bind-xml name="loginId" node="element"/>
		</field>
		<field name="transactionKey" type="java.lang.String">
			<bind-xml name="transactionKey" node="element"/>
		</field>

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Venabili,

I tried changing <field name="loginId" type="java.lang.String"> to <field name="loginId" type="string">.  That did not make a difference.

Then I compared the jar files in my local Tomcat/shared/lib to the jar files on another server.  I was using a later version of axis2.  I was using axis2-1.2 and the other server was using axis2-1.1.1.  For whatever reason, when I changed my axis2 jar files, this problem went away.  Hopefully this could be helpful to someone else in the future.
See my final comment.  The problem was solved by changing my axis2 jar files from version 1.2 to version 1.1.1.   Who knows.