/**
*
* Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**/
package org.servicemix.components.jaxws;
import javax.xml.namespace.QName;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import org.servicemix.TestSupport;
import org.servicemix.jbi.util.DOMUtil;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.traversal.NodeIterator;
import org.xbean.spring.context.ClassPathXmlApplicationContext;
import com.sun.org.apache.xpath.internal.CachedXPathAPI;
/**
* @version $Revision: 680 $
*/
public class JAXWSInTest extends TestSupport {
protected String quote = "SUNW";
public void testJAXWSService() throws Exception {
QName serviceName = new QName("http://jaxws.components.servicemix.org/", "AddNumbersService");
String file = "requestWithEnvelope.xml";
Object answer = requestServiceWithFileRequest(serviceName, file);
assertTrue("Shoud return a DOM Node: " + answer, answer instanceof Node);
Node node = (Node) answer;
System.out.println(transformer.toString(node));
String text = textValueOfXPath(node, "//return").trim();
System.out.println("Result: " + text);
assertTrue("Result text should not be empty", text.length() > 0);
}
protected AbstractXmlApplicationContext createBeanFactory() {
return new ClassPathXmlApplicationContext("org/servicemix/components/jaxws/jaxws-in.xml");
}
protected String textValueOfXPath(Node node, String xpath) throws TransformerException {
CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, xpath);
Node root = iterator.nextNode();
if (root instanceof Element) {
Element element = (Element) root;
if (element == null) {
return "";
}
String text = DOMUtil.getElementText(element);
return text;
}
else {
return root.getNodeValue();
}
}
}