AnsweredAssumed Answered

JAVA : Problem with session activation when calling clarity web service

Question asked by trevaj on Apr 24, 2013
Latest reply on Apr 29, 2013 by trevaj
Dear All,

After generating WSDL2java by this command:
java WSDL2java http://server/niku/wsdl/Object/Ideas - W
We have following structure of java files in eclipse:


Then we have developed following source code, which will use XOG file and writeIdeas into Clarity.
Structure of file:
<NikuDataBus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="../xsd/nikuxog_idea.xsd">
    <Header action="write" externalSource="NIKU" objectType="idea" version="8.0"/>
    <Ideas>
        <Idea objectID="a" lastUpdatedBy="admin"
            lastUpdatedDate="2006-02-17T12:06:10" managerUserName="admin"
            status="0" name="a">
           <CustomInformation>
                <ColumnValue name="partition_code">NIKU.ROOT</ColumnValue>
            </CustomInformation>
        </Idea>
        <Idea objectID="admin" lastUpdatedBy="admin"
            lastUpdatedDate="2006-02-17T12:06:10" managerUserName="admin"
            status="0" name="admin">
            <CustomInformation>
                <ColumnValue name="partition_code">NIKU.ROOT</ColumnValue>
            </CustomInformation>
        </Idea>
        <Idea benefitDescription="asdfasdf" dependencies="asdfasdf"
            description="asdf" estimatedBenefit="2555" estimatedCost="255"
            estimatedFinishDate="2004-02-03T00:00:00"
            estimatedStartDate="2004-01-15T00:00:00" generalNotes="asdf"
            objectID="admin1" impact="asdfasdf" 
            lastUpdatedBy="admin" lastUpdatedDate="2006-02-17T12:06:10"
            managerUserName="admin" risks="asdfasdf" status="0" name="admin1">
            <CustomInformation>
                <ColumnValue name="partition_code">NIKU.ROOT</ColumnValue>
            </CustomInformation>
        </Idea>
        <Idea objectID="b" lastUpdatedBy="admin"
            lastUpdatedDate="2006-02-17T12:06:10" managerUserName="admin"
            status="0" name="b">
            <CustomInformation>
                <ColumnValue name="partition_code">NIKU.ROOT</ColumnValue>
            </CustomInformation>
        </Idea>
    </Ideas>
</NikuDataBus>
Source code:
package com.niku.www.xog;
import java.io.File;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.axis.message.MessageElement;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import com.niku. www.xog.Object.*;
public class NikuService {
                

                private String sessionID;  
                private _Auth a;   
                private IdeasServiceLocator ideaServiceLocator;
                private IdeasPort niku;
                private _Login lin;
                private _Logout lout;
                
                public NikuService (String userName, String userPassword) {   
                               try {    
                                               ideaServiceLocator = new IdeasServiceLocator();
                                               niku = ideaServiceLocator.getIdeasService();
                                               lin = new _Login();
                                               lin.setUsername(userName);
                                               lin.setPassword(userPassword);
                                               sessionID = niku.login(lin);
                                               
                                               _Auth a = new _Auth();
                                               a.setUsername(userName);
                                               a.setPassword(userPassword); 
                                               a.setSessionID(sessionID);
                               
                               }  catch (Exception e) {  
                                               e.printStackTrace();  
                               }  
                }  
                
                protected void finalize() throws Throwable {   
                               lout = new _Logout();
                               lout.setSessionID(sessionID);
                               niku.logout(lout); 
                } 
                   
                
                public void loadTransClass(NikuDataBus xogXml) {   
                               XOGOutput rsp;   
                               try {    
                                               rsp = niku.writeIdea(xogXml, a);
                                               System.out.println(rsp.get_any()[2].getAsString());
                               }  catch (Exception e){    
                                               e.printStackTrace();   
                               }  
                } 
                
                public static Document getDocumentFromFile(String inputFile) {
                               
                               Document XMLDoc = null;
                               try {
                                               XMLDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File(inputFile));
                               } catch (SAXException e) {
                                               // TODO Auto-generated catch block
                                               e.printStackTrace();
                               } catch (IOException e) {
                                               // TODO Auto-generated catch block
                                               e.printStackTrace();
                               } catch (ParserConfigurationException e) {
                                               // TODO Auto-generated catch block
                                               e.printStackTrace();
                               }
                               return XMLDoc;
                }
                
                public static void main(String[] args)
                {
                               NikuService n = new NikuService("user", "pw");
                               MessageElement[] messageElement = new MessageElement[1];
                               messageElement[0] = new MessageElement(NikuService.getDocumentFromFile("WriteTest.xml").getDocumentElement());
                               NikuDataBus ndb = new NikuDataBus();
                               ndb.set_any(messageElement);
                               System.out.println(n.sessionID);
                               n.loadTransClass(ndb);
                               
                }
}
When we run this source code we get following error in returned XOGOutput
<ErrorInformation>
                <Severity>FATAL</Severity>
        <Description>No active session.  Please login or provide a valid session identifier.</Description>
</ErrorInformation>
We have checked through Clarity app UI that the session is active, but still we got this error.


Just to add, we are able to perform this functionality using gel script, but we need implementation in java due to previous steps. (We are generating pdf files from business objects and then we will upload this files onto Clarity DMS using document write XOG).

Any comments are appreciated.
Tomas

Outcomes