URL object and sockets

I wrote an applet. It connects to a web server and reads in info. Then i got a problem. I used URL class to open a connection (url.openConnection().getInputStream()) to the web resource (http://web site:xxx/data?params). URL internally opens a socket connection to the resource. Sockets are a protected resource in applets and the applet crashed sighting the security manager. The only way to that i know to make it work, is to sign the applet.
Is there any other way to open a stream to this web resource with out opening sockets or any other restricted resources?

I wrote an applet. It connects to a web server and
reads in info. Then i got a problem. I used URL class
to open a connection
(url.openConnection().getInputStream()) to the web
resource (http://web site:xxx/data?params). URL
internally opens a socket connection to the resource.
Sockets are a protected resource in applets and the
applet crashed sighting the security manager. The only
way to that i know to make it work, is to sign the
applet.
Is there any other way to open a stream to this web
resource with out opening sockets or any other
restricted resources?Absolutely, you can use the URL object instead of a socket. A URL object allows you to read anything that a Web server can serve as along as you use the http protocol. Here is an example:
URL theURL = new URL("http://www.there.com/index.html") ;
URLConnection conn = thURL.openConnection() ;
conn.connect() ;
DataInputStream dis = new DataInputStream(conn.getInputStream()) ;
FileOutputStream fos = new FileOutputStream(someOutputFile) ;
int data = dis.read() ;
while (data != -1)
fos.write(data) ;
data = dis.read() ;
dis.close() ;
fos.close() ;The above code needs to be enclosed in a try catch block but that is about all it takes.

Similar Messages

  • URL object syntax error - please help!

    Hi,
    I am trying to add sound to my applets, i am using the URL object and declared an new object called mysong etc... Java compiler is not letting me assign url vale to my object "mysong" code is below for reference:
    <b>code:</b>
    // Use the absolute URL of the sound file
    URL oursong = new URL;
    oursong = "http://www.servername.net/media/sound.mp3";                                    
    AudioClip a = getAudioClip(oursong);<b>error desc:</b>
    /tmp/4230/spaceinvader.java:186: '(' or '[' expected
                                            URL oursong = new URL;
                                                                 ^whats the correct syntax for what im trying to do? - Thank you very much...

    oh, just to clarify some more. I tried doing this change to the source:
    URL oursong = new URL("songname.mp3");
    well this time i got this error:
    /tmp/8154/spaceinvader.java:186: unreported exception java.net.MalformedURLException; must be caught or declared to be thrown
                                            URL oursong = new URL("songname.mp3");

  • Decompile applet and proxify all URL and socket connection and recompile

    Hi,
    Please anybody have idea for the below.
    I need to decomple the applet class file to .java file and need to change all URL and Socket connection to proxify all connections from applet. and recompile the sample applet to make ready to load in browser.
    Thi is to load the applet form the web server through one proxy server. In the proxy server side While loading the applet from web server that applet code need to be changed to modify the URL and connections used in that applet to change the further connection from applet through proxyserver.
    Compile and decompile is not a problem that i can use javac and javap respectively.
    But I want to know how to change all URL and connection in applet. is there any easy way to handle this with out changing the applet code.
    can Anybody help me.
    Thanks and Regards,
    Shiban.

    Not sure how you do that:
    Client <----[HTTPS]-----> Secure Gateway <------[HTTP]------->Web servers
    or
    Internet Explorer/Mozilla <----[HTTPS]-----> proxy <------[HTTP]-------> Google
    Is the above correct?
    If so than what are the proxy settings in IE/Moz, I can specify the proxy address in the
    browsers but not the proxy type (SSL).
    When you want to visit a page like google I gues you just type http://www.google.com in
    the browsers address bar. The browser will figure out how to connect to the proxy.
    Java has got the control panel in the general tabl there is a button "network settings...:"
    I have it to "use browser settings" and this works for me.
    All URL and URLConnections work but the sockets don't (maybe put in a bug report)
    for example games.yahoo.com -> card games -> bridge -> create table
    In the trace I can see:
    network: Connecting http://yog70.games.scd.yahoo.com/yog/y/b/us-t1.ldict with proxy=HTTP @ myproxy/00.00.00.00:80
    network: Connecting socket://yog70.games.scd.yahoo.com:11999 with proxy=DIRECT
    The second one fails because port 11999 is not open (what idiot uses an unassigned
    port for a profesional site is beyond me).
    http://www.iana.org/assignments/port-numbers
    #               11968-11999 Unassiged
    Even if the port was open on the proxy you'll notice with proxy=DIRECT that
    "use browser settings" does not work with socket (bug report??).
    Anyway my advice is to open the java console (windows control panel or javacpl.exe in
    the bin dir of java.home) and make sure it is set to "use browser settings"
    Then enable a full trace:
    To turn the full trace on (windows) you can start the java console, to be found here:
    C:\Program Files\Java\j2re1.4...\bin\jpicpl32.exe
    In the advanced tab you can fill in something for runtime parameters fill in this:
    -Djavaplugin.trace=true -Djavaplugin.trace.option=basic|net|security|ext|liveconnect
    if you cannot start the java console check here:
    C:\Documents and Settings\userName\Application Data\Sun\Java\Deployment\deployment.properties
    I think for linux this is somewhere in youruserdir/java (hidden directory)
    add or change the following line:
    javaplugin.jre.params=-Djavaplugin.trace\=true -Djavaplugin.trace.option\=basic|net|security|ext|liveconnect
    for 1.5:
    deployment.javapi.jre.1.5.0.args=-Djavaplugin.trace\=true -Djavaplugin.trace.option\=basic|net|security|ext|liveconnect
    The trace is here:
    C:\Documents and Settings\your user\Application Data\Sun\Java\Deployment\log\plugin...log
    I think for linux this is somewhere in youruserdir/java (hidden directory)
    Print out the full trace of the exception:
    try{...}catch(Exception e){e.printStackTrace();}
    Then visit the games.yahoo and try to create a new table playing bridge.
    Inspect the trace and see if it works/why it doesn't work.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Sending objects with sockets (and making a mess thereof)

    I'm playing about with client/server interaction and have made a simple program where a server waits for a connection on its given port, accepts a socket connection and every second checks for any input from the client and sends a Point object with co-ordinates to the client
    The client in renders the Point object and every second checks for an updated Point from the server, whenever the left or right arrow keys are used the server is sent the keyevent object to process and change the co-ordinates of the point which will then be sent back
    But it doesn't work, the server thread hangs on the if statement testing for a new object to read. If the code looking for a new object is comented out, the system works perfectly (with the random co-ordinates shown, the Point object itself is held in another class and would be used if the server could read the input)
              try
                   ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
                       ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
                       boolean temp = true;
                       while (temp == true)
                        sleep(1000);
                        Object o = in.readObject();
                        if (in.readObject() != null)
                             parent.process.updatePoint((KeyEvent)in.readObject());
                        out.writeObject(new Point((int)(Math.random() * 200), (int)(Math.random() * 200)));
              } Could anyone advise me why it specifically doesn't work? Having said that I realise my design is probably rather inefficient and generally poor and any general tips are welcome to
    Any help appreciated

    I think we are going to need to see the other side of your program. If your code hangs at the if statement:
                        if (in.readObject() != null)
                             parent.process.updatePoint((KeyEvent)in.readObject());
                        }Then i would have to assume the object is never recieved.

  • Cannot send and read objects through sockets

    I have these 4 classes to send objects through sockets. Message and Respond classes are just for
    trials. I use their objects to send &#305;ver the network. I do not get any compile time error or runtime error but
    the code just does not send the objects. I used object input and output streams to send and read objects
    in server (SOTServer) and in the client (SOTC) classes. When I execevute the server and client I can see
    that the clients can connect to the server but they cannot send any objects allthough I wrote them inside the main method of client class. This code stops in the run() method but I could not find out why it
    does do that. Run the program by creating 4 four classes.
    Message.java
    Respond.java
    SOTC.java
    SOTServer.java
    Then execute server and then one or more clients to see what is going on.
    Any ideas will be appreciated
    thanks.
    ASAP pls
    //***********************************Message class**********************
    import java.io.Serializable;
    public class Message implements Serializable
    private String chat;
    private int client;
    public Message(String s,int c)
    client=c;
    chat=s;
    public Message()
    client=0;
    chat="aaaaa";
    public int getClient()
    return client;
    public String getChat()
    return chat;
    //*******************************respond class*****************************
    import java.io.Serializable;
    public class Respond implements Serializable
    private int toClient;
    private String s;
    public Respond()
    public Respond(String s)
    this.s=s;
    public int gettoClient()
    return toClient;
    public String getMessage()
    return s;
    //***********************************SOTServer*********************
    import java.io.*;
    import java.net.*;
    import java.util.Vector;
    //private class
    class ClientWorker extends Thread
    private Socket client;
    private ObjectInputStream objectinputstream;
    private ObjectOutputStream objectoutputstream;
    private SOTServer server;
    ClientWorker(Socket socket, SOTServer ser)
    client = socket;
    server = ser;
    System.out.println ("new client connected");
    try
    objectinputstream=new ObjectInputStream(client.getInputStream());
    objectoutputstream=new ObjectOutputStream(client.getOutputStream());
    catch(Exception e){}
    public void sendToClient(Respond s)
    try
    objectoutputstream.writeObject(s);
    objectoutputstream.flush();
    catch(IOException e)
    e.printStackTrace();
    public void run()
    do
    Message fromClient;
    try
    fromClient =(Message) objectinputstream.readObject();
    System.out.println (fromClient.getChat());
    Respond r=new Respond();
    server.sendMessageToAllClients(r);
    System.out.println ("send all completed");
    catch(ClassNotFoundException e){e.printStackTrace();}
    catch(IOException ioexception1)
    ioexception1.printStackTrace();
    break;
    Respond k=new Respond();
    sendToClient(k);
    }while(true);
    public class SOTServer
    ServerSocket server;
    Vector clients;
    public static void main(String args[]) throws IOException
    SOTServer sotserver = new SOTServer();
    sotserver.listenSocket();
    SOTServer()
    clients = new Vector();
    System.out.println ("Server created");
    public void sendMessageToAllClients(Respond str)
    System.out.println ("sendToallclient");
    ClientWorker client;
    for (int i = 0; i < clients.size(); i++)
    client = (ClientWorker) (clients.elementAt(i));
    client.sendToClient(str);
    public void listenSocket()
    try
    System.out.println ("listening socket");
    server = new ServerSocket(4444, 6);
    catch(IOException ioexception)
    ioexception.printStackTrace();
    do
    try
    ClientWorker clientworker=new ClientWorker(server.accept(), this);
    clients.add(clientworker);
    clientworker.start();
    catch(IOException ioexception1)
    ioexception1.printStackTrace();
    while(true);
    protected void finalize()
    try
    server.close();
    catch(IOException ioexception)
    ioexception.printStackTrace();
    //*************************SOTC***(client class)*********************
    import java.io.*;
    import java.net.Socket;
    import java.net.UnknownHostException;
    class SOTC implements Runnable
    private Socket socket;
    private ObjectOutputStream output;
    private ObjectInputStream input;
    public void start()
    try
    socket= new Socket("127.0.0.1",4444);
    input= new ObjectInputStream(socket.getInputStream());
    output= new ObjectOutputStream(socket.getOutputStream());
    catch(IOException e){e.printStackTrace();}
    Thread outputThread= new Thread(this);
    outputThread.start();
    public void run()
    try
    do
    Message m=new Message("sadfsa",0);
    output.writeObject(m);
    Respond fromServer=null;
    fromServer=(Respond)input.readObject();
    }while(true);
    catch(NullPointerException e){run();}
    catch(Exception e){e.printStackTrace();}
    public SOTC()
    start();
    public void sendMessage(Message re)
    try
    Message k=new Message("sdasd",0);
    output.writeObject(k);
    output.flush();
    catch(Exception ioexception)
    ioexception.printStackTrace();
    System.exit(-1);
    public static void main(String args[])
    SOTC sotclient = new SOTC();
    try
    System.out.println("client obje sonrasi main");
    Message re=new Message("client &#305;m ben mesaj bu da iste",0);
    sotclient.sendMessage(re);
    System.out.println ("client gonderdi mesaji");
    catch(Exception e) {e.printStackTrace();}

    ObjectStreams send a few bytes at construct time. The OutputStream writes a header and the InputStram reads them. The InputStream constrcutor will not return until oit reads that header. Your code is probably hanging in the InputStream constrcutor. (try and verify that by getting a thread dump)
    If that is your problem, tolution is easy, construct the OutputStreams first.

  • How to display URL images and URL link (html) from Smartforms?

    Hi Gurus,
    I'm having difficulty on how to display targeted URL images and URL link from the smartforms, after i sending it out as html mail. The mail i sent just can be preview as a plain text, which can't execute the html code that i put inside the smartforms itself. I follow a few step from this very useful blog.. Hopefully, you guys can give me some solutions or ideas on this.
    /people/pavan.bayyapu/blog/2005/08/30/sending-html-email-from-sap-crmerp -thanks to Pavan for his useful blog.
    My code is like this..
    <--- Start Code.
    FORM call_smartforms.
      DATA : lv_subject TYPE so_obj_des,
             lc_true(1) VALUE 'X',
             lw_control_parameters TYPE ssfctrlop,
             lw_output_options TYPE ssfcompop,
             lc_graphics(8) VALUE 'GRAPHICS',
             lw_xsfparam_line TYPE ssfxsfp,
             lc_extract(7) VALUE 'EXTRACT',
             lc_graphics_directory(18) VALUE 'GRAPHICS-DIRECTORY',
             lc_mygraphics(11) VALUE 'mygraphics/',
             lc_content_id(10) VALUE 'CONTENT-ID',
             lc_enable(6) VALUE 'ENABLE',
             lw_job_output_info TYPE ssfcrescl,
             lw_html_data TYPE trfresult,
             lw_graphics TYPE ssf_xsf_gr,
             lt_graphics TYPE tsf_xsf_gr,
             lv_html_xstr TYPE xstring,
             lw_html_raw LIKE LINE OF lw_html_data-content,
             lv_incode TYPE tcp00-cpcodepage VALUE '4110',
             lv_html_str TYPE string,
             lv_html_len TYPE i,
             lc_utf8(5) VALUE 'utf-8',
             lc_latin1(6) VALUE 'latin1',
             lv_offset TYPE i,
             lv_length TYPE i,
             lv_diff TYPE i,
             lt_soli TYPE soli_tab,
             lw_soli TYPE soli,
             lc_mime_helper TYPE REF TO cl_gbt_multirelated_service,
             lv_name TYPE mime_text VALUE 'sapwebform.htm',
             lv_xstr TYPE xstring,
             lw_raw TYPE bapiconten,
             lt_solix TYPE solix_tab,
             lw_solix TYPE solix,
             lv_filename TYPE string,
             lv_content_id TYPE string,
             lv_content_type TYPE w3conttype,
             lv_obj_len TYPE so_obj_len,
             lv_bmp TYPE so_fileext VALUE 'BMP',
             lv_description TYPE so_obj_des VALUE 'Graphic in BMP format',
             lc_doc_bcs TYPE REF TO cl_document_bcs,
             lc_bcs TYPE REF TO cl_bcs,
             lc_send_exception TYPE REF TO cx_root,
             lw_adsmtp TYPE lty_adsmtp,
             lv_mail_address TYPE ad_smtpadr,
             lc_recipient TYPE REF TO if_recipient_bcs,
             lc_send_request TYPE REF TO cl_bcs,
             lv_sent_to_all TYPE os_boolean.
      DATA : v_language TYPE sflangu VALUE 'E',
             v_e_devtype TYPE rspoptype.
      v_form_name = 'ZTEST_EMAIL'.
      CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
        EXPORTING
          formname           = v_form_name
        IMPORTING
          fm_name            = v_namef
        EXCEPTIONS
          no_form            = 1
          no_function_module = 2
          OTHERS             = 3.
      IF sy-subrc = 0.
       break mhusin.
      ENDIF.
    starting here. ***
    Set title for the output
      lv_subject = 'Smartforms.'.
    Set control parameters to "no dialog"
      lw_control_parameters-no_dialog = lc_true.
    IF lw_service_subject-code = lc_fm1.
    *--- To get output device type
      CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
        EXPORTING
          i_language    = v_language
          i_application = 'SAPDEFAULT'
        IMPORTING
          e_devtype     = v_e_devtype.
      lw_output_options-tdprinter = v_e_devtype.
      lw_control_parameters-getotf = 'X'.
      IF sy-subrc = 0.
       break mhusin.
      ENDIF.
    Set output options
      lw_output_options-xsf        = lc_true.
      lw_output_options-xsfcmode   = lc_true.
      lw_output_options-xsfoutmode = 'A'.
      lw_output_options-xsfoutdev  = space.
      lw_output_options-xsfformat  = lc_true.
      lw_xsfparam_line-name  = lc_graphics.
      lw_xsfparam_line-value = lc_extract.
      APPEND lw_xsfparam_line TO lw_output_options-xsfpars.
      lw_xsfparam_line-name  = lc_graphics_directory.
      lw_xsfparam_line-value = lc_mygraphics.
      APPEND lw_xsfparam_line TO lw_output_options-xsfpars.
      lw_xsfparam_line-name  = lc_content_id.
      lw_xsfparam_line-value = lc_enable.
      APPEND lw_xsfparam_line TO lw_output_options-xsfpars.
    Get the smartform content
      CALL FUNCTION v_namef
        EXPORTING
          control_parameters   = lw_control_parameters
          output_options       = lw_output_options
    *pass other application specific parameters (eg order number, items ).
      IMPORTING
          job_output_info    = lw_job_output_info
      TABLES
          tt_tabh              = tt_tabh
          tt_tabb              = tt_tabb
          tt_tabf              = tt_tabf
      EXCEPTIONS
          formatting_error = 1
          internal_error   = 2
          send_error       = 3
          user_canceled    = 4
          OTHERS           = 5.
      IF sy-subrc = 0.
       break mhusin.
      ENDIF.
      lw_html_data  = lw_job_output_info-xmloutput-trfresult.
      lt_graphics[] = lw_job_output_info-xmloutput-xsfgr[].
      CLEAR lv_html_xstr.
      LOOP AT lw_html_data-content INTO lw_html_raw.
        CONCATENATE lv_html_xstr lw_html_raw INTO lv_html_xstr IN BYTE MODE.
      ENDLOOP.
      lv_html_xstr = lv_html_xstr(lw_html_data-length).
      CALL FUNCTION 'SCP_TRANSLATE_CHARS'
        EXPORTING
          inbuff       = lv_html_xstr
          incode       = lv_incode
          csubst       = lc_true
          substc_space = lc_true
        IMPORTING
          outbuff      = lv_html_str
          outused      = lv_html_len
        EXCEPTIONS
          OTHERS       = 1.
    *HACK THE HTML CODE GENERATED BY SMARTFORM TO MAKE THE
    *EXTERNAL IMAGES APPEAR AS <IMG> TAG IN HTML
      REPLACE ALL OCCURRENCES OF '<IMG' IN lv_html_str WITH '<IMG' IGNORING CASE.
      REPLACE ALL OCCURRENCES OF '/>' IN lv_html_str WITH '/>' IGNORING CASE.
      REPLACE ALL OCCURRENCES OF '</A>' IN lv_html_str WITH '' IGNORING CASE.
      REPLACE ALL OCCURRENCES OF '<' IN lv_html_str WITH '<' IGNORING CASE.
      REPLACE ALL OCCURRENCES OF '>' IN lv_html_str WITH '>' IGNORING CASE.
    CALL METHOD html_control - >load_mime_object
       EXPORTING
         object_id  = 'ZWN'
         object_url = 'ZWN.GIF'
       EXCEPTIONS
         OTHERS     = 1.
      REPLACE ALL OCCURRENCES OF lc_utf8 IN lv_html_str WITH lc_latin1.
    REPLACE ALL OCCURRENCES OF lc_utf8 IN lv_html_str WITH 'iso-8859-1'.
       break mhusin.
      lv_html_len = STRLEN( lv_html_str ).
      lv_offset = 0.
      lv_length = 255.
      WHILE lv_offset < lv_html_len.
        lv_diff = lv_html_len - lv_offset.
        IF lv_diff > lv_length.
          lw_soli-line = lv_html_str+lv_offset(lv_length).
        ELSE.
          lw_soli-line = lv_html_str+lv_offset(lv_diff).
        ENDIF.
        APPEND lw_soli TO lt_soli.
        ADD lv_length TO lv_offset.
      ENDWHILE.
      CREATE OBJECT lc_mime_helper.
      CALL METHOD lc_mime_helper->set_main_html
        EXPORTING
          content     = lt_soli
          filename    = lv_name
          description = lv_subject.
      LOOP AT lt_graphics INTO lw_graphics.
        CLEAR lv_xstr.
        LOOP AT lw_graphics-content INTO lw_raw.
          CONCATENATE lv_xstr lw_raw-line INTO lv_xstr IN BYTE MODE.
        ENDLOOP.
        lv_xstr = lv_xstr(lw_graphics-length).
        lv_offset = 0.
        lv_length = 255.
        CLEAR lt_solix[].
        WHILE lv_offset < lw_graphics-length.
          lv_diff = lw_graphics-length - lv_offset.
          IF lv_diff > lv_length.
            lw_solix-line = lv_xstr+lv_offset(lv_length).
          ELSE.
            lw_solix-line = lv_xstr+lv_offset(lv_diff).
          ENDIF.
          APPEND lw_solix TO lt_solix.
          ADD lv_length TO lv_offset.
        ENDWHILE.
        CONCATENATE lc_mygraphics lw_graphics-graphics text-001 INTO lv_filename.
        CONCATENATE lc_mygraphics lw_graphics-graphics text-001 INTO lv_content_id.
        lv_content_type = lw_graphics-httptype.
        lv_obj_len      = lw_graphics-length.
    *Add images to the email
        CALL METHOD lc_mime_helper->add_binary_part
          EXPORTING
            content      = lt_solix
            filename     = lv_filename
            extension    = lv_bmp
            description  = lv_description
            content_type = lv_content_type
            length       = lv_obj_len
            content_id   = lv_content_id.
      ENDLOOP.
      TRY.
          lv_subject = lv_subject.
          lc_doc_bcs = cl_document_bcs=>create_from_multirelated(
                   i_subject          = lv_subject
                   i_multirel_service = lc_mime_helper ).
        CATCH cx_document_bcs INTO lc_send_exception.
        CATCH cx_bcom_mime INTO lc_send_exception.
        CATCH cx_gbt_mime INTO lc_send_exception.
      ENDTRY.
    Create send request
      TRY.
          lc_bcs = cl_bcs=>create_persistent( ).
        CATCH cx_send_req_bcs INTO lc_send_exception.
      ENDTRY.
      TRY.
          lc_bcs->set_document( i_document = lc_doc_bcs ).
        CATCH cx_send_req_bcs INTO lc_send_exception.
      ENDTRY.
    Set-up email receiver
      lv_mail_address = '[email protected]'.
    TRANSLATE lv_mail_address TO UPPER CASE.
      TRY.
          lc_recipient = cl_cam_address_bcs=>create_internet_address(
              i_address_string = lv_mail_address ).
        CATCH cx_address_bcs INTO lc_send_exception.
      ENDTRY.
      TRY.
          lc_bcs->add_recipient( i_recipient = lc_recipient ).
        CATCH cx_send_req_bcs INTO lc_send_exception.
      ENDTRY.
    Send smartforms as HTML email
      TRY.
          lc_bcs->send( ).
        CATCH cx_send_req_bcs INTO lc_send_exception.
      ENDTRY.
      COMMIT WORK.
      WRITE:/ 'Mail sent'.
    ENDFORM.                    "call_smartforms
    End Code --->
    Thanks and Regards.

    1- put your images in a directory under the web app directory. Example: app/images/
    2- in your jsp, use: String file = application.getRealPath("/images/"); to get the images directory. See http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)
    3- it's not the right forum to post this kind of question. Post them in the JSP/Servlet JSTL forum instead

  • How to store Connection object and call it from other programs.

    Hi,
    I am trying to connect to the database, store the connection object and use this connection object from other standalone java programs.
    Can any one tell me how to do this? I've tried in the following way:
    In the following program I am connecting to the database and saving the connection object in a variable.
    public class GetKT2Connection {
       public static void main(String[] args) {
          String url = "jdbc:odbc:SQLDsn;
          String dbUser = "sa";
          String dbPwd = "sa";
          Connection kt2conn = Connection connection = java.sql.DriverManager.getConnection(url, dbUser, dbPwd);
          if(kt2conn == null) {
             System.out.println("Database Connection Failure!");
          else {
             System.out.println("Connected to Database...");
         GetKTConnectionObj.storeKT2ConnectionObj(kt2conn);
    } Here is the program to save connection object in a variable.
    public class GetKTConnectionObj {
       static Connection kt2Connection = null;
       public static void storeKT2ConnectionObj(Connection conn) {
       kt2Connection = conn;
       public static Connection getKT2ConnectionObj() {
       try {
          return kt2Connection;
       catch(Exception e){
          System.out.println(e);
      return null;
    }Now from the following code I am trying to get the connection object that is stored. But this is throwing NullPointerException.
    public class Metrics_Migration {
      public static void main(String args[]) {
         try {
        java.sql.Connection connection_1 =   GetKTConnectionObj.getKT6ConnectionObj();
         catch(Exception e){
    }

    kt2Connection is null. You need to store it first, to make it not null. Otherwise it will stay null forever. And why on earth are you trying to do this THIS way?
    If you are running the two applications separately, it wont work either.

  • Property List error: Unexpected character b at line 1 / JSON error: JSON text did not start with array or object and option to allow fragments not set.

    Hi,
    I have a MBP 13' Late 2011 and Yosemite 10.10.2 (14C1514).
    Until yesterday, I was using Garmin ConnectIQ SDK and all was working fine.
    Yesterday, I've updated my system with latest security updates and Xcode updates too (Version 6.2 (6C131e)).
    Since, I can't launch the ConnectIQ simulator app, I have this message in console :
    8/04/2015 15:19:04,103 mds[38]: There was an error parsing the Info.plist for the bundle at URL Info.plist -- file:///Volumes/Leto/connectiq-sdk-mac-1.1.0_2/ios/ConnectIQ.bundle/
    The data couldn’t be read because it isn’t in the correct format.
    <CFBasicHash 0x7fa64f44e9a0 [0x7fff7dfc7cf0]>{type = immutable dict, count = 2,
    entries =>
      0 : <CFString 0x7fff7df92580 [0x7fff7dfc7cf0]>{contents = "NSDebugDescription"} = <CFString 0x7fa64f44f0a0 [0x7fff7dfc7cf0]>{contents = "Unexpected character b at line 1"}
      1 : <CFString 0x7fff7df9f5e0 [0x7fff7dfc7cf0]>{contents = "kCFPropertyListOldStyleParsingError"} = Error Domain=NSCocoaErrorDomain Code=3840 "The data couldn’t be read because it isn’t in the correct format." (Conversion of string failed.) UserInfo=0x7fa64f44eda0 {NSDebugDescription=Conversion of string failed.}
    I have looked at this file and it looks like a binary plist
    bplist00ß^P^V^A^B^C^D^E^F^G^H
    ^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\^]^^^_ !"$%&'()'+,^[\CFBundleNameWDTXcodeYDTSDKName_^P^XNSHumanReadableCopyrightZDTSDKBuild_^P^YCFBundleDevelopmentRegion_^P^OCFBundleVersi    on_^P^SBuildMachineOSBuild^DTPlatformName_^P^SCFBundlePackageType_^P^ZCFBundleShortVersionString_^P^ZCFBundleSupportedPlatforms_^P^]CFBundleInfoDictionaryVersion_^P^RCFBundleE    xecutableZDTCompiler_^P^PMinimumOSVersion_^P^RCFBundleIdentifier^UIDeviceFamily_^P^QDTPlatformVersion\DTXcodeBuild_^P^QCFBundleSignature_^P^ODTPlatformBuildYConnectIQT0611[iph    oneos8.1o^P-^@C^@o^@p^@y^@r^@i^@g^@h^@t^@ ^@©^@ ^@2^@0^@1^@5^@ ^@G^@a^@r^@m^@i^@n^@.^@ ^@A^@l^@l^@ ^@r^@i^@g^@h^@t^@s^@ ^@r^@e^@s^@e^@r^@v^@e^@d^@.V12B411RenQ1V14C109Xiphoneos    TBNDLS1.0¡#XiPhoneOSS6.0YConnectIQ_^P"com.apple.compilers.llvm.clang.1_0S8.1_^P^Tcom.garmin.ConnectIQ¡*^P^AW6A2008aT????^@^H^@7^@D^@L^@V^@q^@|^@<98>^@ª^@À^@Ï^@å^A^B^A^_^A?^AT^    A_^Ar^A<87>^A<96>^Aª^A·^AË^AÝ^Aç^Aì^Aø^BU^B\^B_^Ba^Bh^Bq^Bv^Bz^B|^B<85>^B<89>^B<93>^B¸^B¼^BÓ^BÕ^B×^Bß^@^@^@^@^@^@^B^A^@^@^@^@^@^@^@-^@^@^@^@^@^@^@^@^@^@^@^@^@^@^Bä
    I guess it is a normal format but my system seems to be unable to read binary plist ?
    I tried some stuff with plutil
    plutil -lint Info.plist
    Info.plist: Unexpected character b at line 1
    Same for convert
    plutil -convert xml1 Info.plist
    Info.plist: Property List error: Unexpected character b at line 1 / JSON error: JSON text did not start with array or object and option to allow fragments not set.
    I also try to download a fresh version of the connectIQ SDK and no changes.
    Any idea ?
    Thanks

    Step by step, how did you arrive at seeing this agreement?

  • Invalid URL error when displaying Work Item Attached URL Object in UWL

    Hi,
    After upgraded from EP6 to EP7 the user can no longer display the attached URL object of work items in the UWL Inbox.  It works fine in the SAPGUI Inbox so the URL should be okay.  We found below error messages in UWL log file:
    #1.5#0003BA5D298B001E0000030300003A280004314BFE992222#1180102370599#/uwl/ui#sap.com/tcwddispwda#com.sap.netweaver.bc.uwl.ui.control.UWLActionControl#C004049#43497#####SAPEngine_Application_Thread[impl:3]_0##0#0#Warning#1#com.sap.netweaver.bc.uwl.ui.control.UWLActionControl#Plain###com.sap.tc.webdynpro.services.exceptions.InvalidUrlRuntimeException: Invalid URL=HTTP://apinvoice.d51.lilly.com
    gbip
    gbip.asp?po=invoice=TC630400360USERID=USC076601#
    #1.5#0003BA5D298B001E0000030400003A280004314BFE9986AB#1180102370625#/uwl/ui#sap.com/tcwddispwda#com.sap.netweaver.bc.uwl.ui.control.UWLActionControl#C004049#43497#####SAPEngine_Application_Thread[impl:3]_0##0#0#Warning#1#com.sap.netweaver.bc.uwl.ui.control.UWLActionControl#Plain###com.sap.netweaver.bc.uwl.UWLException: Fri May 25 10:12:50 EDT 2007
    (Portal) :com.sap.tc.webdynpro.services.exceptions.InvalidUrlRuntimeException:Invalid URL=HTTP://apinvoice.d51.lilly.com
    gbip
    gbip.asp?po=invoice=TC630400360USERID=USC076601#
    Looks like the error is related to the back slashes in the URL but it was working fine in EP6.  We are going to change the back slashes to forward slashes to see it will work.  We would like to know if any SDNer’s can provide some more detail on why this is happening and if there is other solution.  Any hint will be very appreciated.
    Regards,
    Jiannan Che

    Use link attachment or add button action to UWL as possible workaround. It appears that work item text can only be displayed as-is.

  • Objects in Sockets

    Hi,
    I'm writing a server <-> client application and I have a problem while sending Objects.
    Generally, everything is fine as far as I don't want to send object back and forth. My problem by example:
    - Server creates an object for instance myObject = new MyObject();
    - Server puts an this object on a list myObjectList.add(myObject);
    - Server sends the Object to the client via writeObject
    - Client recives the package myObject = (myObject)input.readObject();
    - Client sets a text in the object myObject.setText("Hello server");
    - Client sends the object back to the server
    - Server gets the object myObjectFromClient = (MyObject)input.readObject();
    and here comes my problem out. Server will be reciving many such objects and he is going to check, which response did he get, but when I'll do a contains() check on a list of MyObjects: myObjectList.contains(myObjectFromClient); I'll get a false in result :(
    Is there any way to recognize same objects when using sockets? one and obvious method is to set a field in an object with an ID and then I'll be able to recognize it when it gets back, but looks very non proffesional to me...
    Thanks in advance
    Maciej

    By recognizing if the objects are the same I mean recognizing which object on the server side is the object that came back from the client (I've send the object earlier to the client).
    Anyway, the idea you suggest seems to be my solution, I can set the ID's as fields in the object and than overload equals() method to compare ID's and everything should work fine with a minimum amount of changes. Thanks!

  • Fetching a URL  from a socket output or input stream in a proxy server

    We have written a proxy server in java .
    It connects with a client on some local port and forwards the request of the client to main server through socket connections.
    The code is as follows...
    * BasicProxyServer.java
    * A simple multithreaded proxy server.
    * A client connects to theserver. The server starts a
    * separate threads for data flow though two Sockets.
    * The first socket communicates with the socket of the client.
    * The second socket is used to communcate with the main server
    * for which this server is a proxy. The sockets are connected by pipes.
    import java.net.*;
    import java.io.*;
    public class BasicProxyServer {
         private static int serverPort;
         private static String primaryServerHost;
         private static int primaryServerPort;
         // 1st arg: port to listen on
         // 2nd arg: primary server IP
         // 3rd arg: primary server port
         public static void main(String [] args) {
              serverPort = Integer.parseInt(args[0]);
              primaryServerHost = args[1];
              primaryServerPort = Integer.parseInt(args[2]);
              BasicServer bserv = new BasicServer(serverPort,primaryServerHost,primaryServerPort);
    class BasicServer extends Thread {
         private int serverPort;
         private String primaryHost;
         private int primaryPort;
         private ServerSocket servSock = null;
         public BasicServer(int port, String primSrv, int primPort) {
              serverPort = port;
              primaryHost = primSrv;
              primaryPort = primPort;
              start();
         public void run() {
              Socket clientSock = null;
              Socket primaryServerSock = null;
              try {
                   servSock = new ServerSocket(serverPort);
              catch (IOException e) {
                   e.printStackTrace();
              while(true) {
                   try {
                        clientSock = servSock.accept();
                        primaryServerSock = new Socket(primaryHost, primaryPort);
                        PipedInputStream fromClient = new PipedInputStream();
                        PipedOutputStream toMainServer = new PipedOutputStream(fromClient);
                        PipedInputStream fromMainServer = new PipedInputStream();
                        PipedOutputStream toClient = new PipedOutputStream(fromMainServer);
                        Talk clientToMainServer = new Talk(clientSock, fromClient, primaryServerSock, toMainServer);
                        Talk mainServerToClient = new Talk(primaryServerSock, fromMainServer, clientSock, toClient);
                        clientToMainServer.start();
                        mainServerToClient.start();
                   catch (IOException e) {
                        e.printStackTrace();
         // Override finalize() to close server socket
    protected void finalize() {
    if (servSock != null) {
    try {
    servSock.close();
    } catch (IOException e) {
    e.printStackTrace();
    servSock = null;
    class Talk extends Thread {
         private Socket incoming;
         private Socket outgoing;
         private InputStream in;
         private OutputStream out;
         private InputStream from;
         private OutputStream to;
         Talk(Socket inSock, InputStream in, Socket outSock, OutputStream out) {
              this.in = in;
              this.out = out;
              incoming = inSock;
              outgoing = outSock;
         public void run() {
              int aByte;
              try {
                   from = incoming.getInputStream();
                   to = outgoing.getOutputStream();          
                   while(( aByte = from.read()) != -1 ) {     //read from socket
                        out.write(aByte);     // write to pipe`
                        // read the byte from the pipe
                        to.write(in.read());          // write it to the output socket stream
                        to.flush();
                   to.close();
                   from.close();
                   if(incoming != null) {
                        incoming.close();
                        incoming = null;
                   if(outgoing != null) {
                        outgoing.close();
                        outgoing = null;
              catch (SocketException e) {
              // there is one for a closed socket. Seems to have no effect.
              //     e.printStackTrace();
              catch (IOException e) {
                   e.printStackTrace();
    Here,when client gives any URL in the address bar in the web browser the request is forwarded to this proxy server.
    We want to fetch the URL which client enters in order to implement content filtering and also store the most visited sites by each user .
    But we don't know how to fetch the URL from the socket input or output stream.
    Can you suggest any suitable solution for the same??

    Shailesh24 wrote:
    We want to fetch the URL which client enters in order to implement content filtering and also store the most visited sites by each user .
    But we don't know how to fetch the URL from the socket input or output stream.
    Can you suggest any suitable solution for the same??Yes. Write a proxy server that actually speaks HTTP.

  • SAP Business Objects and IBM i White Paper available

    The "SAP Business Objects and IBM i" White Paper is available on IBM Techdocs under the follwing URL:
    [http://www.ibm.com/support/techdocs/atsmastr.nsf/WebIndex/WP101947]
    The SAP Business Objects and IBM i white paper describes how the SAP Business Objects Enterprise XI server fits into an SAP on IBM i landscape. The paper provides detailed instructions showing how to integrate data sources located on an IBM i server with SAP Business Objects.
    Feel free to post your feedback and comments.
    Thanks and Regards,
    Mirco
    Edited by: Mirco Malessa on Jul 14, 2011 1:11 PM

    Hi ,
       Please find these blogs by Ingo. This should help you.
    BusinessObjects and SAP - Installation and Configuration Part 1 of 4
    Install Part #1
    BusinessObjects and SAP - Installation and Configuration Part 2 of 4
    Install Part #2
    BusinessObjects and SAP - Installation and Configuration Part 3 of 4
    Install Part #3
    BusinessObjects and SAP - Installation and Configuration Part 4 of 4
    Install Part #4
    BusinessObjects and SAP - Configure SAP Authentication
    SAP Authentication
    BusinessObjects Integration with SAP NetWeaver BI - Technical Material
    Thanks,
    Gopi

  • URL object with https string throws malformed url exception: unknown protocol: https

    In WebLogic I am trying to connect to an HTTPS url by passing that url
    string into the contructor for URL object. This throws a Malformed URL
    Exception : unknown protocol: https.
    When i run this same block of code outside of weblogic (in a stand-alone
    app), it runs perfectly. (not exceptions when creating the URL object).
    why do i get this exception in weblogic?
    could weblogic be loading its own URL class rather than the java.net.URL
    class (which supports ssl)? if so how do i override that classloading?
    is there a weblogic security "feature" that prevents opening an ssl
    connection?
    thanks for any help
    mike
    [email protected]

    You need to modify your weblogic.policy file to allow you to change the
    the property java.protocol.handler.pkgs ... and any other properties
    that you may probably change using JSSE (for example:
    javax.net.ssl.trustStore for storing certificates of servers that you
    want to connect to from WLS )
    Regards,
    John Salvo
    Michael Harrison wrote:
    >
    thanks for the help dennis, but still get the "unknown protocol https".
    the URL object sees that the URLStreamHandler ==null and get the value for
    java.protocol.handler.pkgs (which should be
    com.sun.net.ssl.internal.www.protocol) then it tries to load that class. i
    believe that the GetPropertyAction("java.protocol.handler.pkgs","") is not
    returning com.sun.net.ssl.internal.www.protocol. therefore the class is not
    getting loaded
    i think that my classpath is set up properly for classpath and
    weblogic_classpath so i think that i me calling
    System.setProperty("java.protocol.handler.pkgs",
    "com.sun.net.ssl.internal.www.protocol"); is not effective.
    do you know anyway i can trouble shoot this.
    thanks
    mike
    Dennis O'Neill <[email protected]> wrote in message
    news:39d23c28$[email protected]..
    Https is an add-in so to speak. Try this before you create your url:
    System.setProperty ("java.protocol.handler.pkgs",
    "com.sun.net.ssl.internal.www.protocol");
    // add the default security provider (again, in JSSE1.0.1)
    int iap = java.security.Security.addProvider(new
    com.sun.net.ssl.internal.ssl.Provider() );
    dennis

  • Performance issue in linux while using set with URL object

    Hi,
    I am facing performance issue while using Set(HashSet) with URL object on linux. But it is running perfectly on windows.
    I am using
    set.contains(urlObject)
    Above particular statement is taking 40 sec on Linux, and only a fraction of ms on windows.
    I have checked the jre version on both OS. It is the same version (jre6)
    on both the OS.
    Could anyone please tell me what is the exact reason, why the same statement is taking more time on linux than windows.
    Thanks & Regards
    Naveen

    jtahlborn wrote:
    I believe the URL hashCode/equals implementations have some /tricky behavior which involves network access in order to run (doing hostname lookups and the like). you may want to either use simple Strings, or possibly the URI class (i think it fixed some of this behavior, although i could be wrong).The second new thing I have learned today. I was wrong in reply # 1 because looking at the URL code for 1.6 I see that the hash code is generated from the IP address and this has a lazy evaluation. Each URL placed in a HashMap (or other hash based collection) requires a DNS lookup the first time the hash code is used.
    P.S. 40 seconds does seem a long time for a DNS lookup!
    Edited by: sabre150 on Feb 13, 2008 3:40 PM

  • Cant generate new URL() Object in Dashcode

    As the topic says i im not able to generate a new URL() Object.
    like:
    var url = new URL();
    in Dashcode it says that url is not declared why?

    Hello,
    Thx for the answer but I think I didnt told you why i need the fetch() method.
    The fetch method takes the data(e.g. html) and puts it in a string variable or into a file.
    I need this because I want to make a widget(I finished but one feature is missing) which opens a site and tells you how which trains or busses you need.
    My Problem is that this site needs detailed information and so you have to choose on the site.
    I want to put this choosing into my widget.
    As you recognized the idea is like Ajax.
    But i dont think that xmlhttprequest will work for my problem.
    Is there any other solutions?

Maybe you are looking for