Posting to a servlet from a class in a jar on the server

I'm trying to modify a 3rd party applet that displays documents pulled from a database to post back to the server whenever the user pages up/down into a new document. The primary functionality of the applet is in place and working, the only change I am trying to make is to get the applet to post back to the server when the document being viewed changes so that we can keep track of documents open on the server side.
The document viewer in the applet does have documented, though limited, ways to modify its functionality through properties files. I've added page up/down buttons to the correct properties file and specified button implementation classes as is dictated by their documentation. However, the problem I've run into is that since these page up/down classes are supposed to be placed in a jar file on the server and sent to the applet via the ARCHIVE parameter of the APPLET tag; these classes can not actually submit a post request back to the servlet.
Since these classes exist outside of the world of the web app and applet, they don't have access to any of the connection, session, or cookie info in order to have an address to post back to, much less hold the correct session during the post. I tried hard-coding a URL to send the post request to for the sake of testing, but I'm still not seeing the post request being sent to the servlet. Here is the code I used to post the request, just in case it's a stupid mistake on my part.
URL localURL = new URL("http://localhost:8080/appDir/ServletName");
                localURLConnection = localURL.openConnection();
                localURLConnection.setRequestProperty("method", "POST");
                localURLConnection.setDoOutput(true);
                Properties paramProperties = new Properties();
                paramProperties.put("command", "nextDocument");
                OutputStream localOutputStream = paramURLConnection.getOutputStream();
                ObjectOutputStream localObjectOutputStream = new ObjectOutputStream(localOutputStream);
                localObjectOutputStream.writeObject(paramProperties);
                localObjectOutputStream.flush();
                localObjectOutputStream.close();While searching to find out why this code isn't posting to my servlet, I've been wondering about the viability of this approach as a whole as well. Ideally if I wanted to add a post request to an event generated by the applet, then I would want to modify the applet. But since the applet is in a 3rd party jar file, I've been trying to do things their way. However, assuming I could get the page up/down action classes to post correctly, wouldn't I need some way of preserving the session that this action came from so that the right user's applet would be updated with the right document? The first thought that comes to mind on this involves writing out session/cookie data to temporary files on the server, but this sounds very ugly and insecure; plus I'd have to worry about making sure the files were uniquely named and that this unique name could be used in the page up/down classes. Is there a better way that I could be doing it?
I apologize for the long winded explanation, but if anyone has any thoughts on either why my post request isn't going through or on the absurdity of my solution (and hopefully an alternate idea I could try), I'd be very appreciative.
Thanks in advance.

Well, when I've done URL connections from an applet session and cookies seem to have sorted themselves out. I'm not sure how, but there seems to be some functionality for it in the URLConnection class.
I haven't tried setting the method like this, I always cast to HttpURLConnection and call setMethod to select POST. Your way might be right as well though.
Have you checked the server access logs?
It may be that your URL is rejected by the security manager for not having the same form of the hostname as the original applet retrieval.
You should be able to get a domain name and port from the "code source" of your code, which will reference the online jar it comes from. You can generally get at this as getClass().getProtectionDomain().getCodeSource().getLocation(), or less elegantly by requesting the current class file as a resource.

Similar Messages

  • Calling Servlet from Java Class in eclipse

    Hi ,
    I am calling a Servlet from JAVA Class as I am using IDE: Eclipse. The Problem is below
    URL url = new URL(ServletPath);
    URLConnection connet = url.openConnection();
    I am using the above code in JAVA to Connect to Servlet I have given Print statement in Servlet such that whenever it calls it prints on Console but when I try to run the code the Statement is not printed in the Console of eclipse I think URL connection is not able to establish any connection ..... if any has solution for this please reply
    Thanks & Regards,
    Arvind

    I am calling a Servlet from JAVA Class as I am using IDE: Eclipse. The Problem is below
    URL url = new URL(ServletPath);
    URLConnection connet = url.openConnection();Why should the Servlet running in different Runtime print on your Eclipse Runtime. Please be more clear about the question.

  • Call a function in servlet from java class.

    Hi,
    I am implementing a client/server technology by trying to convert a java desktop client into Browser based. As part of user authetication the only way I know that a username /password does not match is from the servers message as i dont have documentation of the backend servers database.
    Here is a fucntion which receives lines form server.
    public class ServerComm{
    public synchronized void receiveMessage(String  serverMessage){
    if (serverMessage.equals("Login-Fail"))// Login-Fail is message from server if login fails
    LoginHandler.loginFail()//Login Handler is a servlet
    return
    }The Login Handler servlet is as follows.
    public class LoginHandler extends HttpServlet {
        /** Initializes the servlet.
        public void init(ServletConfig config) throws ServletException {
            super.init(config);
        /** Destroys the servlet.
        public void destroy() {
        /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
         * @param request servlet request
         * @param response servlet response
        protected synchronized void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    //some expressions.       
       //this is reached if login fails.
        public static void  loginFail(){
            HttpServletResponse response;
        //redirected to wronglogin web page.  
      response.sendRedirect("/mCVW/wronglogin.jsp");
        /** Handles the HTTP <code>GET</code> method.
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            processRequest(request, response);
        /** Handles the HTTP <code>POST</code> method.
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            processRequest(request, response);
       }Now there is problem in loginFail() method in LoginHandler servlet does not work with the type of response decleration . I need some assistance from any one to make this work or propose a better solution for determining the user authetication with the restriction i have.
    Thank you.

    hmm...I haven't tried this before...but does this work by any chance?
    In your ServerComm class, create new HttpServletRequest and Response objects and get a RequestDispatcher object from request.
    Eg : if (serverMessage.equals("login-fail"){
    HttpServletRequest request = new HttpServletRequest ();
    HttpServletResponse response = new HttpServletResponse ();
    request.setAttribute("function_id", "loginFail");
    RequestDispatcher dispatcher = request.getRequestDispatcher("http://servername:port/ServletName");
    //give the complete path of your servlet
    dispatcher.forward(request, response);
    and in your Servlet, get this function_id and if its loginFail, redirect it to wronlogin.jsp...
    public class MyServlet extends HttpServlet {
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException
    String function_id = request.getAttribute("function_id");
    if(function_id.equalsIgnoreCase("loginFail"))
    //forward to ur jsp
    getServletConfig().getServletContext().getRequestDispatcher(wronlogin.jsp").forward(request, response);
    }

  • Problem accessing servlet from java class which uses Basic Authentication

    "Hi,
    I am using weblogic 6.1 server. I am calling a servlet file from a class file using HttpURLConnection. This is the code below.
              String theUsername="B1A1Z1T2";
              String thePassword="hlladmin";
              String urlString="http://rsnetserver:113/hll/servlet/CallSSRUpload";
              String userPassword = theUsername ":" thePassword;
              String encoding = new sun.misc.BASE64Encoder().encode (userPassword.getBytes());
              try
                   URL url = new URL (urlString);
                   HttpURLConnection uc=(HttpURLConnection)url.openConnection();
                   int it = 0;
                   while ((it = encoding.indexOf('\n')) != -1
                        || (it = encoding.indexOf('\r')) != -1) {
                             encoding = encoding.substring(0, it)
                             encoding.substring(it 1);
                   uc.setRequestProperty("Authorization","BASIC " encoding);
                   uc.setRequestProperty("SOAPAction", url.toString());
                   System.out.println(uc.getResponseCode());
                   System.out.println(uc.getResponseMessage());
              catch(Exception io)
                   io.printStackTrace();
                   System.out.println("error message........" io.getMessage());     
    In web.xml I have d

    Hello,
    Could you post the stack trace?
    Thanks,
    Bruce
    Vijay Babu wrote:
    >
    "Hi,
    I am using weblogic 6.1 server. I am calling a servlet file from a class file using HttpURLConnection. This is the code below.
    String theUsername="B1A1Z1T2";
    String thePassword="hlladmin";
    String urlString="http://rsnetserver:113/hll/servlet/CallSSRUpload";
    String userPassword = theUsername ":" thePassword;
    String encoding = new sun.misc.BASE64Encoder().encode (userPassword.getBytes());
    try
    URL url = new URL (urlString);
    HttpURLConnection uc=(HttpURLConnection)url.openConnection();
    int it = 0;
    while ((it = encoding.indexOf('\n')) != -1
    || (it = encoding.indexOf('\r')) != -1) {
    encoding = encoding.substring(0, it)
    encoding.substring(it 1);
    uc.setRequestProperty("Authorization","BASIC " encoding);
    uc.setRequestProperty("SOAPAction", url.toString());
    System.out.println(uc.getResponseCode());
    System.out.println(uc.getResponseMessage());
    catch(Exception io)
    io.printStackTrace();
    System.out.println("error message........" io.getMessage());
    In web.xml I have d

  • Accessing a servlet from another class

    Not to confuse anyone too much, but here's the scenario.
    I have a servlet that calles other Java classes which perform various functions. Now can I have one of these classes access the servlet directly, without setting up a socket based connection. What I mean is can I just simply call its methods and have access to the HttpServletResponse/HttpServletRequest objects?
    Usually the servlet gets accessed via an HTTP client where then servlet will call classes it needs to access, where here I have a class accessing the servlet directly.
    I do not have the capability of running servlets at the moment so I cannot just do a quick and dirty test to see how it would be done.
    Any input would be appreciated.

    If you have a servlet that contains methods that
    aren't related to the processing of a request (except
    for initialization) then those methods are in the
    wrong place. I don't know where they should be
    instead, that depends on your design. Perhaps you
    should post some details about what you are trying to
    do here.Currently I have not written code for what I am attempting.
    What I am attempting is quite an unorthodox approach of getting server information via a servlet. However unlike your standard servlet the servlet will be accessed via a java class, rather than being invoked from a URL.
    If I had to use psuedo-code I would put it like this:
    class A{
    public void accessHeaders(){
    // access servlet HttpRequest object.
    // use the object.
    // display header info...etc.
    // main prog.
    class Test {
    public static void main(String[] a){
    A a = new A();
    a.accessHeaders();
    The servlet will be a generic servlet which overrides a doGet().
    That's right an app accessing a servlet. I have done this but using the java.net package but I don't want to use that in this case. Can I implicitely call the servlet?
    Now the more I think about doing something like this the more I feel that it cannot be done this way.
    I am new to servlets so I don't know all the ways they can be used.

  • Calling Servlet from Java-Class

    Hi,
    I have a normal java-class that is working with request/response Objects. From within this class I want to call a local servlet, let it do some work with the request and the response and then return it to the class.
    I guess the RequestDispatcher can only be called from within a Servlet, but my class is not a servlet.
    The getServlet()-method is not working any more.
    Maybe somebody has an idea.
    Thanks a lot,
    Matthias

    Hi,
    I have a normal java-class that is working with
    request/response Objects. From within this class I
    want to call a local servlet, let it do some work with
    the request and the response and then return it to the
    class.
    I guess the RequestDispatcher can only be called from
    within a Servlet, but my class is not a servlet.
    The getServlet()-method is not working any more.
    Maybe somebody has an idea.
    Thanks a lot,
    MatthiasThis is not very pretty, so I think you should redessign, but you can open a URLConnection from your class pointing to the URL of the servlet. As far as I know you can't invoke a servlet directly, because you can't get a reference to it, it can only be invoked by the container...

  • CGLIB generation from signed classes(in signed jar) = SecurityException

    Good Day!
    I have the following problem:
    My project uses a number of JARs signed with a jarsigner tool from JAVA distribution package including hibernate2.jar (the jar with all the hibernate stuff), spring.jar and cglib.jar (I think, exact names doesn't matter). All this jars are signed off course for security reasons.
    Then, I have my project working with Hibernate, and it uses lazy-initialized ORM-classes, so Hibernate tries to generate a proxy via CGLIB for these classes. But during initialization of Hibernate SessionFactoryImpl I'm getting a java.lang.SecurityException:
    java.lang.SecurityException: class "cern.spsea.hibernatebeans.BeamFileHibernateBean$$EnhancerByCGLIB$$773cc7e9"'s signer information does not match signer information of other classes in the same package
    cern.spsea.hibernatebeans.BeamFileHibernateBean is one of my ORM-classes and all my classes are not signed because they are in development (they are not in jar, so they can not be signed).
    I think it happens because signed code (from hibernate.jar and cglib.jar) tries to generate another signed code (cern.spsea.hibernatebeans.BeamFileHibernateBean$$EnhancerByCGLIB$$773cc7e9) but relate it to my unsigned package (cern.spsea.hibernatebeans).
    So, I have a couple of questions:
    1. Does signed code generates also signed code?
    2. If so, what can I do for development? I really need to avoid this problem only at development, because at release my classes will be also in the signed jars. Can I force CGLIB to generate not signed classes? Is it some options in JVM start command to skip security checking? May be something else?
    Any help is appreciated!
    Thanks a lot in advance!
    Roman

    I've got the same problem, if someone could help us he'll be very helpful.
    Regards,
    Alx

  • Writing from a BLOB to a FIle on the Server

    I need to be able to save the data from a BLOB column to an external file on the server, preferably in a temporary directory. Afterwards I will add a header to the file and send to the web client. I believe I know how to add the header. However, everything I have read in DBMS_LOB or UTIL_FILE describes saving a BFILE or CLOB to a BLOB, but not the reverse. Can you save from a BLOB to an external file on the server? The processing must be done on the Server.
    I have been able to select TEXT from a VARCHAR column and save to a file on the server but unable to select a BLOB and save to the file.
    Thank you for your help,

    UTL_FILE would be the correct thing to use, but I seem to recall that it didn't work for binary files. It apparently adds CR LF data into the files when written. I am not sure if this has changed recently or not. You might try posting in the database or PL/SQL forum about UTL_FILE.

  • Scripting from VBA when scripting is disabled on the server?

    Hello All,
    I am wondering if it is possible to perform GUI scripting from Excel or MS Access when the scripting functionality has been disabled on the server?  I know it is not possible using the Script Recording and Playback, but not sure within VBA?
    If possible, can anyone please provide examples?  That would be a great help.
    Thanks!
    Emil Jakupovic

    HI
    I have been able to use Visual basic scripting  (*.VBS)  to automate sapgui to a certain extent . see the code below this allows u to logon to sap and use certain transactions using the "sendkeys" function even if scripting is diabled on the sap server. but the functionality is limited like you cant use it in background mode etc so see if this helps
    set objShell = CreateObject("WScript.Shell")
    '===Activate SAP logon pad engine
    set application = CreateObject("Sapgui.ScriptingCtrl.1")
    '===Initiate one of the predefined SAPlogon pad connection
    set SapGui = GetObject ("SAPGUI")
    set application = SapGui.GetScriptingEngine
    set connection = application.OpenConnection("<SERVER DESRIPTION AS IN SAP LOGON PAD>", True)
    WScript.Sleep(10000)
    objShell.SendKeys "<USERNAME>"
    objShell.SendKeys "{TAB}"
    objShell.SendKeys "PASSWORD"
    objShell.SendKeys "{ENTER}"
    WScript.Sleep(10000)
    objShell.SendKeys "/nSP01"
    objShell.SendKeys "{ENTER}"

  • TS2621 From my iPad I get CannotConnect To The Server error message. The iPad is new and I have never received an email via the icloud acct. My PCM receives icloud mail, no problem. Internet connectivity not an issue.

    From my iPad I get an error message "cannot connect to the server". Internet connection not the problem. No problem receiving mail from icloud on my PC. I think it was a set up issue. iPad is new and receives mail from hotmail no problem. It just will not connect to the icloud server.

    I am having this same issue.  I can access these accounts from computers, other locations on others' computers, but I cannot get the mail from one account on either my iPhone or iPad.  I've deleted the account on the iPad and re-installed it, but it still will not receive mail.
    Frustrating.

  • How can i erase my .me mails from my iPhone and keep them in the server

    how can i erase my .me mails from my iPhone and keep them in the server

    You can't. The iPhone doesn't actually store all your emails anyway. It is showing you what is on the server directly.
    Only the most recently accessed emails are cached (stored temporarily) on your phone for access when you are offline. If you delete an email from your iPhone, you are actually deleting it from the server.

  • Post to a servlet from a PL/SQL procedure

    I would like to know if it's possible to post a form from pl/sql. There is this servlet that does stuff but it doesn't have any api i can call so i can only post the parameters to the servlet using an html form. Each form element is added to the http header so i just have to create a header and send it to the servlet but i don't really know how to do this using pl/sql.

    Meanwhile i have found the solution myself.
    This is the snippet that sends a post form to a webpage:
    declare
    v_url varchar2(400) := 'myUrl';
    v_post varchar2(4000);
    HTTP_REQ    utl_http.REQ;
    HTTP_RESP   utl_http.RESP;
    begin
    v_post := 'param1=value1&param2=value2';
    HTTP_REQ := utl_http.BEGIN_REQUEST(v_URL, 'POST', 'HTTP/1.1');
    utl_http.SET_HEADER(HTTP_REQ, 'Content-Type', 'application/x-www-form-urlencoded');
    utl_http.SET_HEADER(HTTP_REQ, 'Content-Length', length(v_post));
    utl_http.WRITE_TEXT(HTTP_REQ, v_post);
    HTTP_RESP := utl_http.GET_RESPONSE(HTTP_REQ);
    end;This post the parameters and values from v_post to the url. In the HTTP_RESP i get the status_code so i can check if it's ok or there was a server error (code 500).

  • I sent an email from my phone, when I log into the server on my desktop, the email doesnot show up in the sent folder. What settings do I need to sync?

    Basically, when I search for messages I have sent from my phone on the desktop, Thunderbird client cannot find them. What settings doI need to employ to sync the phone with Thunderbird? Thanks.

    Since, POP accounts do not synchronize folders, the first step is to make sure your account connection is set up to use IMAP on all devices. Assuming that is an option with your account.

  • Archiving Information from "old" SAP systems and switch off the server

    Good day
    I hope someone can offer some advice. Our company has a few sites across the globe. Three of the sites in South Africa ( where I'm working at the moment ) had their own SAP systems. Three odd years ago, we implementeted a new SAP system, combining the separate SAP systems into the new one, running of the same box etc etc. The "old" SAP systems were still availbale after the new one went live, in the event that people want to look back at history.
    We are you busy with a project where we are going to merge our current SAP implementation into our global SAP system... obviously only the current master data are going to be transfered to the new system. It's an idea time for us to clean up our data.
    My question: Once we go live on our global SAP system, we want to "export" or archive from the 3 "old" SAP systems the Master Data from the HR module ( like employees who's left the company - it's law to keep the records for 5 years at least once a employee has left) , HSEC and FI modules into a single datastore... this way we don't have to keep the three servers running in the event that history is required. The servers wil be kept off-line and only switched back on if a detailed audit is required.
    The global SAP system does not have an archive solution implemented to we can't access archived data from the new system...
    So, we need to export master data from our 3 old SAP boxes into a Unicode type file system, and our local South African sites needs to be able to access the information using a text type editor or a web based interface we can run off our SAP Portal...
    Thank you

    Hello Cornelius,
    To introduce myself, I am an active SDN/BPX member as well as an ASUG Archiving and Information Lifecycle Management Volunteer.
    Decommissioning Legacy Systems (SAP and non-SAP systems) is quite the topic these days with divestitures becoming such a common occurrence. 
    Some things to think about in this situation are:
    Identifying the data to be decommissioned:
    what information would be needed for an audit
    what information would be needed for a lawsuit situation
    Identifying the access requirements to this data.
    Identifying the retention policies for this data (this will be
    driven by regulatory requirements, etc.).
    If this has not already been done - define retention periods for this data - it will most likely have different retention periods based on the type of data.
    You mention that you do not have an archive solution in place yet. 
    I would recommend that you may want to research that option because typical requirements for retaining legacy data is that it is stored in such a manner so that it is protected from any type of modification.
    There are a lot of 3rd party archiving/storage solutions that provide this type of secure storage.
    You are correct in that you will want to export or archive the legacy data as opposed to loading the data into your current system.  It would probably involve a large increase in the size of your SAP database and you would probably run into number range overlaps.
    But, if this data is exported to a filesystem, you will be losing the business logic associated with the data, and the information is no longer in its original format (this could have legal ramifications). 
    I would recommend using SAP Archiving functionality for this effort.  If you are looking for outside resources, there are many vendors out there that have a lot of experience with these types of projects.
    Two that come to mind are Dolphin IT and OpenText.
    Or, depending on the timeline of your project, SAP is coming out with a tool that can be used for decommissioning SAP Systems.  It is part of
    their SAP ILM solution.  It will be called Retention Warehouse.  Here is a paragraph from their latest white paper describing this new tool:
    With the retention warehouse, SAP now offers a
    standardized method for system decommissioning in
    answer to these pressing issues. It allows you to reuse the archived data outside the original system in a central
    retention warehouse.
    For more detail on this topic, the white paper can be found on the SAP ILM Website:
    service.sap.com/ilm
    This tool is part of a larger initiative from SAP to help customers with their ILM (Information Lifecycle Management) strategy.  This tool is near and dear to me as I was fortunate enough to be part of an
    ASUG Influence Council that helped with some of the requirements for this solution.
    I hope this information is useful. 
    Good luck and Best Regards,
    Karin Tillotson

  • Weird classpath issue in EAR.Some classes can access jars that others cant!

    Hi,
    I'm experiencing a very frustrating problem that's proving to be a bit of a show stopper for me. I would really appreciate some help...
    I have an EAR deployed successfully on Sun Appserver 8 which passes the tests from the sun EAR verifier tool. The ear contains a jar file that I built which has a stateless session bean, home, remote interfaces and rmi stubs, deployment descriptors, as well as some utility classes. The EAR also contains some third-party jars such as Hibernate, Log4-j, apache-commons etc etc. The jar I built has in it's manifest file, the classpath information to reference the other jars in the ear.
    The problem I am having is that one of the classes in a third-party jar (hibernate3.jar) cannot see a class in another of the third party jars (log4j-1.2.8.jar) and as a result is throwing a NoClassDefFoundError for org/apache/log4j/Layout while trying to initialise - the two jars are at the root of the EAR.
    Furthermore, my utility classes can access and use Log4j classes without any problem and logging command from those classes is output successfully to the server console. However, my session bean, which is packaged in the same jar as the utility classes, fails to log anything even though it uses exactly the same logger and log configuration as the utility classses.
    I have tried adding classpath information to the manifest of the EAR so that the third-party jars can pick it up but this makes no difference. Also, according to the EAR verifier tool, you are not allowed to put any classpath information in the EAR manifest.
    I have also tried deploying this in weblogic but am experiencing the same problem.
    If anyone can offer any advice or solutions I would greatly appreciate it.
    :)

    what´s type error have you?
    perhaps external libraries (located in classpath) invoke opsCommon.jar and config-3.0.jar classes. then, classnotfound is normal.
    and... why separate external libraries (opsCommon.jar and config-3.0.jar inside ear, and other in classpath)?

Maybe you are looking for

  • I have an older ibook, safari keeps crashing when I try to navigate beyond my home page. New to mac please help

    I am new to mac and was given an ibook. When using safari it will crash every time I attempt to navigate beyond my homepage, I have done all system update and I am not sure what I need to do. Any ideas, tips, or suggestions would be greatly appreciat

  • How to wrap a line in a table cell in adf

    How do I wrap a line of text in a table cell?

  • Bank balance

    HI Guru's Here in my Client, requirement is, they want  to see the balance of their house bank in day to day(opening balance of day and closing balance of the day) Please guide me is there any T code for get this report with regards Arun Kumar

  • Premiere Pro has stopped working

    Premiere Pro has been working fine everyday since Christmas. I have made no changes to anything on the Computer, but suddenly this evening I get message every time I try to enter Premire Pro.  that Premiere Pro has stopped working and windows is chec

  • Glitch with Audio Level Control

    I've been having this issue for a long time now on several computers and with different versions of FCP, and it's really bothered me lately. At times when I am keyframing audio levels in the timeline, if I add a keyframe to an audio track it will ran