Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Gaurang Sheladia
How to get Service Context reference in HTTP Servlet ?
June 7, 2010 4:36 AM
Answer

Gaurang Sheladia

Rank: Regular Member

Posts: 159

Join Date: February 15, 2009

Recent Posts

Hi Everyone,

Does anyone has idea, how to call Service Context in HTTP servlet.

Actually i am trying to insert images from HTTP Servlet but using liferay API its required Service Context of that class. But here i am getting HTTP request not portlet request.

ServiceContext serviceContext = ServiceContextFactory.getInstance(IGImage.class.getName(), request);


Any inputs will really appreciable.

Thanks in advance.

Thanks,
Gaurang
Roshan Qureshi
RE: How to get Service Context reference in HTTP Servlet ?
January 11, 2011 3:02 AM
Answer

Roshan Qureshi

Rank: Regular Member

Posts: 140

Join Date: August 24, 2010

Recent Posts

Hi Gaurang,

You can get ServiceContext using following code in servlet:
1
2ServiceContext serviceContext = new ServiceContext();
3serviceContext.setScopeGroupId(myGroupId);


The only required field is scopeGroupId. So you can use above two lines to generate service context and can then pass to any util class for further use.

Second method is to use ServiceContextFactory.getInstance(ClassName.class.getName(), portletRequest);
But as you have stated your problem is you don't have portletRequest object this will not useful in your case. So you can use first one.

Thanks,
Roshan Qureshi
Gaurang Sheladia
RE: How to get Service Context reference in HTTP Servlet ?
January 11, 2011 3:09 AM
Answer

Gaurang Sheladia

Rank: Regular Member

Posts: 159

Join Date: February 15, 2009

Recent Posts

Thanks Roshan for your reply...

I got solution as you said but i was forget to update in forum.

Anyway thanks for your input it will help to other community members.

Regards,
Gaurang
Aravinth Raj Raju
RE: How to get Service Context reference in HTTP Servlet ?
March 2, 2012 2:22 AM
Answer

Aravinth Raj Raju

Rank: New Member

Posts: 18

Join Date: October 3, 2011

Recent Posts

Hi..

I tried, using below code to get Service context:

ServiceContext serviceContext = new ServiceContext();
serviceContext.setScopeGroupId(groupId);

But, when i tried getting userId via serviceContext, it returned 0.
serviceContext.getUserId() is returning 0..emoticon

I also want to get workflowContext from the servlet request, as i m working with struts portlet.

Give your suggestion on this issue, to get ServiceContext and workflow context from HttpServlet request.

Thanks,
Aravinth Raj R.
Roy Cespedes
RE: How to get Service Context reference in HTTP Servlet ?
November 25, 2013 3:09 PM
Answer

Roy Cespedes

Rank: New Member

Posts: 3

Join Date: August 16, 2012

Recent Posts

Roshan Qureshi:
Hi Gaurang,

You can get ServiceContext using following code in servlet:
1
2ServiceContext serviceContext = new ServiceContext();
3serviceContext.setScopeGroupId(myGroupId);


The only required field is scopeGroupId. So you can use above two lines to generate service context and can then pass to any util class for further use.

Second method is to use ServiceContextFactory.getInstance(ClassName.class.getName(), portletRequest);
But as you have stated your problem is you don't have portletRequest object this will not useful in your case. So you can use first one.

Thanks,
Roshan Qureshi


Hi Roshan,

the solution would be something like that?
1
2User usuario = PortalUtil.getUser(request);
3ServiceContext serviceContext = new ServiceContext();
4serviceContext.setScopeGroupId(usuario.getGroupId());
Roshan Qureshi
RE: How to get Service Context reference in HTTP Servlet ?
December 19, 2013 2:55 AM
Answer

Roshan Qureshi

Rank: Regular Member

Posts: 140

Join Date: August 24, 2010

Recent Posts

Hi Aravinth,

You are right.
When we are using

ServiceContext serviceContext = new ServiceContext();
serviceContext.setScopeGroupId(myGroupId);

its creating new object of ServiceContext and so it will not having any attributes / fields associated with it.
If we are using another method which is having request as a parameter you will get all params / attributes which were present in request via servicecontext.

As said by Roy, first you need to get user object / or anyother object and need to set to ServiceContext in case you are using

ServiceContext serviceContext = new ServiceContext();

Hope this will help to clear it further.

Regards,
Roshan Qureshi