top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to validate or parse HTTP request headers?

+2 votes
1,159 views

I have task to validate or parse following http header

Accept
Accept-Charset
Accept-Encoding
Accept-Language
Accept-Datetime
Content-Length
Content-MD5
Content-Type

lets take Accept-Language as an example , if header language comes other than en-us I should reject the request with customized code response.

let me know ways to achieve the task? can we do with any configuration files?
We are using tomcat 6.0.18

posted Jan 14, 2014 by Mandeep Sehgal

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Have a look at the URLRewriteFilter, here : http://tuckey.org/urlrewrite/

Or, if this is a school exercise, then you'll have a bit more reasearch and work to do yourself, to write your own servlet filter to do the job.

answer Jan 14, 2014 by Deepankar Dubey
Similar Questions
+1 vote

We're developing webapp running on Tomcat 7. The apps use third-party components that we can't modify and those components connect to external sites using HTTP.

We have a policy of routing all outbound traffic through an authenticating HTTP proxy. This is a bit of problem for us since the Oracle Java 7 JVM doesn't support configuring proxy authentication on the JVM level (using e.g. system properties).

One possible workaround I could think of is to create a custom javaagent that would set a default java.net.Authenticator in premain() method. This approach appears to work in a command line program that uses HttpURLConnection, but are there any potential caveats to this method when used with webapps running in Tomcat? One shortcoming is that the same Authenticator would be used for all webapps in the JVM, but this is something we can live with.

0 votes

I'm trying to validate form data before submitting it to the web server but the code giving error.
I'm not able to find where is the problem in code.
so plz correct it....

<script type="text/javascript">
<!--
function validateEmail()
{

   var email_id = document.Form.emaill.value;
   atpos = emailID.indexOf("@");
   dotpos = emailID.lastIndexOf(".");
   if (atpos >1 : ( dotpos - atpos > 2 )) 
   {
       alert("Please enter correct email ID")
       document.myForm.EMail.focus() ;
       return false;
   }
   return( true );
}
//-->
</script>
+1 vote
$scope.addTodo = function() {     
    var url = 'http://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/Find/v1.10/json2.ws?Key=XE97-xXxx-YG99-JK92&SearchTerm=12345&PreferredLanguage=English&Filter=&UserName=&CallbackFunction=a';
    var config1 = {headers:{
    'Access-Control-Allow-Origin':'*',
    'Access-Control-Allow-Methods': ['OPTIONS', 'GET', 'POST'],
    'Access-Control-Allow-Headers':'Origin, X-Requested-With, Content-Type, Accept',
    'Content-Type':'text/plain; charset=utf-8',
    'Accept':'*/*'
            }};
   //  alert("hello");
   alert("url" + url);
   //Enable cross domain calls
   $http.defaults.useXDomain = true;
   // alert("$http.defaults.useXDomain");
   //Remove the header used to identify ajax call  that would prevent CORS from working
   delete $http.defaults.headers.common['X-Requested-With'];
    //   alert("$http.defaults.headers.common");
    //  alert("$http.config1"+config1);
    //  alert("url" + url);

    $http.get(url, config1).success(function (data, status, headers, config) {
  alert("success");
  if(data.success){
  alert("inside success");
  }else{
   alert("inside else");
  }
}).
error(function (data, status, headers, config) {
alert("Error, please report to admin. Error code is " + status);
//alert("data, please report to admin. Error code is " + data);      
});
};
+1 vote

We have a set up like Apahce (80,443) redirects the request to Tomcat (8080) using mod_jk.

The new requirement is to route the request from the same apache to another tomcat (8090). Hence I made the different config file for apache with different ports (86,4444) and different worker for mod_jk which routes the request to tomcat.

Now the issue is when I hit the url http://:86 and after providing the credentials, it is redirecting to https://:86 and throwing the below error.

Error in browser:

Secure Connection Failed

An error occurred during a connection to x.x.x.x:86. SSL received a record that exceeded the maximum permissible length. (Error code: ssl_error_rx_record_too_long)

Error in logs:

"x16x03x01" 501

[Thu Jan 08 08:22:46 2015] [debug] ssl_engine_io.c(1523): OpenSSL: I/O error, 11 bytes expected to read on BIO#1bf568 [mem: 1f3930]
[Thu Jan 08 08:22:46 2015] [debug] ssl_engine_kernel.c(1806): OpenSSL: Exit: error in SSLv2/v3 read client hello A
[Thu Jan 08 08:22:46 2015] [info] (70014)End of file found: SSL handshake interrupted by system [Hint: Stop button pressed in browser?!]
[Thu Jan 08 08:22:46 2015] [info] Connection to child 3 closed with abortive shutdown(server pritoolvca1.sw.ericsson.se:443 [2], client 153.88.164.216)
[Thu Jan 08 08:23:53 2015] [error] [client 172.17.136.153] Invalid method in request x16x03x01

Could you please suggest where it might went wrong and the way forward..

+2 votes

I want the images should be accessible as part of http page only not by any other mean, no clue any suggestion would have great help.

...