views:

83

answers:

1

Am trying to invoke a public web-service using a java client but am getting the following exception:

deserialization error: XML reader error: unexpected character content: "<?xml version="1.0" ?>
<rankedTermCandidates 
  xmlns="http://www.nactem.ac.uk/xsd/termine" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://www.nactem.ac.uk/xsd/termine http://www.nactem.ac.uk/software/termine/webservice/termine.xsd" 
  >

Am not able to find out what I am doing wrong. Am tempted to move to a .NET client{am a c# programmer} but would like to know what I am doing wrong here.

The method calling the webservice is :

    private String InvokeNactemWebService(String textToParse) throws Exception
{

String wsdlURL = "http://www.nactem.ac.uk/software/termine/webservice/termine.wsdl";
URL url = new URL(wsdlURL);
String targetNamespace = "urn:termine";
String   serviceName = "termine";
String      portName = "termine_porttype";
String operationName = "analyze";
QName    serviceQN   = new QName(targetNamespace, serviceName);
QName       portQN   = new QName(targetNamespace, portName);
QName  operationQN   = new QName(targetNamespace, operationName);

String parseResult = "";

try
{
      ServiceFactory serviceFactory = ServiceFactory.newInstance();
      Service service = serviceFactory.createService(url, serviceQN);

      Call call = (Call) service.createCall();
      call.setProperty(Call.ENCODINGSTYLE_URI_PROPERTY, "");
      call.setProperty(Call.OPERATION_STYLE_PROPERTY, "rpc");
      call.setTargetEndpointAddress("http://www.nactem.ac.uk:9000/termine");


      call.setPortTypeName(portQN);
      call.setOperationName(operationQN);

      call.removeAllParameters();
      call.addParameter("src",           XMLType.XSD_STRING, ParameterMode.IN);
      call.addParameter("input_format",  XMLType.XSD_STRING, ParameterMode.IN);
      call.addParameter("output_format", XMLType.XSD_STRING, ParameterMode.IN);
      call.addParameter("stoplist",      XMLType.XSD_STRING, ParameterMode.IN);
      call.addParameter("filter",        XMLType.XSD_STRING, ParameterMode.IN);


      Object[] inParams = new Object[] {textToParse, "", "xml", "", ""};

      Object result = call.invoke(inParams);
      //parseResult = (String) call.invoke(inParams);
      //System.out.println(call.invoke(inParams));
      return parseResult;
    }
    catch (Exception e)
    {
        e.printStackTrace();
        Debug.println(e.getMessage(), e.getStackTrace().toString());
    }

    return parseResult;

}
+1  A: 

I suspect there's a byte-order-mark in your XML response. See this SO question for further details. Capturing the response using Wireshark or similar will indicate what's going on.

If you do have a BOM, I suspect you can install a servlet filter to intercept the response before the webservice XML parsing code, and remove the BOM from the raw response before passing it forward.

Brian Agnew
Thanks Brian! Thats correct. The following is the exception stacktrace:<?xml version="1.0" ?> But am not able to find how the BOM can be removed from the response. Specifically, I would like to do the following: (call.invoke(inParams)).RemveBOM(); Is there a quick way to do this in Java? The link you mentioned shows the workaround for a .NET client.
Codex
See my amended answer.
Brian Agnew
That makes sense! Will try it out. Thanks.
Codex