# How to get perspective session info in customized module?

**URL:** <https://forum.inductiveautomation.com/t/how-to-get-perspective-session-info-in-customized-module/70345>\
**Category:** Module Development\
**Tags:** perspective, ignition81\
**Created:** [February 27, 2023, 6:05am UTC](https://forum.inductiveautomation.com/t/how-to-get-perspective-session-info-in-customized-module/70345 "2023-02-27T06:05:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![weixionglichina](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/weixionglichina/32/10650_2.png) [@weixionglichina](https://forum.inductiveautomation.com/u/weixionglichina)\
**Post date:** [February 27, 2023, 6:05am UTC](https://forum.inductiveautomation.com/t/how-to-get-perspective-session-info-in-customized-module/70345/1 "2023-02-27T06:05:13Z")

</div>

I created a module to get local files via server, but errors happen to  
PerspectiveSessionCollection psc = (PerspectiveSessionCollection) sess.getAttribute("perspective-session");

as below:  
java.lang.ClassCastException: class com.inductiveautomation.perspective.gateway.session.PerspectiveSessionCollection cannot be cast to class com.inductiveautomation.perspective.gateway.session.PerspectiveSessionCollection (com.inductiveautomation.perspective.gateway.session.PerspectiveSessionCollection is in unnamed module of loader com.inductiveautomation.ignition.gateway.modules.ModuleClassLoader @7855ca07; com.inductiveautomation.perspective.gateway.session.PerspectiveSessionCollection is in unnamed module of loader com.inductiveautomation.ignition.gateway.modules.ModuleClassLoader @4d028b45)

How to use perspective session in proper way, any examples would be appreciated!

```
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String pathInfo = req.getPathInfo();

	String project = "demo";
	HttpSession sess = req.getSession(false);

	sLogger.infof("140 %s", "sLogger.debugf(\"140 %s\", sess.getAttribute(\"perspective-session\"));");
	sLogger.infof("140 %s", sess.getAttribute("perspective-session")==null);

	Enumeration<String> keys = sess.getAttributeNames();
	while (keys.hasMoreElements()) {
		String s = keys.nextElement();
		sLogger.info("144" + s);
	}
				
	PerspectiveSessionCollection psc = (PerspectiveSessionCollection) sess.getAttribute("perspective-session");
	InternalSession isess = psc.getOrCreateSession(project);

	WebAuthUser wau = isess.getWebAuthStatus().getUser().get();
	sLogger.infof("154 %s", isess.getSessionInfo());

```

Ignition server version 8.1.3, perspective-gateway version: 2.1.3

---

<div class="post-metadata">

**Author:** ![weixionglichina](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/weixionglichina/32/10650_2.png) [@weixionglichina](https://forum.inductiveautomation.com/u/weixionglichina)\
**Post date:** [February 27, 2023, 12:52pm UTC](https://forum.inductiveautomation.com/t/how-to-get-perspective-session-info-in-customized-module/70345/2 "2023-02-27T12:52:58Z")

</div>

Any ideas?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 27, 2023, 3:31pm UTC](https://forum.inductiveautomation.com/t/how-to-get-perspective-session-info-in-customized-module/70345/3 "2023-02-27T15:31:35Z")

</div>

Is your module marked as depending on Perspective in your module.xml? Without that, you'll be loaded in an isolated class loader without automatic access to any other module's classes, though you can ask the module manager to resolve any class by name.

---

<div class="post-metadata">

**Author:** ![weixionglichina](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/weixionglichina/32/10650_2.png) [@weixionglichina](https://forum.inductiveautomation.com/u/weixionglichina)\
**Post date:** [February 28, 2023, 2:16am UTC](https://forum.inductiveautomation.com/t/how-to-get-perspective-session-info-in-customized-module/70345/4 "2023-02-28T02:16:08Z")

</div>

Yes, I am using Maven and marked perspective as depending perspective as below, how do I fix this issue?

```auto
    <dependencies>
		<dependency>
		    <groupId>com.inductiveautomation.perspective</groupId>
		    <artifactId>perspective-gateway</artifactId>
		    <version>2.1.3</version>
		</dependency>
		<dependency>
		    <groupId>javax.servlet</groupId>
		    <artifactId>javax.servlet-api</artifactId>
		    <version>3.1.0</version>
		    <scope>provided</scope>
		</dependency>
		<dependency>
		    <groupId>com.inductiveautomation.ignition</groupId>
		    <artifactId>gateway-api</artifactId>
		    <version>8.1.3</version>
		</dependency>
    </dependencies>

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 28, 2023, 2:27am UTC](https://forum.inductiveautomation.com/t/how-to-get-perspective-session-info-in-customized-module/70345/5 "2023-02-28T02:27:39Z")

</div>

Your SDK dependencies need to be `provided` scope as well.

---

<div class="post-metadata">

**Author:** ![weixionglichina](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/weixionglichina/32/10650_2.png) [@weixionglichina](https://forum.inductiveautomation.com/u/weixionglichina)\
**Post date:** [February 28, 2023, 6:23am UTC](https://forum.inductiveautomation.com/t/how-to-get-perspective-session-info-in-customized-module/70345/6 "2023-02-28T06:23:45Z")

</div>

@Kevin.Herron

I import classes like:

```auto
import com.inductiveautomation.perspective.gateway.session.InternalSession;
import com.inductiveautomation.perspective.gateway.session.PerspectiveSessionCollection;

```

```auto
<dependencies>
		<dependency>
		    <groupId>com.inductiveautomation.perspective</groupId>
		    <artifactId>perspective-gateway</artifactId>
		    <version>2.1.3</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
		    <groupId>javax.servlet</groupId>
		    <artifactId>javax.servlet-api</artifactId>
		    <version>3.1.0</version>
		    <scope>provided</scope>
		</dependency>
		<dependency>
		    <groupId>com.inductiveautomation.ignition</groupId>
		    <artifactId>gateway-api</artifactId>
		    <version>8.1.3</version>
			<scope>provided</scope>
		</dependency>
    </dependencies>

```

It cann't find class if it is provided scope.  
java.lang.NoClassDefFoundError: com/inductiveautomation/perspective/gateway/session/PerspectiveSessionCollection

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 28, 2023, 1:56pm UTC](https://forum.inductiveautomation.com/t/how-to-get-perspective-session-info-in-customized-module/70345/7 "2023-02-28T13:56:23Z")

</div>

It sounds like your module isn’t declaring its dependency on the Perspective module.

---

<div class="post-metadata">

**Author:** ![weixionglichina](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/weixionglichina/32/10650_2.png) [@weixionglichina](https://forum.inductiveautomation.com/u/weixionglichina)\
**Post date:** [February 28, 2023, 2:51pm UTC](https://forum.inductiveautomation.com/t/how-to-get-perspective-session-info-in-customized-module/70345/8 "2023-02-28T14:51:10Z")

</div>

Any examples or links could help me out?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 28, 2023, 2:57pm UTC](https://forum.inductiveautomation.com/t/how-to-get-perspective-session-info-in-customized-module/70345/9 "2023-02-28T14:57:45Z")

</div>

> <https://github.com/inductiveautomation/ignition-sdk-examples/blob/4c4552578fec89082a207cca68f36d27e920c7d1/perspective-component/build.gradle.kts#L28-L31>

for Maven looks something like this (change module ID):

> <https://github.com/inductiveautomation/ignition-sdk-examples/blob/4c4552578fec89082a207cca68f36d27e920c7d1/opc-ua-device/opc-ua-device-build/pom.xml#L55-L60>
