0

I'm fairly new to using SOAP and Blueprint (Which is just like Spring). Anyway, I'm just trying to learn the basics atm, doing pretty well so far.

I've run into a small problem when using a Java Class to retrieve a specific node value from an XML file. This works when I run the application as a stand-alone but when I am getting the request using Soap, the value "lastName" returns null.

public static void main(String[] args) throws XPathExpressionException {

    DocumentBuilderFactory builderFactory =
            DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = null;
    try {
        builder = builderFactory.newDocumentBuilder();
    } catch (ParserConfigurationException p) {
        p.printStackTrace();
    }
    try {
    Document document = builder.parse(new FileInputStream("d:\\input11.xml")); 
    XPath xP = XPathFactory.newInstance().newXPath();
    String expression ="/people/person/lastName";
    NodeList nodeList = (NodeList) xP.compile(expression).evaluate(document, XPathConstants.NODESET);
    for (int i = 0; i < nodeList.getLength(); i++) {
        lastName += nodeList.item(i).getFirstChild().getNodeValue() + " ";
    }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (SAXException s) {
        s.printStackTrace();
    }

    System.out.println(lastName);
}

public static String returnLastName(String input){
System.out.println(lastName);

return "LastName: "+lastName +"\n";

} 

}

And here's my blueprint.xml code:

    <bean id="lastNameBean" class="com.*****.camelBlueprintTest.XMLCamel" />
    <route id="lastName">
<from uri="cxf:bean:returnLName" />
<bean ref="lastNameBean" method="returnLastName" />
    <log message="The message contains ${body}" />
    <to uri="mock:result" />
</route>

So it does actually return the last names when I run the Java application, but in the SOAP request I am getting "LastName: null".

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Tuss
  • 57
  • 1
  • 9

1 Answers1

0

AH!! I've found the error. Silly me. So, I was calling the method in my blueprint "returnLastName" and it was returning null, I didn't realize that this method was called ALONE, so moving my code from the main into the method fixed it like a charm haha.

I feel really silly but it's always the little mistakes that get me.

Tuss
  • 57
  • 1
  • 9