1

我正在尝试使用以下代码调用 Web 服务:

/* 
 * A sample Java code for the Termine Web Service.
 */

import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.rpc.*;
import javax.xml.rpc.encoding.XMLType;

public class termine
{

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

    String sentence = "Technical terms are important for knowledge mining, especially in the bio-medical area where vast amount of documents are available.";

    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);

    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, "wrapped");
      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[] {sentence, "", "xml", "", ""};

      call.setReturnType(XMLType.XSD_STRING);

      System.out.println(call.invoke(inParams));
    }
    catch (Exception e) {e.printStackTrace();} 
  }
}

但是,我收到以下错误。

javax.xml.rpc.ServiceException:在 javax.xml.rpc.FactoryFinder.find( FactoryFinder.java:137) 在 javax.xml.rpc.ServiceFactory.newInstance(ServiceFactory.java:58) 在 com.ivita.termExtraction.termine.main(termine.java:31)

通过在网上阅读有关类似问题的信息,我得到的印象是我没有使用正确的库。在我的 pom.xml 中,我提供了以下依赖项:

<dependency>
    <groupId>javax.xml</groupId>
    <artifactId>jaxrpc-api</artifactId>
    <version>1.1</version>
</dependency>
<dependency>
    <groupId>org.apache.axis</groupId>
    <artifactId>axis-jaxrpc</artifactId>
    <version>1.4</version>
</dependency>
<dependency>
    <groupId>xerces</groupId>
    <artifactId>xercesImpl</artifactId>
    <version>2.11.0</version>
</dependency>

你能帮我解决这个问题吗?谢谢!

4

1 回答 1

1

将以下依赖项添加到我的 pom.xml 解决了问题(部分原因是其他依赖项似乎仍然缺失)。

<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4</version>
</dependency>
于 2013-06-09T12:05:50.453 回答