views:

125

answers:

2

Similarly to an older post I'm trying to access a web service with JAX-WS using:

Dispatch<Source> sourceDispatch = null;
sourceDispatch = service.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD);
Source result = sourceDispatch.invoke(new StreamSource(new StringReader(req)));
System.out.println(sourceToXML(result));

where:

private static String sourceToXML(Source result) {
    Node rootNode= null;
    try {
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer();
        DOMResult domResult = new DOMResult();
        transformer.transform(result, domResult );
        rootNode = (Node) domResult.getNode();
  } catch (TransformerException e) {
        e.getMessage();
  }

    return rootNode.getFirstChild().getNodeValue();
}

but I get the error 'The current event is not START_ELEMENT null but 2' (I think on the transformer)

What am I doing wrong :(

A: 

Presumably from the parser. I would say a stack trace would be helpful, but Xerces/Xalan has a tendency for screwing those up.

Obvious steps to take:

  • Try looking at the result as a string.
  • Try parsing with a parser, ignoring the transformer for now.
  • Try finding out exactly what the error was.
Tom Hawtin - tackline
The stack trace: http://collabedit.com/display?id=44647
A: 

You should amend your statement

e.getMessage()

to actually print the error message :-) That should help.

System.err.println(e.getMessage());

or preferably

e.printStackTrace();
Brian Agnew
Or better throw new Error(exc);
Tom Hawtin - tackline
The stack trace: http://collabedit.com/display?id=44647