Search code examples
javasoapwsdlotrs

OTRS: error generating Java SEI with wsdl


Windows 7, Java 7 OTRS appliannce.enter image description here

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.

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/">

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

Thank you.


Solution

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