Alternative to (Deprecated)HttpRequest

Now that most of the javafx.io.http package is Deprecated what is the alternative.

http://download.oracle.com/javase/7/docs/api/java/net/URL.html
* Use this to be certain string data is sent in ascii format.
static final Charset ASCII_CHARSET = Charset.forName("US-ASCII");
try {
     * Create the URL object.
    URL url = new URL("http://www.somwebsite.com/thepage.html?some_key=some_value");
    //Create the connection object from the url object.
    URLConnection connection = url.openConnection();
    //Since this is an Http URL, we can cast the URLConnection to something more specific.
    HttpURLConnection httpConnection = (HttpURLConnection) connection;
    //Tell it we are reading and writing.
    httpConnection.setDoInput(true);
    httpConnection.setDoOutput(true);
    //We are sending post headers, so set this appropriately.
    httpConnection.setRequestMethod("POST");
    //Tell it the MIME format of the request.
    httpConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    //Send the post headers.
    OutputStream outputStream = httpConnection.getOutputStream();
    outputStream.write("username=myusername&password=mypassword".getBytes(ASCII_CHARSET));
    outputStream.close();
    //Recieve whatever data here.
    InputStream inputStream = httpConnection.getInputStream();
    inputStream.close();
} catch (IOException ex) { //Something went wrong. Tell us what.
    ex.printStackTrace();
}I was a little distracted when writing this, so there may be errors. If you want to send large files, it gets much more complicated. Had to build my own class for that.
Edited by: aidreamer on Jun 17, 2011 6:38 PM

Similar Messages

  • Looking for alternative to deprecated SortCriterion

    JDev 11.1.1.0.1 + ADF BC + ADF RC
    I have a requirement to be able to access the sort criterion of a rich table from the backing bean of the page that contains the table.
    Currently, I am using the following code I originally wrote in JDeveloper 10.1.3.4 to do so:
    SortCriterion criterion = (SortCriterion)getTechDataTable().getSortCriteria().get(0);
    String sortBy = criterion.getProperty();
    However, the oracle.adf.view.rich.model.SortCriterion object is apparently deprecated, and so is the org.apache.myfaces.trinidad.model.SortCriterion object.
    So, my question is, what alternative is available? As I understand it, objects aren't deprecated unless there is a viable alternative.
    Does anyone know the alternative to use in place of the deprecated oracle.adf.view.rich.model.SortCriterion?
    Thanks All and Happy New Years!

    Where did you find the info that org.apache.myfaces.trinidad.model.SortCriterion is deprecated?
    in the 1.2.11 API docs I found nothing about a deprication.
    For me it looks like you just can use org.apache.myfaces.trinidad.model.SortCriterion instead of oracle.adf.view.rich.model.SortCriterion.
    Timo

  • Finding alternative to deprecation

    hi, i'm learning java sockets programming and i stumble upon these codes...
    import java.net.*;
    import java.io.*;
    public class TestClient2{
         boolean connStat=false;
         Socket sock=null;
         DataInputStream streamIn=null;
         DataOutputStream streamOut=null;
         public TestClient2(){
              try{
                   sock=new Socket("127.0.0.1",1024);
                   System.out.println("Connected to server");
                   streamIn=new DataInputStream(System.in);
                   streamOut=new DataOutputStream(sock.getOutputStream());
                   while(!connStat){
                        try{
                             String line=streamIn.readLine(); //THE OFFENDING DEPRECATED STATEMENT
                             streamOut.writeUTF(line);
                             streamOut.flush();
                             connStat=line.equalsIgnoreCase("bye");
                        catch(Exception err){
                             System.out.println(err);
                             connStat=true;
                   if(streamOut!=null)     streamOut.close();
                   if(streamIn!=null)     streamIn.close();
                   if(sock!=null)          sock.close();
              catch(Exception err){
                   System.out.println(err);
         public static void main(String[]args){
              TestClient2 tc2=new TestClient2();
    }as u can see, the statement with caps comments is the cause of the deprecation during compilation
    i tried to use readUTF, but as a result, the program will just hang
    do u guys know of a better alternative to that statement?
    thx,
    gildan2020

    See the API docs whenever you have a deprecation warning.
    http://java.sun.com/j2se/1.4.2/docs/api/java/io/DataInputStream.html#readLine()
    It says to use BufferedReader.readLine().

  • Alternative for deprecated MethodBinding?

    Hi,
    I was trying to setValueChangeListener on a UI component created using Java and found that the MethodBinding arguement it takes comes from a deprecated class javax.faces.el.MethodBinding.
    What alternative do I have instead?
    Thanks...
    -inder

    similar issue at setActionListener still only takes depreciated MethodBinding, not MethodExp

  • How do I find out user and domain names in WL7.0 security

    Hi,
    I'm moving to WL7.0 security and now weblogic.security.acl.Security.getCurrentUser()
    that worked in CompatibilityMode throws NullPointerException. What is the alternative
    to deprecated weblogic.security.acl.Security in the new Weblogic security framework?
    Also, how can I find the current domain name?
    Thanks,
    Michael.

    "Michael Bogomolov" <[email protected]> wrote in message
    news:3ec515ae$[email protected]..
    >
    Hi,
    I'm moving to WL7.0 security and nowweblogic.security.acl.Security.getCurrentUser()
    that worked in CompatibilityMode throws NullPointerException. What is thealternative
    to deprecated weblogic.security.acl.Security in the new Weblogic securityframework?
    >
    See getCurrentSubject in
    http://e-docs.bea.com/wls/docs81/javadocs/weblogic/security/Security.html
    getCurrentUser only works in compatibilty mode

  • Thread.stop() -- Why is it deprecated ? - What alternatives ?

    Hi,
    I'm creating an XMPP server in Java and I have a problem. I have a thread that run the SAX parser and is constantly blocking to recive data from my socket. Now the problem is that at some point (after the authentication) I need to stop the XML parsing.
    The only way I can do this, I think, is by using the Thread.stop() method, but it is deprecated :(
    I read the FAQ about this deprecation but the alternatives given can't work for me:
    - I can't close the eocket because I need to read another XML document right after on the socket
    - I can't call Thread.interrupt() because the thread is blocking on an IO
    - I can't use a shared variable because the thread is blocked inside the SAX parser that call from time to time a callback. I can't modify the SAX code :(
    Does anyone have an idea how to make my thread stop the parsing ?
    Thanks
    Mildred

    If you've read the "FAQ" on deprecation of stop etc then you already know why stop() is deprecated - it is inherently unsafe as you can't know for sure what your thread was doing when you tried to stop it. Further, what those documents don't tell you is that Thread.stop doesn't break you out of most blocking situations any way - so it wouldn't necessarily help even if it weren't deprecated.
    I don't know the I/O or threading architecture of what you are working with so the following may not be applicable, but hopefully something will help:
    One of the alternatives you didn't mention is setting the SO_TIMEOUT option on the socket so that your thread can periodically check if its actually been cancelled. I don't know if that is possible in this case it depends on how the use of sockets gets exposed by the library.
    Other possibilities for unblocking a thread are to give the thread what it is waiting for - some data on the socket in this case. If you can send something that can be interpreted as "stop looking for more data", or if you check for cancellation before trying to interpret the data at all, then you can unblock the thread by writing to the socket. Whether this is feasible depends on how the real data is written to the socket.
    Final possibility is to create a new thread to do the socket reading. Your parser thread can then read from a BlockingQueue, for example, that is populated with data from the socket thread. You can use interrupt() to cancel the parser thread and just ignore the socket thread - which presumably will unblock when the next real data arrives.

  • DataInputStream: method readLine() is deprecated. (What's the alternative?)

    Hi there,
    I have a DataInputStream object (code below). The code works great but I get a warning message below the code: dis.readLine()
    The method readLine() from the type DataInputStream is deprecated
    does anyone have an alternative to eliminate the warning?
    DataInputStream dis = null;
    String line = null;
    //read
    File f = new File(inputFolder+"/"+inputFileName);
    FileInputStream fis = new FileInputStream(f);
    BufferedInputStream bis = new BufferedInputStream(fis);
    dis = new DataInputStream(bis); 
    while ( (line=dis.readLine()) != null )
    }

    http://java.sun.com/j2se/1.4.2/docs/api/java/io/DataInputStream.html
    readLine()
    Deprecated. This method does not properly convert bytes to characters. As of JDK 1.1, the preferred way to read lines of text is via the BufferedReader.readLine() method. Programs that use the DataInputStream class to read lines can be converted to use the BufferedReader class by replacing code of the form:
    DataInputStream d = new DataInputStream(in);
    with:
    BufferedReader d
    = new BufferedReader(new InputStreamReader(in));

  • APEX_CUSTOM_AUTH deprecated - what are my alternatives?

    Hi,
    We are in the process of moving to 4.2.3 on our production instance which is tightly integrated with our eBusiness Suite. We do not use Oracle SSO.
    The logout URL is currently set using the following code:
    l_return := 'apex_custom_auth.logout_then_go_to_url?p_args='
              ||p_app_id
              ||':'
              ||FND_PROFILE.value('APPS_FRAMEWORK_AGENT')
              ||'/OA_HTML/OA.jsp?OAFunc=OAHOMEPAGE';
    This produces a URL which logs the user out of APEX and sends them back to the Oracle eBusiness Homepage for whichever environment they are currently on. It is the currently recommended best practice according to the Oracle R12 and APEX integration whitepaper.
    How can we achieve a similar redirection using apex_authentication.logout? Would this have to be handled by a public page and a branch now?
    Cheers, Pete

    Hi Pete,
    just to clarify, only the logout functions are deprecated, not the whole package. You are probably using a custom authentication scheme. It contains a "Post Logout Procedure Name" attribute, where you can enter a procedure that redirects to EBS. The procedure can be in the PL/SQL block or in a server-side package. Here is an example:
    procedure redirect_to_ebs
    is
    begin
        apex_debug.enter('redirect_to_ebs');
        sys.owa_util.redirect_url(FND_PROFILE.value('APPS_FRAMEWORK_AGENT') || '/OA_HTML/OA.jsp?OAFunc=OAHOMEPAGE');
        apex_application.stop_apex_engine;
    end redirect_to_ebs;
    The apex_authentication.logout procedure then calls this post-logout procedure at the end.
    Regards,
    Christian

  • Alternative required for IService Configure Method which is Deprecated.

    Hi,
            I wanted to run few programs in EP 7.0 as soon as the User logs or as soon as the portal is started, without User running any thing to activate the functionality. For this, i am using IService (portal service) with Start-up parameter in Service-config set to True.
    But when i implemented IService to create portal service, the Iservice Method
    public void configure(IServiceConfiguration serviceConfiguration) should be implement or atleats left blank.
    But this is marked as deprecated. As i service is Inteface, i am forced to Implement(atleats blank) but are deprecated.
    and also the Class Used as parameter(IServiceConfiguration) in this method is marked as deprecated.
    So the Questions are.
    1. Is there any other way other than using Iservice to make the programe run autamatically, say by using Web dynpro or so on?
    2. Is it OK if i still use Iservice though The method and the class is deprecated.
    3. if i have to skip Iservice, then It will sound like EP 7.0 doesnt Encourage Portal service. Is it Ok If is use or , else please suggest a Way to Bring up the same functionality.
    Thanks..

    Hi ,
    Did you find an alternate for this? I am having the same issue.
    Appreciate your help.
    Thanks.

  • JComponent.setNextFocusableComponent is deprecated - what's an alternative?

    As of JDK 1.4, the JComponent.setNextFocusableComponent is deprecated. The javadocs say it is "replaced by FocusTraversalPolicy". However, FocusTraversalPolicy only has get methods, no set methods. Does anyone know what should be used instead of setNextFocusableComponent?
    Thanks!

    check out this link, it will speede you on your way
    http://www.szptt.net.cn/9810dnwl/new/jfc/ch26/ch26.htm
    Thanks for the link - but it appears to describe deprecated classes and methods (FocusManager for example). Apparently JDK 1.4 brought out some new focus functionality. Anyone know any good references for it?
    Thanks!

  • InvokeAction deprecated: Alternative?

    Hi
    We are using JDeveloper 11.1.2.1
    We want to change the invokeActions that we are using in an application, but only find alternatives to execute actions on page load with method calls. We have invokeActions to execute actions inside of a page to refresh iterators and re-execute queries.
    For example, on select a row in a af:table, to re-execute query and refresh a dependant component.
    Which is the alternative in this case? Override the af:table selectionListener?
    Thanks

    You can either use a task flow and call the method as method activity before navigation to the page, or you call your methods from a bean. 
    Your use car can be done using a generic take selection listener like http://www.oracle.com/technetwork/developer-tools/adf/learnmore/23-generic-table-selection-listener-169162.pdf
    Timo

  • Warning: [deprecation] getRealPath in ServletRequest has been deprecated

    I have extended class HttpServletRequestWrapper for custom implementation I have neither overriden the method getRealPath(java.lang.String) nor has this method been used/accessed anywhere. I still get following warning
    [javac] /home/pangav1/dev/upgrade/webapps/common/src/minimed/ddms/webapp/common/filter/LocaleFilter.java:222: warning: [deprecation] getRealPath(java.lang.String) in javax.servlet.ServletRequest has been deprecated
    [javac] public static class HttpRequest extends HttpServletRequestWrapper {
    [javac] ^
    Can anyone tell me the reason why compiler shows the warning message?

    It should certainly not be ignored, especially if you don't understand the reason of deprecation and don't know the alternatives, which is the case of the topicstarter. In any case of deprecated classes/methods, the reasoning of deprecation and any alternatives should already be described in the API docs.
    [Here is the API doc of ServletRequest#getRealPath()|http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#getRealPath(java.lang.String)]

  • Deprecated methods in java.lang.thread

    Hi,
    I am getting the followng warning message when i run my code:
    The method void stop() in class java.lang.Thread has been deprecated,
    can anyone suggest an alternative method to the deprectaed stop method, i can't seem to find one.
    Thanks in advance

    The stop() method in thread has been deprecated because it is inherently dangerous. The suggested action now is to simply modify a variable inside the thread to tell it to stop running, and the thread should periodically check the variable to see when it should stop. There's good description of why stop() and a few other methods in Thread have been deprecated at..
    http://java.sun.com/j2se/1.4/docs/guide/misc/threadPrimitiveDeprecation.html

  • Deprecated Thread Methods

    My organization has recently come from the Microsoft world into the J2EE world. In .Net, Microsoft has an abort method on threads that is similar to the Java's stop method. Unfortunately, the stop method has been deprecated.
    While I have read the information on why this method is dangerous, I don't understand why the method has been removed. If I have a situation that warrants killing a thread (such as in the case of an application server that hosts other threads of execution), why remove it from the platform? While I agree with Sun's article on seeking out alternative methods, there are still exceptions where a thread just needs to be interrupted so that it can get out of a deadlock, endless loop or blocking I/O.
    Since the stop method is deprecated, is there an equivalent VM call that I can interface from native code?
    I must say that I feel a bit like I'm being mothered by Sun.

    From your comments, you make a strong argument that suggests there's no need for a VM-level stop function.
    This puzzles me because operating systems implement kill methods to terminate rogue processes, yet they remain efficient and manage to keep things clean. Granted, multiple processes don't generally share memory structures but certainly the OS, on their behalf, shares memory structures. I'm puzzled as to why similar desires/features aren't present in the JRE.
    Regardless, short of running multiple JRE instances, each managing just one piece of work, the current deprecated status of the stop method renders Java without the ability to stop something that's gone wild unless the application is specifically pre-programmed to anticipate this behavior. (Of course that's a bit of a catch 22 in and of itself but...)
    There is also a subscription to the notion that my company or company x can write perfect software that never hangs a Java-based application server. I feel that this is impractical -- especially when what businesses ask of IT continues to get more complex.
    At this point perhaps it's fair to reveal the underlying reasons for my up-to-now, hypothetical questions. In my situation, company x is actually Sun. They failed to expose a socket timeout on their implementation of HTTPUrlConnection. I suppose that pretty much removes the luster from the argument that I, or anyone else, can write perfect software when the inventors of Java are themselves, imperfect. Of course, like you said and the JDK documents, the stop method will not abort a blocking socket read anyway (...although there's no reason why it couldn't except for more flawed design decisions...)
    I've certainly investigated alternative packages but I'm just chasing a moving target. HTTPUrlConnection today, class x tomorrow. That's why I was wanting something at the framework level to provide a trap door so that recovery without terminating the JRE is possible.

  • PROBLEM WITH MY CLA- DEPRECATED CODE

    Hi all,
    I really need some help to sort out my small class which generates a random string. Here is the code:
    package project_gui;
    import java.util.Random;
    //Random string generator class
            public class randomString {
                    private static Random rn = new Random();
                    public randomString()
                    public static int rand(int lo, int hi)
                            int n = hi - lo + 1;
                            int i = rn.nextInt() % n;
                            if (i < 0)
                                    i = -i;
                            return lo + i;
                    public String randomstring(int lo, int hi)
                            int n = rand(lo, hi);
                            byte b[] = new byte[n];
                            for (int i = 0; i < n; i++)
                                    b[i] = (byte)rand('a', 'z');
                            return new String(b, 0);
                    public String randomstring()
                            return randomstring(1, 12);
            }The error I get is:
    project_gui/randomString.java:28: warning: String(byte[],int) in java.lang.String
    has been deprecated
              return new String(b, 0);I'm already looked through the API to try and find an alternative way of doing it, but I'm an inexperienced programmer and so I'm not sure what to do.
    Please help!!!

    JDK1.4.2 API docs:
    I believe it's:
    old
    String(byte[] ascii, int hibyte)
              Deprecated. This method does not properly convert bytes into characters. As of JDK
    1.1, the preferred way to do this is via the String constructors that take a charset name or
    that use the platform's default charset.
    new
    String(byte[] bytes, String charsetName)
              Constructs a new String by decoding the specified array of bytes using the
    specified charset.Try looking under class Charset for more details. I have not used these constructors myself though.

Maybe you are looking for

  • SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

    Here is sql Store procedure Create procedure InsertResMasterNEW          @urm_id int output,          @upm_sector varchar(60) , @upm_block varchar(50) , @upm_plot varchar(50) , @urm_entry_dt datetime,          @urm_loc_adv varchar(50) ,@urm_alott_cat

  • Problem in getting sandbox path in Content Database

    Hello all, we have created a custom application using Oracle Content database API, which upload files to content database programmatically. For this we are using following code to retrieve sandbox try FdkCredential credential = new SimpleFdkCredentia

  • Communication between 2 servlets/java classes.

    Hi, I’ve a problem. Not sure if it’s a simple one. I have a web app with servlets (say Servlet1, Servlet2, etc.) in it. I use a SQL query in Servlet1 and fetch an employee’s information (say empinfo) from the database. This is a string value. Now, I

  • Powerpoint problem in presenter view.

    I'm having a powerpoint problem in presenter view. For some reason it's only showing the slide I'm on, as opposed to showing the next slide as well. Anyone else ever run into this?

  • MDM 7,1 Portal Content

    I have configured MDM 7.1 Portal content and I am facing issuse that I do not have control on . For example if I edit an existing record and try saving the changes it saves and automatically creates a duplicate record. If I try to duplicate a particu