OTRS: error generating Java SEI with wsdl

后端 未结 1 1002
抹茶落季
抹茶落季 2021-01-17 03:30

Windows 7, Java 7 OTRS appliannce.\"enter

I am trying to use wsimport to generate Java

1条回答
  •  北海茫月
    2021-01-17 03:57

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

    2. 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.

    My working codes are here,

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

    links I referred are:

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

    0 讨论(0)
提交回复
热议问题