Windows 7,Java 7
OTRS的功能。

我正在尝试使用wsimport与https://raw.githubusercontent.com/OTRS/otrs/master/development/webservices/GenericTicketConnectorSOAP.wsdl中的wsdl文件生成Java SEI

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

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

我应该如何生成SEI以使用Java与OTRS对话?

谢谢。

最佳答案

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


无法从wsdl生成Java存根类。我在任何地方都找不到任何解决方案,也无法从这里的任何人或OTRS论坛-forums.otterhub.org听到任何回音。 (Google OTRS论坛不会发布我的问题。)
要访问OTRS Web服务,您将必须使用SOAP。我首先在otrs服务器上运行SOAPRequest.pl,以弄清所有内容,然后从那里恢复工作。在这两者之间,我还遇到了将名称空间uri链接到本地​​名称的问题。


我的工作代码在这里,

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脚本)
https://github.com/gtudan/OTRS-Client(通过Java SOAP访问OTRA)
http://sastriawan.blogspot.com/2010/01/using-javaxxmlsoap-to-access-otrs-soap.html(通过Java SOAP访问OTRA)
SOAP message with javax.xml.soap - namespace error?(命名空间绑定)

10-06 14:52