Java sample


Creating an Issue

import javax.xml.soap.*;

public class CreateIssue

{

    public static void main( String[] args )

    {

        try

        {

            // Comment this out for NO proxy.

            java.util.Properties props = System.getProperties();

            props.put( "http.proxyHost", "localhost" );

            props.put( "http.proxyPort", "8888" );

            // Setup SOAP message.

            SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();

            SOAPConnection connection = scf.createConnection();

            MessageFactory msgFactory = MessageFactory.newInstance();

            SOAPMessage msg = msgFactory.createMessage();

            SOAPEnvelope env = msg.getSOAPPart().getEnvelope();

            env.addNamespaceDeclaration( "xsi", "http://www.w3.org/1999/XMLSchema-instance" );

            env.addNamespaceDeclaration( "xsd", "http://www.w3.org/1999/XMLSchema" );

            env.addNamespaceDeclaration( "namesp2", "http://xml.apache.org/xml-soap" );

            env.addNamespaceDeclaration( "SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/" );

            

            // Compose SOAP body.

            SOAPBody body = env.getBody();

            SOAPElement invoke = body.addChildElement( env.createName("MRWebServices__createIssue", "namesp1","MRWebServices") );

            

            SOAPElement arg1 = invoke.addChildElement( env.createName("user") );

            arg1.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg1.addTextNode("WebServices");

            SOAPElement arg2 = invoke.addChildElement( env.createName("password") );

            arg2.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg2.addTextNode("fakepassword");

            SOAPElement arg3 = invoke.addChildElement( env.createName("extrainfo") );

            arg3.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            SOAPElement arg4 = invoke.addChildElement( env.createName("args") );

            arg4.addAttribute( env.createName("type","xsi",""), "namesp2:SOAPStruct" );

            SOAPElement arg4_1 = arg4.addChildElement( env.createName("priorityNumber") );

            arg4_1.addAttribute( env.createName("type","xsi",""), "xsd:int" );

            arg4_1.addTextNode("1");

            SOAPElement arg4_2 = arg4.addChildElement( env.createName("status") );

            arg4_2.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg4_2.addTextNode("Open");

            SOAPElement arg4_3 = arg4.addChildElement( env.createName("abfields") );

            arg4_3.addAttribute( env.createName("type","xsi",""), "namesp2:SOAPStruct" );

            SOAPElement arg4_3_1 = arg4_3.addChildElement( env.createName("Custom__bAB__bField__bOne") );

            arg4_3_1.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg4_3_1.addTextNode("Value of Custom AB Field One");

            SOAPElement arg4_3_2 = arg4_3.addChildElement( env.createName("Last__bName") );

            arg4_3_2.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg4_3_2.addTextNode("Doe");

            SOAPElement arg4_3_3 = arg4_3.addChildElement( env.createName("First__bName") );

            arg4_3_3.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg4_3_3.addTextNode("John");

            SOAPElement arg4_3_4 = arg4_3.addChildElement( env.createName("Email__bAddress") );

            arg4_3_4.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg4_3_4.addTextNode("johndoe@nowhere.com");

            SOAPElement arg4_4 = arg4.addChildElement( env.createName("description") );

            arg4_4.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg4_4.addTextNode("Place issue description here. From Java code.");

            SOAPElement arg4_5 = arg4.addChildElement( env.createName("assignees") );

            arg4_5.addAttribute( env.createName("type","xsi",""), "SOAP-ENC:Array" );

            arg4_5.addAttribute( env.createName("arrayType","SOAP-ENC",""), "xsd:string[2]" );

            SOAPElement arg4_5_1 = arg4_5.addChildElement( env.createName("item") );

            arg4_5_1.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg4_5_1.addTextNode("user1");

            SOAPElement arg4_5_2 = arg4_5.addChildElement( env.createName("item") );

            arg4_5_2.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg4_5_2.addTextNode("user2");

            SOAPElement arg4_6 = arg4.addChildElement( env.createName("projfields") );

            arg4_6.addAttribute( env.createName("type","xsi",""), "namesp2:SOAPStruct" );

            SOAPElement arg4_6_1 = arg4_6.addChildElement( env.createName("Custom__bField__bOne") );

            arg4_6_1.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg4_6_1.addTextNode("Value of Custom Field One");

            SOAPElement arg4_6_2 = arg4_6.addChildElement( env.createName("Custom__bField__bTwo") );

            arg4_6_2.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg4_6_2.addTextNode("Value of Custom Field Two");

            SOAPElement arg4_7 = arg4.addChildElement( env.createName("projectID") );

            arg4_7.addAttribute( env.createName("type","xsi",""), "xsd:int" );

            arg4_7.addTextNode("78");

            SOAPElement arg4_8 = arg4.addChildElement( env.createName("title") );

            arg4_8.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg4_8.addTextNode("This title comes from Java");

            msg.saveChanges();

            //System.out.println("Request Message ----------\n");

            //msg.writeTo( System.out );

            // Make SOAP call

            SOAPMessage reply = connection.call( msg, "http://fakeserver/MRcgi/MRWebServices.pl" );

            connection.close();

            //System.out.println("Reply Message ----------\n");

            //reply.writeTo( System.out );

            // Get result

            SOAPBody replybody = reply.getSOAPPart().getEnvelope().getBody();

            // Check for error

            if( replybody.hasFault() )

            {

                throw new Exception( replybody.getFault().getFaultString() );

            }

            // Iterate through the result body, extracting information

            java.util.Iterator it = replybody.getChildElements();

            while( it.hasNext() )

            {

                Object obj = it.next();

                if( obj instanceof SOAPElement )

                {

                    SOAPElement ele = (SOAPElement)obj;

                    String s = ele.getElementName().getLocalName();

                    if( s.equals("MRWebServices__createIssueResponse") )

                    {

                        java.util.Iterator it2 = ele.getChildElements();

                        while( it2.hasNext() )

                        {

                            Object obj2 = it2.next();

                            if( obj2 instanceof SOAPElement )

                            {

                                SOAPElement ele2 = (SOAPElement)obj2;

                                String s2 = ele2.getElementName().getLocalName();

                                if( s2.equals("return") )

                                {

                                    java.util.Iterator it3 = ele2.getChildElements();

                                    while( it3.hasNext() )

                                    {

                                        Object obj3 = it3.next();

                                        if( obj3 instanceof Text )

                                        {

                                            Text txt = (Text)obj3;

                                            System.out.println( "Issue " + txt.getValue() + " has been created." );

                                        }

                                    }

                                }

                            }

                        }

                    }

                }

            }

        }

        catch( Exception ex )

        {

            ex.printStackTrace();

        }

    }

}

Editing an Issue

import javax.xml.soap.*;

public class EditIssue

{

    public static void main( String[] args )

    {

        try

        {

            // Comment this out for NO proxy.

            java.util.Properties props = System.getProperties();

            props.put( "http.proxyHost", "localhost" );

            props.put( "http.proxyPort", "8888" );

            // Setup SOAP message.

            SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();

            SOAPConnection connection = scf.createConnection();

            MessageFactory msgFactory = MessageFactory.newInstance();

            SOAPMessage msg = msgFactory.createMessage();

            SOAPEnvelope env = msg.getSOAPPart().getEnvelope();

            env.addNamespaceDeclaration( "xsi", "http://www.w3.org/1999/XMLSchema-instance" );

            env.addNamespaceDeclaration( "xsd", "http://www.w3.org/1999/XMLSchema" );

            env.addNamespaceDeclaration( "namesp2", "http://xml.apache.org/xml-soap" );

            env.addNamespaceDeclaration( "SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/" );

            

            // Compose SOAP body.

            SOAPBody body = env.getBody();

            SOAPElement invoke = body.addChildElement( env.createName("MRWebServices__editIssue", "namesp1","MRWebServices") );

            

            SOAPElement arg1 = invoke.addChildElement( env.createName("user") );

            arg1.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg1.addTextNode("WebServices");

            SOAPElement arg2 = invoke.addChildElement( env.createName("password") );

            arg2.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg2.addTextNode("fakepassword");

            SOAPElement arg3 = invoke.addChildElement( env.createName("extrainfo") );

            arg3.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            SOAPElement arg4 = invoke.addChildElement( env.createName("args") );

            arg4.addAttribute( env.createName("type","xsi",""), "namesp2:SOAPStruct" );

            SOAPElement arg4_1 = arg4.addChildElement( env.createName("abfields") );

            arg4_1.addAttribute( env.createName("type","xsi",""), "namesp2:SOAPStruct" );

            SOAPElement arg4_1_1 = arg4_1.addChildElement( env.createName("Custom__bAB__bField__bOne") );

            arg4_1_1.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg4_1_1.addTextNode("NEW VALUE FOR Custom AB Field One");

            SOAPElement arg4_2 = arg4.addChildElement( env.createName("projfields") );

            arg4_2.addAttribute( env.createName("type","xsi",""), "namesp2:SOAPStruct" );

            SOAPElement arg4_2_1 = arg4_2.addChildElement( env.createName("Custom__bField__bTwo") );

            arg4_2_1.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg4_2_1.addTextNode("NEW VALUE FOR Custom Field Two");

            SOAPElement arg4_3 = arg4.addChildElement( env.createName("title") );

            arg4_3.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg4_3.addTextNode("NEW title is here.");

            

            SOAPElement arg4_4 = arg4.addChildElement( env.createName("projectID") );

            arg4_4.addAttribute( env.createName("type","xsi",""), "xsd:int" );

            arg4_4.addTextNode("78");

            SOAPElement arg4_5 = arg4.addChildElement( env.createName("mrID") );

            arg4_5.addAttribute( env.createName("type","xsi",""), "xsd:int" );

            arg4_5.addTextNode("40");

            msg.saveChanges();

            //System.out.println("Request Message ----------\n");

            //msg.writeTo( System.out );

            // Make SOAP call

            SOAPMessage reply = connection.call( msg, "http://fakeserver/MRcgi/MRWebServices.pl" );

            connection.close();

            //System.out.println("Reply Message ----------\n");

            //reply.writeTo( System.out );

            // Get result

            SOAPBody replybody = reply.getSOAPPart().getEnvelope().getBody();

            // Check for error

            if( replybody.hasFault() )

            {

                throw new Exception( replybody.getFault().getFaultString() );

            }

            System.out.println( "done." );

        }

        catch( Exception ex )

        {

            ex.printStackTrace();

        }

    }

}

Retrieving Issue Details

import javax.xml.soap.*;

public class GetIssueDetails

{

    public static String GetIndent( int num )

    {

        String s = "";

        for( int i = 0; i < num; i++ )

        {

            s = s + " ";

        }

        return s;

    }

    public static void DumpSOAPElement( SOAPElement el, int indent ) throws Exception

    {

        java.util.Iterator it = el.getChildElements();

        while( it.hasNext() )

        {

            String indstr = GetIndent( indent );

            Object obj = it.next();

                

            if( obj instanceof SOAPElement )

            {

                SOAPElement ele = (SOAPElement)obj;

                System.out.println( indstr + "-----------------------------" );

                System.out.println( indstr + ele.getElementName().getLocalName() );

                System.out.println( indstr + "-----------------------------" );

                DumpSOAPElement( ele, indent + 4 );

            }

            else if( obj instanceof Text )

            {

                Text txt = (Text)obj;

                System.out.println( indstr + txt.getValue() + "\n" );

            }

        }

    }

    public static void main( String[] args )

    {

        try

        {

            // Comment this out for NO proxy.

            java.util.Properties props = System.getProperties();

            props.put( "http.proxyHost", "localhost" );

            props.put( "http.proxyPort", "8888" );

            // Setup SOAP message.

            SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();

            SOAPConnection connection = scf.createConnection();

            MessageFactory msgFactory = MessageFactory.newInstance();

            SOAPMessage msg = msgFactory.createMessage();

            SOAPEnvelope env = msg.getSOAPPart().getEnvelope();

            env.addNamespaceDeclaration( "xsi", "http://www.w3.org/1999/XMLSchema-instance" );

            env.addNamespaceDeclaration( "xsd", "http://www.w3.org/1999/XMLSchema" );

            env.addNamespaceDeclaration( "namesp2", "http://xml.apache.org/xml-soap" );

            env.addNamespaceDeclaration( "SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/" );

            

            // Compose SOAP body.

            SOAPBody body = env.getBody();

            SOAPElement invoke = body.addChildElement( env.createName("MRWebServices__getIssueDetails", "namesp1","MRWebServices") );

            

            SOAPElement arg1 = invoke.addChildElement( env.createName("user") );

            arg1.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg1.addTextNode("WebServices");

            SOAPElement arg2 = invoke.addChildElement( env.createName("password") );

            arg2.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg2.addTextNode("fakepassword");

            SOAPElement arg3 = invoke.addChildElement( env.createName("extrainfo") );

            arg3.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            SOAPElement arg4 = invoke.addChildElement( env.createName("projectnumber") );

            arg4.addAttribute( env.createName("type","xsi",""), "xsd:int" );

            arg4.addTextNode("78");

            SOAPElement arg5 = invoke.addChildElement( env.createName("mrid") );

            arg5.addAttribute( env.createName("type","xsi",""), "xsd:int" );

            arg5.addTextNode("1");

            msg.saveChanges();

            //System.out.println("Request Message ----------\n");

            //msg.writeTo( System.out );

            // Make SOAP call

            SOAPMessage reply = connection.call( msg, "http://fakeserver/MRcgi/MRWebServices.pl" );

            connection.close();

            //System.out.println("Reply Message ----------\n");

            //reply.writeTo( System.out );

            // Get result

            SOAPBody replybody = reply.getSOAPPart().getEnvelope().getBody();

            // Check for error

            if( replybody.hasFault() )

            {

                throw new Exception( replybody.getFault().getFaultString() );

            }

            DumpSOAPElement( replybody, 0 );

        }

        catch( Exception ex )

        {

            ex.printStackTrace();

        }

    }

}

Querying the FootPrints Database

import javax.xml.soap.*;

public class Search

{

    public static String GetIndent( int num )

    {

        String s = "";

        for( int i = 0; i < num; i++ )

        {

            s = s + " ";

        }

        return s;

    }

    public static void DumpSOAPElement( SOAPElement el, int indent ) throws Exception

    {

        java.util.Iterator it = el.getChildElements();

        while( it.hasNext() )

        {

            String indstr = GetIndent( indent );

            Object obj = it.next();

                

            if( obj instanceof SOAPElement )

            {

                SOAPElement ele = (SOAPElement)obj;

                System.out.println( indstr + "-----------------------------" );

                System.out.println( indstr + ele.getElementName().getLocalName() );

                System.out.println( indstr + "-----------------------------" );

                DumpSOAPElement( ele, indent + 4 );

            }

            else if( obj instanceof Text )

            {

                Text txt = (Text)obj;

                System.out.println( indstr + txt.getValue() + "\n" );

            }

        }

    }

    public static void main( String[] args )

    {

        try

        {

            // Comment this out for NO proxy.

            java.util.Properties props = System.getProperties();

            props.put( "http.proxyHost", "localhost" );

            props.put( "http.proxyPort", "8888" );

            // Setup SOAP message.

            SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();

            SOAPConnection connection = scf.createConnection();

            MessageFactory msgFactory = MessageFactory.newInstance();

            SOAPMessage msg = msgFactory.createMessage();

            SOAPEnvelope env = msg.getSOAPPart().getEnvelope();

            env.addNamespaceDeclaration( "xsi", "http://www.w3.org/1999/XMLSchema-instance" );

            env.addNamespaceDeclaration( "xsd", "http://www.w3.org/1999/XMLSchema" );

            env.addNamespaceDeclaration( "namesp2", "http://xml.apache.org/xml-soap" );

            env.addNamespaceDeclaration( "SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/" );

            

            // Compose SOAP body.

            SOAPBody body = env.getBody();

            SOAPElement invoke = body.addChildElement( env.createName("MRWebServices__search", "namesp1","MRWebServices") );

            

            SOAPElement arg1 = invoke.addChildElement( env.createName("user") );

            arg1.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg1.addTextNode("WebServices");

            SOAPElement arg2 = invoke.addChildElement( env.createName("password") );

            arg2.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg2.addTextNode("root");

            SOAPElement arg3 = invoke.addChildElement( env.createName("extrainfo") );

            arg3.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            SOAPElement arg4 = invoke.addChildElement( env.createName("query") );

            arg4.addAttribute( env.createName("type","xsi",""), "xsd:string" );

            arg4.addTextNode("select mrID, mrTITLE from MASTER78 WHERE mrTITLE LIKE '%of%'");

            msg.saveChanges();

            //System.out.println("Request Message ----------\n");

            //msg.writeTo( System.out );

            // Make SOAP call

            SOAPMessage reply = connection.call( msg, "http://virgo/MRcgi/MRWebServices.pl" );

            connection.close();

            //System.out.println("Reply Message ----------\n");

            //reply.writeTo( System.out );

            // Get result

            SOAPBody replybody = reply.getSOAPPart().getEnvelope().getBody();

            // Check for error

            if( replybody.hasFault() )

            {

                throw new Exception( replybody.getFault().getFaultString() );

            }

            DumpSOAPElement( replybody, 0 );

        }

        catch( Exception ex )

        {

            ex.printStackTrace();

        }

    }

}

Compiling the Java Code

The following is a sample batch file for compiling the sample Java code:

set JWSDP=C:\Sun\jwsdp-1.5

set SAAJ_LIB=%JWSDP%\saaj\lib

set JAXP_LIB=%JWSDP%\jaxp\lib\endorsed

set SHARED_LIB=%JWSDP%\jwsdp-shared\lib

set CLASSPATH=%SHARED_LIB%\activation.jar;%SAAJ_LIB%\saaj-api.jar;%SHARED_LIB%\mail.jar;%SAAJ_LIB%\saaj-impl.jar;%JAXP_LIB%\..\jaxp-api.jar;%JAXP_LIB%\sax.jar;%JAXP_LIB%\dom.jar;%JAXP_LIB%\xercesImpl.jar;%JAXP_LIB%\xalan.jar;

javac -d . -classpath %CLASSPATH% %1%

Running the Compiled Java Sample Code

The following is a sample batch file for running the compiled Java sample code:

set JWSDP=C:\Sun\jwsdp-1.5

set SAAJ_LIB=%JWSDP%\saaj\lib

set JAXP_LIB=%JWSDP%\jaxp\lib\endorsed

set SHARED_LIB=%JWSDP%\jwsdp-shared\lib

set CLASSPATH=%SHARED_LIB%\activation.jar;%SAAJ_LIB%\saaj-api.jar;%SHARED_LIB%\mail.jar;%SAAJ_LIB%\saaj-impl.jar;%JAXP_LIB%\..\jaxp-api.jar;%JAXP_LIB%\sax.jar;%JAXP_LIB%\dom.jar;%JAXP_LIB%\xercesImpl.jar;%JAXP_LIB%\xalan.jar;

java -classpath %CLASSPATH% %1%

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*