Announcement Announcement Module
Collapse
No announcement yet.
XPath evaluation issues Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • XPath evaluation issues

    I have a AbstractDomPayloadEndpoint that uses jaxp XPath to get info out of the passed in element. I have unit tests that pass in a Element that was created from a sample xml file that works fine, but as soon as I deploy to tomcat the XPath evaluations always return empty values. Relevant code snippets are below:

    Endpoint code:

    Code:
    @Override
    	protected Element invokeInternal(Element element, Document document)
    			throws Exception {
    
    		XPath xpath = XPathFactory.newInstance().newXPath();
    		xpath.setNamespaceContext(new MyNamespaceContext());
    		String expression = "/dep:UploadRequest/dep:CompanyName";
    		
    		String companyName = (String) xpath.evaluate(expression, element, XPathConstants.STRING);
    		
    //    companyName is empty in acceptance test(when hitting tomcat), but works fine in unit tests!
    		logger.debug("Company name: " + companyName);
    		
    		return null;
    	}
    
    private class MyNamespaceContext implements NamespaceContext {
    	    public String getNamespaceURI(String prefix) {
    	    	
    	    	if (prefix == null) throw new NullPointerException("Null prefix");
    	        else if ("dep".equals(prefix))
    	        	return "http://virtualmobiletech.com/DeploymentApp/schemas";
    	        else if ("xml".equals(prefix)) return XMLConstants.XML_NS_URI;
    	        return XMLConstants.NULL_NS_URI;
    	    }
    
    	    // This method isn't necessary for XPath processing.
    	    public String getPrefix(String uri) {
    	        throw new UnsupportedOperationException();
    	    }
    
    	    // This method isn't necessary for XPath processing either.
    	    public Iterator<Object> getPrefixes(String uri) {
    	        throw new UnsupportedOperationException();
    	    }
    	}

    The xml file being used to generate the element for the unit tests that passes looks as follows:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <UploadRequest xmlns="http://virtualmobiletech.com/DeploymentApp/schemas">
    	  <Credentials>
    		<User>Carl</User>
    		<Password>123456</Password>
    	  </Credentials>
    	  
    	  <CompanyName>viewfines</CompanyName>
    	  
    	  <ApplicationId>vflive</ApplicationId>
    	
    	  <ApplicationVersion>
    		  <Major>1</Major>
    		  <Minor>0</Minor>
    	  </ApplicationVersion>
    		
    		<Devices>
    		   <Device brand="Siemens" model="CL75"/>
    		   <Device brand="Nokia" model="E61"/>
    		</Devices>
    		
    		
    		<CapabilityGroups>
    		   <CapabilityGroup>MIDP1.0</CapabilityGroup>
    		   <CapabilityGroup>hasPointer</CapabilityGroup>
    		</CapabilityGroups>
    		
    		<MetaData>VGhpcyBpcyBteSBqYWQgZmlsZSE=</MetaData>
    	
    		<BinData>VGhpcyBpcyBteSBqYXIgZmlsZSwgd29vaG9vIQ==</BinData>
    	  
    </UploadRequest>
    The request that is being passed in for the acceptance test and that fails looks as follows:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <soap:Envelope xmlns:soap="">
      <soap:Body>
    	<UploadRequest xmlns="http://virtualmobiletech.com/DeploymentApp/schemas">
    	  <Credentials>
    		<User>Carl</User>
    		<Password>123456</Password>
    	  </Credentials>
    	  
    	  <CompanyName>1time</CompanyName>
    	  
    	  <ApplicationId>1time</ApplicationId>
    	
    	  <ApplicationVersion>
    		  <Major>1</Major>
    		  <Minor>21</Minor>
    	  </ApplicationVersion>
    		
    		<Devices>
    		   <Device brand="Siemens" model="CL75"/>
    		   <Device brand="Nokia" model="E61"/>
    		</Devices>
    		
    		
    		<CapabilityGroups>
    		   <CapabilityGroup>MIDP1.0</CapabilityGroup>
    		   <CapabilityGroup>hasPointer</CapabilityGroup>
    		</CapabilityGroups>
    		
    		<MetaData>TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz
    	IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg
    	dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu
    	dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo
    	ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=
    	</MetaData>
    	
    		<BinData>TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz
    	IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg
    	dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu
    	dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo
    	ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=
    	</BinData>
    	  
    	</UploadRequest>
    
      </soap:Body>
    </soap:Envelope>

    The only difference that I could see is that for the unit test org.apache.xpath.jaxp.XPathImpl is the class returned by XPathFactory.newInstance().newXPath() and when in tomcat com.sun.org.apache.xpath.internal.jaxp.XPathImpl is returned!

    Anyone got any idea?

  • #2
    Also when I navigate the element using the W3C api of the element I can get all the elements and their data. It is only when using XPath that the empty string is returned.

    Another difference that I have noticed is that in the unit test the passed in Element is of class type org.apache.xerces.dom.DeferredElementNSImpl and for acceptance test in tomcat it is com.sun.xml.internal.messaging.saaj.soap.ver1_1.Bo dyElement1_1Impl

    The following works in both the acceptance test and the unit test:

    Code:
    NodeList nodeList = element.getChildNodes();
    	    
    		for(int i = 0; i < nodeList.getLength();i++)
    		{
    			Node node = nodeList.item(i);
    			
    			if(node.getNodeName().equals("CompanyName"))
    				logger.debug("Company name dom API: " + node.getTextContent());
    		}
    Last edited by symfrog; Feb 9th, 2009, 11:44 PM.

    Comment


    • #3
      I also generated a sample message from the WSDL generated by Spring WS using soapUI and got the same problem

      Comment

      Working...
      X