VMware {code} Community
avasilsg
Contributor
Contributor

HTML issue user session.

Hello All,

the case is as follows:

I have a controller that is supposed to clone virtual machines. However, I do not know how to inject the user session cookie and URL within the controller constructor from HTML part. I have not seen an example so far that acquires these two parameters with javascript and HTML bridge. I dont want to use an adapter for this because the whole my logic is based on requests and responses. I have tried to define the controller as follows:

<bean name="createVMController" class="com.controller.CreateVMController">
<constructor-arg ref="userSessionService"/>
</bean>
0 Kudos
8 Replies
laurentsd
VMware Employee
VMware Employee

See this HTML bridge sample to inject UserSession on the java side: html-bridge/samples/vsphere-wssdk-service/src/main/java/com/vmware/samples/vspherewssdk/VmDataProviderImpl.java

(you can do the same thing inside a Java controller)

If you have a different use case please provide all the details. Thanks.

0 Kudos
JDeepa
Contributor
Contributor

I have similar issue in my HTML bridge code. I injected UserSessionService in ActionsController.

private final UserSessionService _userSessionService;

public ActionsController(UserSessionService userSessionService, < other constructor args>  ) {

      _userSessionService = userSessionService;

// other constrcutor args

}

public Map<String, Object> invoke(....) {

UserSession userSession = _userSessionService.getUserSession();   // here userSession is coming as null.

}


actionsController and userSessionService bean in webapp/WEB-INF/spring/ bundle-context.xml.


<bean name="actionsController" class="com.sabc.mvc.ActionsController" autowire="constructor"/>

<osgi:reference id="userSessionService"    interface="com.vmware.vise.usersession.UserSessionService"/>

0 Kudos
JDeepa
Contributor
Contributor

Can you please help me to fix the issue with User session?

0 Kudos
laurentsd
VMware Employee
VMware Employee

Does your action URL ends with ".html" as explained in the HTML bridge doc?  This is a requirement for the session to be authenticated.

0 Kudos
JDeepa
Contributor
Contributor

My action url is .../rest/actions.html?acitonUid=someValue&targets=objectIdValue.

So should it be just ../rest/actions.html and pass the parameters in request body.?

0 Kudos
laurentsd
VMware Employee
VMware Employee

Yes, action rest calls are generally issued as POST requests. See the chassisA-html/src/main/webapp/resources/editChassisAction.html

0 Kudos
JDeepa
Contributor
Contributor

My requirement is that I have to display some custom data in a summary page. I have a java service that gets the custom data. Now I have to plugin my summary.html with the java service.

The java service requires a user session object. If I follow the chassis-summary.html sample, then I have to give the properties to DataAccessController, but in my case, I need several properties .

If I use my own controller instead of DataAccessController to hookup with java service, the will user session works fine?

Note: The java service is shared by flex too,

0 Kudos
laurentsd
VMware Employee
VMware Employee

yes, you can inject the UserSessionService in your java service.  What matters is that the http request gets authenticated properly.

0 Kudos