Fórumok

How is Portlet get user-agent from httpHeader ?

miii suuu, módosítva 15 év-val korábban

How is Portlet get user-agent from httpHeader ?

New Member Bejegyzések: 24 Csatlakozás dátuma: 2008.07.06. Legújabb bejegyzések
Hi all,

I tried to get user-agent from httpHeader but still not found any way to do that. I am using portlet JSR 168

Thanks,
suu
thumbnail
Wilson Man, módosítva 15 év-val korábban

RE: How is Portlet get user-agent from httpHeader ?

Liferay Master Bejegyzések: 581 Csatlakozás dátuma: 2006.06.21. Legújabb bejegyzések
hmmm, i don't think the httpHeader info is found in portletRequest. You may have to gain access to the HttpServletRequest or you can extend Liferay to put that info into the portletRequest attribute.
miii suuu, módosítva 15 év-val korábban

RE: How is Portlet get user-agent from httpHeader ?

New Member Bejegyzések: 24 Csatlakozás dátuma: 2008.07.06. Legújabb bejegyzések
Many thank for your reply.
I have concern about method getProperty(String name ) of javax.portlet.PortletRequest. Could you please explain for me about that, as I know it used to get attributes from httpHeader, eg : portletRequest.getProperty("user-agent");

If you could, please explain me a simple example description that PorletRequest can httpHeader.

Thank you so much

suu

PS: I have just approached Portlet some week ago emoticon
thumbnail
Wilson Man, módosítva 15 év-val korábban

RE: How is Portlet get user-agent from httpHeader ?

Liferay Master Bejegyzések: 581 Csatlakozás dátuma: 2006.06.21. Legújabb bejegyzések
actually, i check on the API and you may want to try the getProperties() method and see if you can get the header values returned.
miii suuu, módosítva 15 év-val korábban

RE: How is Portlet get user-agent from httpHeader ?

New Member Bejegyzések: 24 Csatlakozás dátuma: 2008.07.06. Legújabb bejegyzések
Yup, I tried with both of them - getProperty() and getProperties() but could not get any info about httpHeader.
I used portlet in strust webwork, below a example I tried.


PortletRequest portletRequest = com.opensymphony.webwork.portlet.context.PortletActionContext.getRequest();
		
        final Enumeration e = portletRequest.getPropertyNames();
        String value = null;
        String name = null;
        while (e.hasMoreElements()) {
            name = (String) e.nextElement();
            value = portletRequest.getProperty(name);
           System.out.println(value);
        }


Also, I tried with simple method getProperty("user-agent") but still can not.

- suuu
thumbnail
Wilson Man, módosítva 15 év-val korábban

RE: How is Portlet get user-agent from httpHeader ?

Liferay Master Bejegyzések: 581 Csatlakozás dátuma: 2006.06.21. Legújabb bejegyzések
can you post the system out printing the name value pairs?
miii suuu, módosítva 15 év-val korábban

RE: How is Portlet get user-agent from httpHeader ?

New Member Bejegyzések: 24 Csatlakozás dátuma: 2008.07.06. Legújabb bejegyzések
Hi,

have not any data in Enumeration - e.hasMoreElements() always = null

not reach to while loop, there for do not any is printed out.

-suuu
thumbnail
Fuad Efendi, módosítva 15 év-val korábban

RE: How is Portlet get user-agent from httpHeader ?

Regular Member Bejegyzések: 180 Csatlakozás dátuma: 2007.04.05. Legújabb bejegyzések
Try this:

((com.liferay.portlet.PortletRequestImpl) portletRequest).getHttpServletRequest().getHeader("user-agent");
or something similar.

JSR-168 mentions only some HTTP headers available to PortletRequest (such as Locale, Content-Length).



miii suuu:
Hi all,

I tried to get user-agent from httpHeader but still not found any way to do that. I am using portlet JSR 168

Thanks,
suu
miii suuu, módosítva 15 év-val korábban

RE: How is Portlet get user-agent from httpHeader ?

New Member Bejegyzések: 24 Csatlakozás dátuma: 2008.07.06. Legújabb bejegyzések
Many thanks for your instruction about JSR168 spec.

PortletRequest portletRequest = com.opensymphony.webwork.portlet.context.PortletActionContext.getRequest();
String portletRequestContext = "";
portletRequestContext.append(...)
....
portletRequestContext.append(portletRequest.getContextPath());
System.out.println(portletRequestContext);


Will print out : http://localhost:8080/portletexample, that mean portletRequest have effect.
And then:


portletRequest.getProperty("content-length"); // will return ""
portletRequest.getProperty("content-type");// will return ""
portletRequest.getProperty("accept-language"); //will return ""

I only concern that, in this case I do as JSR168 spec, I would like to know why I can not get httpHeader ?

Also I use portletRequest.getPropertyNames() method, but I get null value too,

- suuu
miii suuu, módosítva 15 év-val korábban

RE: How is Portlet get user-agent from httpHeader ?

New Member Bejegyzések: 24 Csatlakozás dátuma: 2008.07.06. Legújabb bejegyzések
Hi,

I debugged and saw that object requestPortlet is com.liferay.portlet.RenderRequestImp

suu
thumbnail
Fuad Efendi, módosítva 15 év-val korábban

RE: How is Portlet get user-agent from httpHeader ?

Regular Member Bejegyzések: 180 Csatlakozás dátuma: 2007.04.05. Legújabb bejegyzések
miii suuu:
Many thanks for your instruction about JSR168 spec.

portletRequest.getProperty("content-length"); // will return ""
portletRequest.getProperty("content-type");// will return ""
portletRequest.getProperty("accept-language"); //will return ""

I only concern that, in this case I do as JSR168 spec, I would like to know why I can not get httpHeader ?

Also I use portletRequest.getPropertyNames() method, but I get null value too,

- suuu



JSR-168:
=======

getLocale()
Returns the preferred Locale in which the portal will accept content.

getResponseContentType()
Returns the portal preferred content type for the response.


HTTP Headers available to PortletRequest depend also on whether it is ActionRequest:

getCharacterEncoding()
Returns the name of the character encoding used in the body of this request.
getContentLength()
Returns the length, in bytes, of the request body which is made available by the input stream, or -1 if the length is not known.
getContentType()
Returns the MIME type of the body of the request, or null if the type is not known.
... ... ...


Only some HTTP headers available explicitly (for file upload request for instance), and not via getProperty()... getProperty() could return HTTP headers, but it's up to Portlet Container implementation... "A portlet can access portal/portlet-container specific properties through this method and, if available, the headers of the HTTP client request."


((com.liferay.portlet.PortletRequestImpl) portletRequest).getHttpServletRequest().getHeader("user-agent");
works fine; I tested it with RenderRequest instance.



com.liferay.portlet.PortletRequestImpl

...
public Enumeration<String> getPropertyNames() {
return _portalCtx.getPropertyNames();
}
...
public HttpServletRequest getHttpServletRequest() {
return _req;
}
...
gianluca maranzana, módosítva 15 év-val korábban

RE: How is Portlet get user-agent from httpHeader ?

Junior Member Bejegyzések: 26 Csatlakozás dátuma: 2008.07.30. Legújabb bejegyzések
...And what about getHeader("x-forwarded-for")?

I'm try to get a client's IP inside a portlet, but my liferay is proxed via ajp with an Apache, and getRemoteAddr/Host doesn't work.

Any Ideas?

Tnx
gianluca maranzana, módosítva 15 év-val korábban

RE: How is Portlet get user-agent from httpHeader ?

Junior Member Bejegyzések: 26 Csatlakozás dátuma: 2008.07.30. Legújabb bejegyzések
I reply by myself:

I've noticed that in my portlet Jsp, the "request" Object is a "com.liferay.portlet.PortletServletRequest".

In 4.4.2 (that I'm using...) this class have "some" methods such as getRemoteAddr()/Host() that forced return in null.

If you cast your "request" to the class that extends it (javax.servlet.http.HttpServletRequestWrapper) you get quickly the correct IP from getRemoteAddr()/Host(), also if you're using reverseProxy w/ Apache.

G.
thumbnail
daniel aguil mallea, módosítva 15 év-val korábban

RE: How is Portlet get user-agent from httpHeader ?

New Member Bejegyzések: 16 Csatlakozás dátuma: 2007.02.23. Legújabb bejegyzések
other tip...

<jsp:scriptlet>
boolean isFirefox = request.getHeader("user-agent").indexOf("Firefox/") != -1 ;
if(isFirefox){
</jsp:scriptlet>
....
...
....
thumbnail
Subhasis Roy, módosítva 10 év-val korábban

RE: How is Portlet get user-agent from httpHeader ?

Expert Bejegyzések: 275 Csatlakozás dátuma: 2012.01.20. Legújabb bejegyzések
Fuad Efendi:
Try this:

((com.liferay.portlet.PortletRequestImpl) portletRequest).getHttpServletRequest().getHeader("user-agent");
or something similar.

JSR-168 mentions only some HTTP headers available to PortletRequest (such as Locale, Content-Length).



miii suuu:
Hi all,

I tried to get user-agent from httpHeader but still not found any way to do that. I am using portlet JSR 168

Thanks,
suu





Hi Mika,

I am currently facing the same issue. Please find my query in the link below-


Liferay Forum Post


Inside a liferay portlet, I want to fetch the header values which has been set by OpenAM Policy Agent. Is it possible to fetch all the header values inside liferay portlet and is possible can you please provide some pointer to get the HEADER values.

thanks,
subhasis