SSLSession instance in servlets

How can I get SSLSession instance or SSL session propereties inside servlets in OC4J?

money321 wrote:
Because in beginning I was not sure that Servlets instances are also actually threads.They are not not threads. Each call to doGet(), doPost() etc is called in a Thread and since there can be many simultaneous calls each having it's own thread a Servlet has to be thread safe.
My other question was specific to threads as I was trying to implement threads.Why?
>
But in this one I rather used servlets.
But apologies, as instance of servlet are also threads.As I said, they are not threads.
>
But still one last doubt.
Sabre if you could please clarify the same as well :How about you do some reading [http://java.sun.com/developer/onlineTraining/Servlets/Fundamentals/|http://java.sun.com/developer/onlineTraining/Servlets/Fundamentals/] and use Google.
>
in your option 2 and three I will have to pass request object to function fun().No. You will need access to the request object for 2 and the servlet context for 3. You need to pass something
If i am correct on this then is this too a better approach ?My preferred approach is 1 since it makes much of your code testable outside of a Servlet.

Similar Messages

  • Number of instances of servlet

    I am confused about the concept "instance" and "thread".
    Consider this example:
    public class Test extends HttpServlet{
    private String langEnv;
    public void doGet(HttpRequest req,HttpResponse res){
    langEnv = (String) session.getAttribute("langEnv");
    When there are many users logged in and access this servlet, since they
    have different language setting when they log in, so the servlet will get
    different value of the variable langEnv. But there is only one instance !
    So how is this problem to be solved ? Maybe the problem has something to do with
    "thread", but I am really confused.
    I read the specification of servlet and could not find the answer.
    Thanks.

    I have another question.
    If the class have another method "doPost":
    doPost(HttpRequest req,HttpResponse res){
    if ( langEnv.equals("EN") ){
    // do something
    Assume that langEnv is still private field of the class.
    When user visit the servlet for the first time, langEnv gets its value
    from session, and servlet displays a form, user submit the form , then
    the servlet executes the doPost method, the langEnv is still there!
    Where is the value of langEnv from ? This time , the serlvet does not get
    it from session?
    In another word, how can the system dispatch the request of the user
    to the same instance (or thread ?) at the second time ?

  • How can I create a java bean instance from servlet, at runtime?

    Will anybody help me?
    I want to send bean (class) name to a servlet through parameter and I need servlet to create specified bean instance and run its method that I will send through another parameter, at runtime.

    Thanks. I found answer

  • How to get SSLSession in Servlet?

    Hello,
    Is there any new way to get a SSLSession object inside Servlet?
    Why javax.net.ssl.session attribute is no longer available since Servlet 2.1 specification?
    See:
    http://java.sun.com/products/servlet/2.1/api/javax.servlet.ServletRequest.html#getAttribute(javax.servlet.String)
    Thank you.

    I agree with you, but the question is still remind - how can I destroy Application Session so that transport level (SSL) session will be destroyed also?
    The problem is that I need to force the browser to check user certificate which is stored on the smart card.

  • Restricting Thread Pool for Servlet instances

    I am using WebLogic5.1.0 version wherein I am registering a Servlet which
    would be called by all the clients connecting
    to my aplication. The servlet's service methods is taking some time to
    execute. Since the servlet is following a SingleThreadModel, when there are
    a large number of Clients connected, the number instances of Servlets
    created are very high and the number of thread in the Application Server
    process becomes very high affecting the performance of the other
    applications.
    Is it possible to restrict the number of instances of the servlets that get
    created in the Application server ?
    What are the setting required to achieve this ?
    Sandeep

    Hi.
    I'm not aware of a property setting that allows you to restrict the number of
    servlet instances in WLS for the SingleThreadModel. The number of execute
    threads is fixed - it does not grow depending on load. You can set this value
    in the weblogic.properties file by setting weblogic.system.executeThreadCount.
    This value is 15 by default.
    It does sound like you are reaching the max capability of your
    server/hardware. You should try tuning WLS.
    Here are a couple of suggestions:
    1. Try adjusting the executeThreadCount value to a higher value. Start by
    setting it to 30 - see if that makes any difference.
    2. Check out the following tuning guide:
    http://www.weblogic.com/docs51/admindocs/tuning.html
    3. Here is a list of admin properties that might aid in tuning:
    http://www.weblogic.com/docs51/adminhelp/AdminPropertyHelp.html
    4. If you are still having problems you might do better by posting this issue
    to the performance newsgroup.
    Regards,
    Michael
    Sandeep Rajpathak wrote:
    I am using WebLogic5.1.0 version wherein I am registering a Servlet which
    would be called by all the clients connecting
    to my aplication. The servlet's service methods is taking some time to
    execute. Since the servlet is following a SingleThreadModel, when there are
    a large number of Clients connected, the number instances of Servlets
    created are very high and the number of thread in the Application Server
    process becomes very high affecting the performance of the other
    applications.
    Is it possible to restrict the number of instances of the servlets that get
    created in the Application server ?
    What are the setting required to achieve this ?
    Sandeep--
    Michael Young
    Developer Relations Engineer
    BEA Support

  • I need know the concept of instance servlet

    i know the servlt instance when thecomming request or on load start up but i need improve of the servlet istance may be have in our application more than one of the instance servlet (i mean one servlet more than one instance ) or in our servlet have one instnace ????
    please i need to know for that couase this improve for starting to programming he web aplication
    thanks

    We said above that servlets persist between requests as object instances. In other words, at the time the code for a servlet is loaded, the server creates a single class instance. That single instance handles every request made of the servlet. This improves performance in three ways:
    It keeps the memory footprint small.
    It eliminates the object creation overhead that would otherwise be necessary to create a new servlet object. A servlet can be already loaded in a virtual machine when a request comes in, letting it begin executing right away.
    It enables persistence. A servlet can have already loaded anything it's likely to need during the handling of a request. For example, a database connection can be opened once and used repeatedly thereafter. It can even be used by a group of servlets. Another example is a shopping cart servlet that loads in memory the price list along with information about its recently connected clients. Yet another servlet may choose to cache entire pages of output to save time if it receives the same request again.
    Not only do servlets persist between requests, but so do any threads created by servlets. This perhaps isn't useful for the run-of-the-mill servlet, but it opens up some interesting possibilities. Consider the situation where one background thread performs some calculation while other threads display the latest results. It's quite similar to an animation applet where one thread changes the picture and another one paints the display.
    but you can created for each request the instance servlet through
    implements SingleThreadModel
    i think this is concept of instanced of servlet
    thanks

  • Instance variables in Servlets.

    Hi
    Is it a good practice to use instance variable in servlet.
    Please refer code snippet below.
    public class ExcelAction extends HttpServlet {
    private int var1 =0;
    doGet () {
    var1++;
    fun1();
    fun1 (){
    var1++;
    }Like in above code I have used an instance variable var1 because I wish the same to be accessible in all servlet functions.
    I guess it is not a good practice, as different requests to this servlet at same time will result in multiple threads of this servlet. Which will make the state of var1 unsafe.
    If this is correct then what are the alternates if I wish to share variables between functions in a servlet.
    Thanks

    money321 wrote:
    Because in beginning I was not sure that Servlets instances are also actually threads.They are not not threads. Each call to doGet(), doPost() etc is called in a Thread and since there can be many simultaneous calls each having it's own thread a Servlet has to be thread safe.
    My other question was specific to threads as I was trying to implement threads.Why?
    >
    But in this one I rather used servlets.
    But apologies, as instance of servlet are also threads.As I said, they are not threads.
    >
    But still one last doubt.
    Sabre if you could please clarify the same as well :How about you do some reading [http://java.sun.com/developer/onlineTraining/Servlets/Fundamentals/|http://java.sun.com/developer/onlineTraining/Servlets/Fundamentals/] and use Google.
    >
    in your option 2 and three I will have to pass request object to function fun().No. You will need access to the request object for 2 and the servlet context for 3. You need to pass something
    If i am correct on this then is this too a better approach ?My preferred approach is 1 since it makes much of your code testable outside of a Servlet.

  • Servlet and Class instances

    Under normal conditions a web-container creates only one instance of servlet.Now the case is I am creating instance of a class in the servlet.So for every request to the servlet does an instance of the class is created?

    If you make the instance in a service method (service(), doGet(), doPost() etc...) then yes, each request will create a new instance.
    If you create the instance anyplace else, no they will share it.
    If you hold the reference to the class in the servlet class level as opposed to storing it in the method which creates and uses it, then you can run into problems as well, since there will be only one reference for all requests.
    So generally speaking in Servlets (and in any application you need to worry about thread safety:
    This is bad. One object will be used by all requests:
    public class BadServlet ... {
        Object myObject = new Object();
        public void doGet(...) ... {
            do something with myObject;
    }This is bad. A new instance is made for each request, but only one reference. So one request will end up using another's instance:
    public class BadServlet ... {
        Object myObject;
        public void doGet(...)... {
            myObject = new Object();
            do something with myObject;
    }This is how you would do it in a thread safe manner:
    public class GoodServlet ...{
        public void doGet(...)... {
            Object myObject = new Object();
            //Another method in same class needs a reference?  Pass it as a parameter
            someOtherMethod(myObject);
            //Some other servlet needs access?  Store it in Request scope
            request.setAttribute("myObject", myObject);
            //Some other request needs to access it?  Put it in the session scope
            HttpSession session = request.getSession();
            session.setAttribute("myObject", myObject);
        private void doSomething(Object myObject) ... {
            do something with myObject
    }

  • Number of Instances of Stateless Session Bean

    For a servlet(not SingleThreadModel) not hosted in a distributed environment(the default),the servlet container must use only one instance per servlet declaration.
    All instances of a stateless session bean are equivalent.
    In this case, why do the EJB container need to create more than one instances per stateless session bean?
    thanks.

    Would you like to explain why a servlet declaration
    has only one instance?Handling the different client requests as separate threads in the service() method of the servlet is more efficient than using a pool of servlets. That's one of the reasons that the SingleThreadModel (usually implemented using a pool) is now deprecated, along with the fact that that model gives the developer a false sense of security as to multithreading issues...
    Once we leave the Web tier to handle remote objects (EJBs) or database connections, we have a different problem, since we are faced with objects that are slow to create and tie up much more resources. In the biz and back-end tiers, using a pool of already existing instances gives actually better performance.

  • Scalability of single servlet for application

              Hi,
              The J2EE blue prints recomends the single servlet approach as a controller and
              entry point for the application. How does this scale up in Weblogic server for
              a website with a very heavy load of many concurrent users. Right now we are planning
              to use Weblogic 6.1 for the portal development
              REgards
              Barath
              

    WLS 5.1 only uses a single instance per servlet, but it is multi-thread. So if your
              service method is not synchronized, or not using any synchronizing within service
              method, there should be no scale up problem.
              Just curious, why doesn't WLS webserver use several instances under heavy load?
              minjiang
              Mike Reiche wrote:
              > There is no scaling issue here. Hitting a single servlet many times is equivalent
              > (processing-wise) to hitting many servlets fewere times.
              >
              > Mike
              >
              > "barath" <[email protected]> wrote:
              > >
              > >Hi,
              > > The J2EE blue prints recomends the single servlet approach as a controller
              > >and
              > >entry point for the application. How does this scale up in Weblogic server
              > >for
              > >a website with a very heavy load of many concurrent users. Right now
              > >we are planning
              > >to use Weblogic 6.1 for the portal development
              > >
              > >REgards
              > >Barath
              

  • Parameterized constructor in servlets

    why can't we use parameterized constructor in servlets?
    please describe it briefly?

    Why should you use parametrized constructor with servlet? If you want to pass any parameter then use <init-param> in web.xml. Even if you make parameterized constructor, how it would be invoked? Servlet container creates instance of servlet by invoking common constructor.
    So do you intent to rewrote container to invoke parameterized constructor?
    Please refer servlet documentation for more information on servlets and it would help you.

  • Shared objects in servlet?

    Consider this code snippet
    public class MyServlet extends HttpServlet {  
    //declare session object
    private HttpSession session;
    public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    session = req.getSession(true);
    // get a value
    String value_of_id = req.getParameter("some_name");
    session.setAttribute("myid",value_of_id);
    Now the question
    Will a new instance of servlet be spawned for each incoming request?
    Is the session object declared in servlet level shared among all servlet instances?
    If Yes, Is there a possibility that the value of 'my_id' for request#1 will be owerwritten by the value set from request#2?

    #1 - No servlets are multithreaded.
    So essentailly there is only instance but many threads processing a request?Correct.
    #2 - Yes All servlets and JSP's in the same servlet context can access a session.
    Will the servletcontext for servlet-thread#1 be the same as servletcontext for servlet-thread#2
    Yes. Servlet context is the webapp the servlets are running.
    http://localhost:8080/test/servlet/myServlet
    Here the context is /test.
    #3 - No. The servlet container assigns each session a unigue id so that each request will only access the session associated with requests from a specific browser.
    So essentially the concept of shared objects apply to Httpsession objects?
    When the servlet encounters request.getSession() it checks the request for a session cookie. It takes the session id from the cookie and retrieves the HttpSession object for that request. The servlet is multi threaded but each thread has it's own copy of the local variables so as long as you do not put the session object in a global variable each request will see a seperate session object. Therefore sessions are not shared objects.
    A request is a thread.

  • In which way Servlet implements  multiThread  without servlet implement Run

    Hi,
    In which way Servlet implements multiThread without servlet implement Runnable.
    In general servletconaainer use one instance of servlet to handle multiple request(except implement SingleThreadmodal).
    I thing that conatainer can achive this ,in this Way
    Myservlet ms;
    1st Way:
    For each new request container call
    new Thread(){
    puvlic void run(){
    ms.service(request,response);
    }.start();
    but I do not thing in this way we get any performace.
    It is better creat pool of Myservelt. and get object from this
    ms1,ms2,ms3
    2nd way is
    Myservlet implement Runnable
    and for each request
    new Myservlet ().start();
    Please tell me In which way conatiner achive multithread of servlet
    Siddharth Singh([email protected])

    You don't need to do any of this. The servlet container starts its own threads, and they call the servlet methods as required. All you have to do is syncrhonize your servlet internally as required to protect anything that needs protecting from multiple threads.

  • Session Tracking between two tomcat instances

    Hi.
    Am using two different tomcat instances. i want to pass a username from one context to another thru jsp/servlet. can anybody help me without the knowledge of cookies...
    for ex:
    webapps
    - app1
    - app2
    i want to pass username from app1 to app2.
    thanks

    Yep,
    In the servlet on ServerA have setSession and getSession methods.
    When you create the session and when you add to it, call setSession:
    setSession(session);This is what the setSession method looks like
    public void setSession(HttpSession session)
      this.session = session;
    }When servletA calls servletB, pass an instance of servletA to it.
    ServletB b = new ServletB(servletA);servletB's contructor:
    public ServletB(servletA)
      this.servletA = servletA;
    }Now you can call ServletA's getSession method from ServletB:
    session = servletA.getSession();and this is what ServletA's getSession looks like:
    public HttpSession getSession()
      return session;
    }

  • Servlet Life Cycle. .can anybody say whether this is correct or not

    Hello everyone
    Servlet Life Cycle.This is what i understood .can anybody say whether this is correct or not
    According to sevlet specification,servlet life cycle has 4 stages
    1)Loading and instantiation
    2)Initialization
    3)service the request
    4)destroy
    When we start webcontainer, webcontainer looks for deployed web applications and reads deployment descriptor of each web application.In the process of reading web.xml webcontainer container creates servletcontext object for holding context parameters and servletconfig object for holding servlet init-parameters after finding the servlet classes of the web application.
    After finding the servlet classes webcontainer loads the servlet classes.
    Loading can be done in 2 ways
    1)When Webcontainer starts(loads) the webaplication by using load on startup in web.xml.
    or
    2)when first request comes for the webapplication
    Say webcontainer starts the webaplication by using load on startup in web.xml ,Webcontainer creates an instance of servlet class and call init method of GenericServlet class by passing ServletConfig as parameter to init method i.e init(ServletConfig config).The code that is part of this init method initilize the ServletConfig variable of GenericServlet class and call init() method of GenericServlet class.
    So when a request comes,webcontainer creates HttpServletRequest object,
    HttpServletResponse object ,identifies the servlet class based onthe URL and
    allocates a thread for the request and calls
    service(ServletRequest req,ServletResponse resp) of HttpServlet class by
    passing HttpServletRequest object, HttpServletResponse object as arguments.
    Since req,resp are of type ServletRequest,ServletResponse they are type
    casted to HttpServletRequest , HttpServletResponse and calls
    service(HttpServletRequest req,HttpServletResponse resp) of HttpServletand
    here request method is determined and either doGet()/doPost() methods are executed.
    And finally when desroy method is called.

    Mostly, but a servlet that has been initialized may service any number of 0 or more requests before being destroyed. So the life cycle might be:
    1) Load
    2) Initialize
    3) Service a Request
    4) Destroy
    or
    1) Load
    2) Initialize
    3) Service a Request
    3) Service a Request
    3) Service a Request
    3) Service a Request
    3) Service a Request
    3) Service a Request
    3) Service a Request
    3) Service a Request
    3) Service a Request
    3) Service a Request
    3) Service a Request
    4) Destroy
    or
    1) Load
    2) Initialize
    4) Destroy
    For any given <servlet> definition, you might have a combination of all:
    1) Load (instance 1)
    2) Initialize
    4) Destroy
    1) Load (instance 2)
    2) Initialize
    3) Service a Request
    3) Service a Request
    3) Service a Request
    3) Service a Request
    3) Service a Request
    3) Service a Request
    3) Service a Request
    3) Service a Request
    3) Service a Request
    3) Service a Request
    3) Service a Request
    4) Destroy
    1) Load (instance 3)
    2) Initialize
    3) Service a Request
    4) Destroy
    And for some Servlets with special configurations you might get:
    1) Load (instance 1)
    2) Initialize
    1) Load (instance 2)
    2) Initialize
    1) Load (instance 3)
    2) Initialize
    3) Service a Request (instance 1)
    3) Service a Request (instance 2)
    3) Service a Request (instance 3)
    3) Service a Request (instance 2)
    3) Service a Request (instance 2)
    3) Service a Request (instance 2)
    3) Service a Request (instance 1)
    3) Service a Request (instance 2)
    3) Service a Request (instance 2)
    3) Service a Request (instance 3)
    3) Service a Request (instance 1)
    4) Destroy (instance 1)
    3) Service a Request (instance 2)
    4) Destroy (instance 3)
    4) Destroy (instance 2)
    Finally, if you have multiple <servlet> entries in the web.xml (maybe with different servlet names and mappings) then you could have multiple parallel chains of this sort of life-cycle.
    The key concept you have is correct. But once you understand that it is important to know that you really have no control over the lifecycle of the Servlet and that you should not assume anything about it.

Maybe you are looking for

  • Background Scheduling in R3

    Hi All, Can we create Process chains in R/3.If means how? Can we call process chains in R/3 means Background scheduling? Please give information regarding this? Thanks, Mahesh

  • Does anybody know if it is ok to use a standard travel adaptor with macbook magsafe 85w power supply?

    I am moving to New Zealand and want to take my macbook pro with me. I have a Magsafe 85w power supply. I am aware of the apple travel kit. Do i need to purchase this, or is a standard travel adaptor safe? Do i need a lower watt magsafe power supply?

  • Weblogic console doesn't start

    Hi all, Sorry if this is a wrong place...I am new to weblogic. I have weblogic 9.2 installed in my PC and I tried to configure servers in the console and I restarted the weblogic server. Now when i try to log into localhost:7001/console it says "+*A

  • ZCM 11.2.4 in a VMWare View VDI environment

    We have been running 11.2.4 in our View VDI environment and overall been very successful. We just rolled Win 7 and are seeing approx. 10% of the VMs with the zenworkswindowsservice.exe running steadily around 50% for hours. Any thoughts? One thing I

  • How long does it take for apply to activate your iPhone number for imessage?

    I restored my iphone and now it won't let me iMessage anyone and it says it's waiting for activation.  How long does it take for apple to activate my phone number for imessage?