httpservletrequest

How can I get access to the HttpServletRequest object when using Java Web Services

I'm using Java 6, Tomcat 6, and Metro. I use WebService and WebMethod annotations to expose my web service. I would like to obtain information about the request. I tried the following code, but wsCtxt is always null. What step must I take to not get null for the WebServiceContext. In other words: how can I execute the following line to ...

How do I get URL label when parsing request URL?

URL can have a label, separated with a "#" sign, coming after the URL parameters. E.g. http://example.com/foo/bar.jsp?p1=v1#test_label I would expect label to be part of request.getQueryString() and part of request.getRequestURL().toString(). But it doesn't seem to be there. Is there a way to retrieve the label value from HttpServletRe...

Accessing the raw body of a PUT or POST request

I am implementing a RESTful API in Grails, and use a custom authentication scheme that involves signing the body of the request (in a manner similar to Amazon's S3 authentication scheme). Therefore, to authenticate the request, I need to access the raw POST or PUT body content to calculate and verify the digital signature. I am doing au...

Unable to get the content out of a HttpServletRequest

Hi, I'm trying to get the contents of a HttpServletRequest. Here is how I'm doing it: // Extract the request content StringBuilder stringBuilder = new StringBuilder(); BufferedReader bufferedReader = null; String content = ""; try { InputStream inputStream = request.getInputStream(); if (inputStream != null) { bufferedReader = new...

httpclient 4 how to get bytes

HttpGet httpget = new HttpGet("http://www.google.com/"); System.out.println("executing request " + httpget.getURI()); // Create a response handler ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = httpclient.execute(httpget, responseHandler); this will get responseBody as...

Best practice: servlet that uses httpclient to post content

i want to write a java servlet that will be called by different users to do httpclient post content to another side via "POST" . i wanted to hear opinion from guru in this case, do my servlet need to use threadpool or something since i want to serve different users at the same time and each user is executing different httpclient post ...

JSP Page HttpServletRequest getAttribute Typecasting

Hi There, Any ideas on the correct method of typecasting an Object out of a getAttribute request from a JSP page HttpServletRequest? I have googled but it seems that the common solution is just sticking suppresswarnings in your code... Something I would very much like to avoid. I currently have: HashMap<String, ArrayList<HashMap<Stri...

create pageContext from HttpServletRequest

I know this might sound crazy...but i am integrating with some third party api's and unfortunately they have a utility class which only takes a pageContext object..I did some peeking around and found that they are doing a lot of stuff with pageContext... Is there a way to get to or create a pageContext from HttpServeletRequest. ...

Retrieve POST parameters only (Java)

Does anyone know of a way to get only POST parameters from an HttpServletRequest object? IE, PHP has the $_POST superglobal and Perl's CGI.pm will only retrieve POST parameters if the HTTP method is POST (by default). HttpServletRequest.getParameter(String) will include the GET URL parameters even if the HTTP method is POST. ...

How can you get the original REQUEST_URI from within a Struts 2 Action reached via an apache ErrorDocument redirection?

How can you access the REQUEST_URI from within a Struts 2 Action? In perl/php/ruby it is readily available via ENV["REQUEST_URI"] and the like. In java it seems that the PageContext.getErrorData().getRequestURI() is what I'm looking for, but sadly, the PageContext does not appear to be defined within the action, either because the ErrorD...

Java HttpServletRequest get URL in browsers URL bar.

So I'm trying to grab the current URL of the page using Java's request object. I've been using request.getRequestURI() to preform this, but I noticed that when a java class reroutes me to a different page off a servlet request getRequestURI gives that that address as opposed to the orginal URL that was typed in the browser and which stil...

Get the Raw Request String from HttpServletRequest.

Is it possible to get the raw HTTP Request from the HttpServletRequest object? I want to see the raw request as a String if at all possible. I need to get the full text of the request, in this case it's a POST request, so the URL doesn't help. It's also part of a multi-part form, so I can't just call the "getParameterNames()" or "getPar...

Servlet request.getParameters non english character help!

Heya guys, I'm in desperate need of help. I have a Java servlet that is accessed by a HTTP Get URL with eight parameters in it. The problem is that the parameters are not exclusive to English. Any other language can be in those parameters, like Hebrew, for example. Now, when I send the data - either from the class that is supposed to...

How to retrieve multiple values from the select field using Commons File Upload?

Update: The problem ended up being the Flash component itself. It wasn't properly compiling the multiple values from the element. I notified the developers and they implemented a workaround. Commons FileUpload does support multiple values per the accepted answer. I have a form, enctype="multipart/form-data", with one <select name="XX...

How can I manually load a Java session using a JSESSIONID?

I have a servlet which handles a multipart form post. The post is actually being made by a Flash file upload component embedded in the page. In some browsers, the Flash-generated POST doesn't include the JSESSIONID which is making it impossible for me to load certain information from the session during the post. The flash upload compon...

Retrieving JSON Object Literal from HttpServletRequest

I am writing code that needs to extract an object literal posted to a servlet. I have studied the API for the HttpServletRequest object, but it is not clear to me how to get the JSON object out of the request since it is not posted from a form element on a web page. Any insight is appreciated. Thanks. ...

HTTP Referer header in Struts 2

How can I get the Referer header under Struts2? Right now I'm using an ActionSupport class and I can't seem to get a ServletActionContext object or implement the ServletRequestAware interface? (Where is ServletRequestAware in Struts2? which jar?) I'm trying to set up an automatic redirect to a page's referer, stored in a session variabl...

HttpServletRequest.getRemoteAddr() returning wrong address

We need to log the client's IP address from a Seam action. Currently, we're using the code: ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); HttpServletRequest request = (HttpServletRequest)context.getRequest(); this.remoteAddress = request.getRemoteAddr(); However, this seems to be always returning ...

How do I reliably access the HttpServletRequest in a jspx when it's behind a proxy?

I've got a jspx that needs to know the current HttpServletRequest's getServerName(). The jspx can fetch this with #{mybean.serverName} from its bean, like this: public String getServerName() { HttpServletRequest request = (HttpServletRequest) FacesInstance.getCurrentInstance().getExternalContent().getRequest(); return request.getS...

get to the HttpServletRequest (request) object from java code

Hey guys, This is probably a very beginner level question. But I need to get hold of the request object in java code. I can't pass this object down to my code for certain reasons. Is there any way I can say something like: getCurrentHTTPServletRequest? It is safe for me to assume that I am in a Servlet Context. ...