How to manage agile api libraries in a webapp running on tomcat ?

hi ,

im running a webapp url (should be directed as a url px from agile) . the webapp is running on the tomcat of the filemanager. 
when trying to use agile api classes i got the “JAVA CLASS NOT FOUND ” exception. so i copied agileapi.jar and sdk.jar to the MYAPP/WEB-INF/lib directories but now  i get the following:

org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.ExceptionInInitializerError
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)

root cause

javax.servlet.ServletException: java.lang.ExceptionInInitializerError
	org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
	org.apache.jsp.PXinputTemplate_jsp._jspService(PXinputTemplate_jsp.java:255)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)

root cause

java.lang.ExceptionInInitializerError
	java.lang.Class.forName0(Native Method)
	java.lang.Class.forName(Class.java:186)
	com.agile.api.AgileSessionFactory.initServerLocally(AgileSessionFactory.java:812)
	com.agile.api.AgileSessionFactory.<init>(AgileSessionFactory.java:745)
	com.agile.api.AgileSessionFactory.getInstance(AgileSessionFactory.java:651)
	javabeanforpx.JavaBeanForPX.<init>(JavaBeanForPX.java:41)
	org.apache.jsp.PXinputTemplate_jsp._jspService(PXinputTemplate_jsp.java:119)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)

 

could it be a certificate issue? or maybe adding more jars?
what shoud i do to be able to use the api in such tomcat application?

Add Comment
17 Answer(s)

The Filemgr tomcat is strictly configured to work with Axis and Filemgr application.
You should not use it for custom web application.

However, problem could be related to the url that you are using to getIntance of AgileSessionFactory
AgileSessionFactory(String url, String username, String password).
Can you please write the codethat you are use to create the IAGileSession in your custom code?

Agile Angel Answered on March 15, 2016.
Add Comment

Thanks antonio.

1. why is that a problem to run the custom app on the filemanager? 

2,here is my code. i passed null values because i dont know how to fetch the user password from the url (i see only the user name)  :

public String getObjectName()
{
try{

AgileSessionFactory ag = AgileSessionFactory.getInstance(null);  
IAgileSession sess = ag.createSession(null);

return … //should get some object from the session but failes on the first line,,,

}

catch ( APIException ex )
{
return (“Failed Getting object name from context ” + ex.getErrorCode()+ex.getRootCause().getMessage()+” ” +System.getProperty(“java.io.tmpdir”) );

}

}

Agile User Answered on March 15, 2016.
Add Comment

Hi,
Problem is related to teh fact that this tomcat can have custom libraries just to work with FileManager. Also some server configuration can be done ad hoc for FileMgr.

However, the value passes to the getInstance has to be the AgileURL (http://myserver:7001/Agile
So it becomes:
AgileSessionFactory ag = AgileSessionFactory.getInstance(“http://myserver:7001/Agile“);  

To get the user information, an URL PX shares with other applications the user cookies “j_username” and “j_password” that you can use to create an IAgileSession in your application .

AgileSessionFactory factory = AgileSessionFactory.getInstance(myAgileUrl);
params.put(AgileSessionFactory.PX_USERNAME, j_usernameValue);
params.put(AgileSessionFactory.PX_PASSWORD, j_passwordValue);
IAgileSession session = factory.createSession(params);
...
 
Agile Angel Answered on March 15, 2016.
Add Comment

wi will try that thanks!

is there  documentation on how to use the api through webapps? (i mean, where could i found this cookies solution)

Agile User Answered on March 16, 2016.
Add Comment

You can use link below to access to the full ocumentation for Process Extensions
http://docs.oracle.com/cd/E50306_27/otn/pdf/integration/html_agaaq/output/chapter_3.htm

 

3.6.4 Passing Encoded Agile PLM Information to Other Applications
where there a full example

Example 3-6 Creating IAgileSessions with PX_USERNAME and PX_PASSWORD fields
private IAgileSession connect(Cookie[] cookies) throws Exception {
factory = AgileSessionFactory.getInstance("http://agileserver/Agile");
HashMap params = new HashMap();
 String username = null;
 String pwd = null;
 for (int i = 0; i < cookies.length; i++) {
 if (cookies[i].getName().equals("j_username"))
  username = cookies[i].getValue();
  else if (cookies[i].getName().equals("j_password"))
  pwd = cookies[i].getValue();
}
params.put(AgileSessionFactory.PX_USERNAME, username);
 params.put(AgileSessionFactory.PX_PASSWORD, pwd);
 session = factory.createSession(params);
return session;
}
Agile Angel Answered on March 16, 2016.
Add Comment

hi antonio ,

i have been printing the cookies name from the request and i dont see the j_username or j_password cookie.

these are the ones i see:
JSESSIONID 7topCreatePopupSize START_UPLOAD_IMMED UNZIP UPLOAD_TO_SINGLE_FF FILE_FOLDER_TYPE jsDebug invalidate_session

Agile User Answered on March 16, 2016.
Add Comment

tried also 

private IAgileSession connect(HttpServletRequest request) throws ServletExceptio
{
  HashMap params = new HashMap();
  params.put(AgileSessionFactory.PX_REQUEST, request);
  session = factory.createSession(params);
  return session;
}


(with the factory created by the url) and got :


org.apache.jasper.JasperException: An exception occurred processing JSP page /PXinputTemplate.jsp at line 83

80: 
81:    
82:    
83:    javabeanforpx.JavaBeanForPX px= new javabeanforpx.JavaBeanForPX(request,agileServerURL); %>
84: 
85:   <div class='container'>
86:     <div class='panel panel-primary dialog-panel'>


Stacktrace:
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)

root cause

javax.servlet.ServletException: java.lang.NoClassDefFoundError: Could not initialize class com.agile.api.pc.ServerProperties
	org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
	org.apache.jsp.PXinputTemplate_jsp._jspService(PXinputTemplate_jsp.java:282)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)

root cause

Agile User Answered on March 16, 2016.
Add Comment

I have never tried the creation of session as below

HashMap params = new HashMap();

params.put(AgileSessionFactory.PX_REQUEST, request);

session = factory.createSession(params);

But it is strange that your request has not any Cookie in the request. From where do you run the UrlPX?

In my case, when I run an URLPX from the action menu of an item, I found them.

Probably could be a matter of server configuration

have a look also at this doc section:

 

n addition to information encoded in the URL of a URL-based process extension, the encrypted username and its associated password are available from the j_username and j_password cookies, respectively, which are automatically passed to the target system if the following conditions are met:

  • The user initiates a URL-based process extension from Agile Web Client.

Note:

Your Web application must reside in the domain specified in the cookie.domain property of agile.properties. Otherwise, security cookies will not propagate.

  • The target system is permitted to receive cookies.

  • The target system is in the same domain as the Agile PLM system.

Note:

If the target system is located outside the company firewall, it should be a secure Web server using SSL.

3.6.5 Creating an Agile PLM Session from the Target System

Using authentication information contained in the HTTP request received from a URL-based process extension initiated from Agile Web Client, the target application can use the Agile API to create an IAgileSession. The Agile API client can then retrieve and configure the Agile PLM object referenced by the HTTP request.

When a user logs into Agile Web Client, the authentication process creates a pair of cookies (j_username and j_password) on the server computer that store the user’s encrypted user name and password.

Note:

These cookies will expire after the duration set by the Agile PLM Administrator.

When you initiate a URL-based process extension from Agile Web client, the target system can use cookies to create an Agile PLM session. In effect, Agile Web client and the Agile API client on the target system can share a single sign-on.

Note:

The Agile Java Client, unlike the Web client, does not create client-side cookies. Therefore, it does not support the single sign-on feature for process extensions.

Cookies are designed to be shared among computers within the same domain. For example, if during installation of Agile PLM, you configure the domain to be ”.agile.agilesoft.com”, then all computers ending with ”.agile.agilesoft.com” can use the j_username and j_password cookies.

For more information, see http://cookiescache.tripod.com/.

The following example shows how to use the Agile API to extract cookie information from the HTTP servlet request and use that information to generate an IAgileSession. The value of the AgileSessionFactory.PX_REQUEST field, which is the key used to create the session, is set to be equal to the servlet request.

 
Agile Angel Answered on March 16, 2016.
Add Comment

hey antontion,

i think it might be related to class/jar files that are missing on tomcat.
which jar files should i have in my tomcat app and where?

i have agileAPI.jar and sdk.jar on my WEB-INF/libs folder

Agile User Answered on March 17, 2016.
Add Comment

Hi,

the only api that you have to put is the web app dependencies (AgileAPI.jar and yourCustomTool.jar)
But the one that is missing is related to the weblogic.jar (you can find it in Weblogic server shared lib). This jar is involved only inside the Agile environment and not in the FileMgr. In the normal usage, the ServerProperties should not be called. In your case is called because of the code below is used but I think that is always related to the fact that your http request is not fullfilled with all required elements to create a Session

params.put(AgileSessionFactory.PX_REQUEST, request);
  session = factory.createSession(params);
Agile Angel Answered on March 17, 2016.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.