本文介绍了OTRS:使用wsdl生成Java SEI时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows 7,Java 7OTRS应用程序.

Windows 7, Java 7OTRS appliannce.

我正在尝试使用wsimport从 https://raw.githubusercontent.com/OTRS/otrs/master/development/webservices/GenericTicketConnectorSOAP.wsdl

I am trying to use wsimport to generate Java SEI with the wsdl file from https://raw.githubusercontent.com/OTRS/otrs/master/development/webservices/GenericTicketConnectorSOAP.wsdl

我从命令提示符处尝试(以管理员身份运行),但它给了我错误(请参阅附件),并且没有生成任何东西.

I tried from command prompt (run as admin) and it gave me errors (see attachment) and did not generate anything.

我也尝试使用Netbeans8.我从wsdl文件中选择了创建Web服务,但它抱怨找不到服务或端口.然后,我验证了wsdl文件,它找不到该元素的声明xmlns:tns ="http://www.otrs.org/TicketConnector/">

I also tried using Netbeans 8. I select create web service from wsdl file and it complains cannot find service nor port. I then validated the wsdl file, it cannot find declaration of this element, xmlns:tns="http://www.otrs.org/TicketConnector/">

我应该如何生成SEI以与Java中的OTRS对话?

How am I supposed to generate SEI to talk to OTRS in Java?

谢谢.

推荐答案

我在这里发布我的解决方案给那些有兴趣从Java创建OTRS票证的人.我希望有更多关于从Java访问OTRS的文档.

I am posting my solution here for anyone who is interested in creating OTRS tickets from Java. I wish there is more documentation about accessing OTRS from Java.

  1. 无法从wsdl生成Java存根类.我无法在任何地方找到任何解决方案,也无法从这里的任何人或OTRS论坛-forums.otterhub.org听到任何回音. (Google OTRS论坛不会发布我的问题.)

  1. Generating Java stub classes from wsdl is not possible. I cannot find any solution anywhere nor do I hear anything back from anyone here nor OTRS forums - forums.otterhub.org. (Google OTRS group wouldn't post my question.)

要访问OTRS Web服务,您将必须使用SOAP.我首先在otrs服务器上运行SOAPRequest.pl,以弄清所有内容,然后从那里恢复工作.在这两者之间,我还遇到了将名称空间uri链接到本地​​名称的问题.

To access OTRS webservice, you will have to use SOAP. I first run SOAPRequest.pl on otrs server to get everything figured out then worked back from there. In between, I also suffered from linking namespace uri to local name problem.

我的工作代码在这里,

try {
    SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
    SOAPConnection conn = scf.createConnection();
    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage msg = mf.createMessage();
    SOAPPart sp = msg.getSOAPPart();

    SOAPEnvelope env = sp.getEnvelope();
    env.addNamespaceDeclaration("tns", "http://www.otrs.org/TicketConnector/");
    SOAPBody body = env.getBody();
    SOAPBodyElement dispatch = body.addBodyElement(new QName("http://www.otrs.org/TicketConnector/", "TicketCreate", "tns"));
    dispatch.addChildElement(new QName("http://www.otrs.org/TicketConnector/", "UserLogin", "tns")).addTextNode("some user login");
    dispatch.addChildElement(new QName("http://www.otrs.org/TicketConnector/", "Password", "tns")).addTextNode("some user password");

    SOAPElement tkt = dispatch.addChildElement(new QName("http://www.otrs.org/TicketConnector/", "Ticket", "tns"));
    tkt.addChildElement(new QName("http://www.otrs.org/TicketConnector/", "Title", "tns")).addTextNode("some title");
    tkt.addChildElement(new QName("http://www.otrs.org/TicketConnector/", "Queue", "tns")).addTextNode("one of your queue names");
    tkt.addChildElement(new QName("http://www.otrs.org/TicketConnector/", "Type", "tns")).addTextNode("one of your types");
    tkt.addChildElement(new QName("http://www.otrs.org/TicketConnector/", "CustomerUser", "tns")).addTextNode("some email address not customer id/name/username. Thought this could be my sys config");
    tkt.addChildElement(new QName("http://www.otrs.org/TicketConnector/", "State", "tns")).addTextNode("one of your states");
    tkt.addChildElement(new QName("http://www.otrs.org/TicketConnector/", "Priority", "tns")).addTextNode("one of your priorities");

    SOAPElement article = dispatch.addChildElement(new QName("http://www.otrs.org/TicketConnector/", "Article", "tns"));
    article.addChildElement(new QName("http://www.otrs.org/TicketConnector/", "Subject", "tns")).addTextNode("some subject");
    article.addChildElement(new QName("http://www.otrs.org/TicketConnector/", "Body", "tns")).addTextNode("some body");
    article.addChildElement(new QName("http://www.otrs.org/TicketConnector/", "ContentType", "tns")).addTextNode("text/plain; charset=utf8");

    SOAPElement dynamicField = dispatch.addChildElement(new QName("http://www.otrs.org/TicketConnector/", "DynamicField", "tns"));
    dynamicField.addChildElement(new QName("http://www.otrs.org/TicketConnector/", "Name", "tns")).addTextNode("one of your dynamic field");
    dynamicField.addChildElement(new QName("http://www.otrs.org/TicketConnector/", "Value", "tns")).addTextNode("your dynamic field value");

    dispatch.addChildElement(tkt);
    dispatch.addChildElement(article);
    dispatch.addChildElement(dynamicField);

    /* Print the request message */
    System.out.print("Request SOAP Message:");
    msg.writeTo(System.out);
    System.out.println();
    URL url = new URL("http://your otrs ip address/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorSOAP");
    SOAPMessage resp = conn.call(msg, url);
    resp.writeTo(System.out);
    System.out.println();
    } catch (SOAPException | UnsupportedOperationException | IOException e) {
        e.printStackTrace();
    }

我引用的链接是:

  • https://github.com/OTRS/otrs/tree/master/development/webservices (Perl script)
  • https://github.com/gtudan/OTRS-Client (Access OTRA via Java SOAP)
  • http://sastriawan.blogspot.com/2010/01/using-javaxxmlsoap-to-access-otrs-soap.html (Access OTRA via Java SOAP)
  • SOAP message with javax.xml.soap - namespace error?(namespace binding)

这篇关于OTRS:使用wsdl生成Java SEI时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 23:20