Accessing seured website using java URL/Socket programming

Hi,
I am working on an intranet search engine using java URL and Authenticator class. This is a secured web-site using SSL in http server. I am not able to access the password protected pages. Following is the code:
URL url = new URL("https://*************");
URLConnection connection = url.openConnection();
PasswordAuthentication pa = Authenticator.requestPasswordAuthentication( InetAddress.getByName(connection.getURL().getHost()),
connection.getURL().getPort(), connection.getURL().getProtocol(), null, "Basic");
StringBuffer buf = new StringBuffer("*****************");
buf.append(":");
buf.append("************");
String encoded = new sun.misc.BASE64Encoder().encode(buf.toString().getBytes());
connection.setRequestProperty ("Authorization", "Basic" + encoded);
InputStream content = (InputStream)connection.getInputStream();
BufferedReader in = new BufferedReader (new InputStreamReader (content));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
Let me know if there is any other alternative
tnx,
Biswajit Biswal

Below is my first test program. I first take the home page of a website (this can be automated later) and save it to "myTest.html". Then I try to see if this page contains the keywords that a company website often has.
Could you give your opinion on this approach?
If this approach is fine, then any idea about the keywords to select a company website from other sites is welcome.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
public class MyTest {
      * @param args
      * @throws IOException
     public static void main(String[] args) throws IOException {
          InputStream in = MyTest.class.getResourceAsStream("/myTest.html");
          Reader reader = new InputStreamReader(in, "UTF-8");
          BufferedReader bufferedReader = new BufferedReader(reader);
          String line;
          while ((line = bufferedReader.readLine()) != null) {
               line=line.toLowerCase();
               if (line.contains("contact us")) {
                    System.out.println("contact us: line = "+line);
               if (line.contains("career")) {
                    System.out.println("career: line = "+line);
               if (line.contains("company")) {
                    System.out.println("company: line = "+line);
               if (line.contains("about us")) {
                    System.out.println("about us: line = "+line);
               if (line.contains("product")) {
                    System.out.println("product: line = "+line);
          bufferedReader.close();
          reader.close();
}

Similar Messages

  • Logging in on website using java

    Hello,
    I am quite inexperienced when it comes to java programming, so my apologies if I post this in the wrong section.
    I am trying to open a website using java. So far I succeeded in reading the source code through java, which is about halfway I want to get. However, for getting the information I want, I need to login on the website with my account. I have no idea how something like that should be done. Cookies are used to login, and I am using BlueJ for my program. Could anyone help me out with an example or explanation on how this is done?
    Thanks in advance,
    Tybs

    I downloaded the httpclient tool, it looks promising. I managed to open it in blueJ, so far so good... the only problem now is that I can't compile it. Each class gives me an error message. This one, for example:
    import test.com.meterware.httpunit.*;
    package test.com.meterware.httpunit does not exist
    I found the necessary packages in the tool itself, but I have no idea how I can specify the path to them, or how I can add them to the packages that java already has. What do I need to do for this?
    Thanks for the information so far, it really helps :D
    Greetz,
    Tybs

  • How to access Websphere variables using java

    Hi
    I want to access Websphere variables using java.
    Any help is appreciated!!
    Thanks
    P

    WebSphere Application Server has a bunch environmental variables such as log locations. These are held at the "server", "node", and "cell" level.
    To access them, you have to get the right context. Something like this, I believe...
    InitialContext initialContext = new InitialContext();
    initialContext.lookup("foo:bar/baz/blah"); //correct context hereGo to the IBM website for WAS and do a search on namespace bindings. That should give you some more information.
    Good luck.

  • How to find out top 10 records from the R/3 using Java code (WD Program)

    Hi Experts,
    I have used Java Web Dynpro program to fetch records from the backend. Following code helps me and fetches record. As per the customer reqirement, we have to fetch only top 10 records (Actual Cost) from the backend. So I have to modify the Java code. How I can do so? Please help.
              wdContext.nodeGraphData().invalidate();
              IPublicCostcnt.IGraphDataElement categoryElement;
                   for (int i = 0; i < wdContext.nodeItab_Final1().size(); i++) {
                   categoryElement = wdContext.createGraphDataElement();
                   categoryElement.setCostElement(""+ wdContext.nodeItab_Final1().getItab_Final1ElementAt(i).getDescription());
                   categoryElement.setActualCost(wdContext.nodeItab_Final1().getItab_Final1ElementAt(i).getActual_Cost().toString());
                   categoryElement.setPlannedCost(wdContext.nodeItab_Final1().getItab_Final1ElementAt(i).getPlan_Cost().toString());
                   wdContext.nodeGraphData().addElement(categoryElement);
    Regards,
    Gary

    Dear SDN Users,
    This is how I resolved the issue.
    1) Requested ABAPer to provide me sorted data. The data has been sorted in descending order of actual_cost.
    2) After that I used following code. This resolved the issue.
         if (wdContext.nodeItab_Final1().size()>10){
         IPublicCostcnt.IGraphDataElement categoryElement;
              for (int i = 0; i < 10; i++) {
              categoryElement = wdContext.createGraphDataElement();
              categoryElement.setCostElement(""+ wdContext.nodeItab_Final1().getItab_Final1ElementAt(i).getDescription());
              categoryElement.setActualCost(wdContext.nodeItab_Final1().getItab_Final1ElementAt(i).getActual_Cost().toString());
              categoryElement.setPlannedCost(wdContext.nodeItab_Final1().getItab_Final1ElementAt(i).getPlan_Cost().toString());
              wdContext.nodeGraphData().addElement(categoryElement);
         if (wdContext.nodeItab_Final1().size()<=10){
         if (wdContext.nodeItab_Final1().size()>0){
         IPublicCostcnt.IGraphDataElement categoryElement;
              for (int i = 0; i < wdContext.nodeItab_Final1().size(); i++) {
              categoryElement = wdContext.createGraphDataElement();
              categoryElement.setCostElement(""+ wdContext.nodeItab_Final1().getItab_Final1ElementAt(i).getDescription());
              categoryElement.setActualCost(wdContext.nodeItab_Final1().getItab_Final1ElementAt(i).getActual_Cost().toString());
              categoryElement.setPlannedCost(wdContext.nodeItab_Final1().getItab_Final1ElementAt(i).getPlan_Cost().toString());
              wdContext.nodeGraphData().addElement(categoryElement);
    Regards,
    Gary

  • Error code 404 keeps coming up on screen when I try to access Vodafone website (using Mac Pro)

    Error code 404 keeps coming up on screen when I try to access Vodafone website (using Mac Pro)
    Any ideas why only started happening in last week ?

    404 means the page you are looking for doesn't exist,  if you are using a bookmark
    type the website directly into your browser.
    otherwise:
    open terminal> type:
    traceroute www.vodafone.com.au
    you should get something like this:

  • How to access sharepoint logs using Java?

    Is there a way to access Sharepoint logs using Java from a remote machine? 
    Any help / pointers would be appreciated. Thanks.

    Hello,
    I am not aware about any client modal class for log but if you create your own service and host in SP server then you can call this web service in JAVA. (i am not sure whether JAVA supports .NET web service or not).
    You can refer this for web service:
    http://www.arboundy.com/2010/12/centalised-view-of-sharepoint-uls-log-files/
    Hope it could help
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • How to control tcp connection with java tcp socket programing ??

    Hi,
    I am connecting a server as using java socket programming.
    When server close the connection (socket object) as using close() method ,
    I can not detect this and My program continue sending data as if there is a connection with server.
    How to catch the closing connection ( socket ) with java socket programming.
    My Client program is as following :
    import java.io.PrintWriter;
    import java.net.Socket;
    public class client
      public client()
       * @param args
      public static void main(String[] args)
        Socket socket=null;
        PrintWriter pw=null;
        try
                          socket = new Socket("localhost",5555);
                          pw = new PrintWriter(socket.getOutputStream(),true);
                          int i=0;
                          while (true)
                            i++;
                            pw.println(i+". message is being send.");
                            Thread.sleep(5000);
        } catch (Exception ex)
                          ex.printStackTrace();
        } finally
                          try
                            if(pw!=null)pw.close();
                            if(socket!=null)socket.close();
                          } catch (Exception ex)
                            ex.printStackTrace();
                          } finally
    }

    I changed the code as following. But I couldn't catch the EOFException when I read from the socket. How can I catch this exception ?
    import java.io.BufferedReader;
    import java.io.EOFException;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    import java.net.Socket;
    import java.net.UnknownHostException;
    public class client
      public client()
       * @param args
      public static void main(String[] args)
        Socket socket=null;
        PrintWriter pw=null;
        BufferedReader bufIn=null;
        InputStreamReader inRead=null;
        InputStream in=null;
        try
                          socket = new Socket("localhost",5555);
                          in = socket.getInputStream();
                          inRead = new InputStreamReader(in);
                          bufIn = new BufferedReader(inRead);
                          pw = new PrintWriter(socket.getOutputStream(),true);
                          int i=0;
                          while (true)
                            i++;
                            try
                              bufIn.readLine();
                              pw.println(i+". message is being send.");
                              System.out.println(i+". message has been send");
                            } catch (Exception ex2)
                              System.out.println(ex2.toString());
                              System.out.println(i+". message could not be send");
                            } finally
                            Thread.sleep(5000);
        } catch (EOFException ex)
                          ex.printStackTrace();
        } catch (InterruptedException ex)
                          ex.printStackTrace();
        } catch (IOException ex)
                          ex.printStackTrace();
        } finally
                          try
                            if(pw!=null)pw.close();
                            if(socket!=null)socket.close();
                          } catch (Exception ex)
                            ex.printStackTrace();
                          } finally
    }

  • Access System Resources using Java Applet via Java Script

    Hello
    I can access my Applet public methods (and this methods access system resources) via Java Script if I do the following: System.setSecurityManager(null);However, I'm making this post because I don't like this solution.
    Supposedly, setting the SM to null is like making the Applet (which is signed and was accepted by the user via a prompt from the browser) behave like a normal Java program that has no restrictions. (http://java.sun.com/docs/books/tutorial/essential/environment/security.html, second paragraph)
    However, this feels like a workaround of something that is supposed to be there (the SM).
    Also, if I make the methods invocation from inside the applet (using swing buttons and textboxes for example) I can use the standard SM without no problems.
    From my readings, the problem regarding Java Script invocation, comes from the fact that the Java Script is not a secure (not signed) source (because you can invoke public methods the way you wish from it i guess) on the contrary to the applet methods invoked by the buttons.
    Possible solutions I found in the web range from using the public static Object doPrivileged(PrivilegedAction action) method or imaginative things like creating new threads on the public method that call the private methods that access the system resources (supposedly because the new thread runs under the safe environment of the applet)
    I almost got a glimpse of hope with this post http://forums.sun.com/thread.jspa?threadID=5325271&tstart=0
    However, none of these solutions worked, the only results were with the setResourceManager(null)So, any one can contribute with a solution for this? Should I keep trying to find a solution other then the one I already have?
    Regards
    Cad

    1. yes
    2. yes
    Note for 2. the converter will run the applet with SUN jre for sure if the user has IE.
    IE will use the ActiveX technology to run the applet (as with Macromedia Flash).
    For Netscape I am not sure, but I would think Netsape will use the plug in provided by
    SUN.
    Note for SUN jre 1.3. If this applet is to be used within a company that uses a proxy with
    ntlm authentication the 1.3 applet cannot connect (to the Internet) through this proxy since
    ntlm athentication is supported since j2re1.4.2_03. There is one version before that but
    that one will pop up a window asking for the user's domain account and password wich
    is both lame and crappy.
    As for the IE settings, IE has a default setting that askes users the "do you trust"
    queston for AciveX controls within the Internet securety zone (tools -> internet options
    -> security).
    Sincy anybody can make ActiveX controls (allso sign them) a user that has a problem
    to find the "no" button will sooner or later install a malicuous ActiveX control (spy ware
    or a virus).
    If this user's desktop is within your company's network it will cause serious harm.
    This is why most company's disable this by changing the default internet expolorer
    settings. Since I assume you are writhing this applet to be used by a company I allso
    assumed that company has someone to maintain the desktops. In that case I
    assume that person would want to control the security within the SUN jre instead of
    letting the user deside what to trust and what not.

  • Need help with java.nio.socket program.

    Can someone please help me here? I am trying to create a class that listens on a socket for an incoming connection, but I am getting the following error on compile:
    SocketIn.java:48: incompatible types
    found : java.nio.channels.SocketChannel
    required: java.net.Socket
    Socket requestSocket = requestChannel.accept();
    Here is my code:
    package NETC;
    import java.net.*;
    import java.util.*;
    import java.io.*;
    import java.nio.*;
    import java.nio.charset.*;
    import java.nio.channels.*;
    import java.nio.channels.spi.*;
    public class SocketIn{
         // Buffer for any incoming data.
         private static ByteBuffer inBuffer = ByteBuffer.allocateDirect(1024);
         CharBuffer charBuffer = null;
         public SocketIn(int intPort)throws Exception{
              // Create a non-blocking server socket.
              ServerSocketChannel serverChannel = ServerSocketChannel.open();
              serverChannel.configureBlocking(false);
              // Use the host and port to bind the server socket.
              InetAddress inetAddress = InetAddress.getLocalHost();
              InetSocketAddress socketAddress = new InetSocketAddress(inetAddress, intPort);
              serverChannel.socket().bind(socketAddress);
              // The selector for incoming requests.
              Selector requestSelector = SelectorProvider.provider().openSelector();
              // Put the server socket on the selectors 'ready list'.
              serverChannel.register(requestSelector, SelectionKey.OP_ACCEPT);
              while(requestSelector.select() > 0){
                   System.out.println("Connection Accepted...");
                   // A request has been made and is ready for IO.
                   Set requestKeys = requestSelector.selectedKeys();
                   Iterator iterator = requestKeys.iterator();
                   while(iterator.hasNext()){
                        SelectionKey requestKey = (SelectionKey)iterator.next();
                        // Get the socket that's ready for IO.
                        ServerSocketChannel requestChannel = (ServerSocketChannel)requestKey.channel();
                        // This shouldn't block.
                        Socket requestSocket = requestChannel.accept();
                        inBuffer.clear();
                        requestSocket.read(inBuffer);                    
                        inBuffer.flip();
                        Charset charset = Charset.forName("ISO-8859-1");
                        CharsetDecoder decoder = charset.newDecoder();
                        charBuffer = decoder.decode(inBuffer);
                        iterator.remove();                    
    }

    Well its been about a month and a half so I guess you have your answer. In case you don't...
    // This shouldn't block.
    Socket requestSocket = requestChannel.accept();
    The problem is quite simple. The ServerSocketChannel.accept() returns a SocketChannel. (Channel -> Channel).
    You can get access to the socket using the SocketChannel.
    SocketChannel requestSocketChannel = requestChannel.accept();
    Socket requestSocket = requestSocketChannel.socket();
    But you don't need the socket to read and write.

  • How to access NTFS entries using Java

    I want to access and read the attributes of a file stored in the Master File Table of NTFS.
    How should I do it using Java. Is using native code and using JNI the only way or is there a package in Java that supports this?
    Thanks

    WebSphere Application Server has a bunch environmental variables such as log locations. These are held at the "server", "node", and "cell" level.
    To access them, you have to get the right context. Something like this, I believe...
    InitialContext initialContext = new InitialContext();
    initialContext.lookup("foo:bar/baz/blah"); //correct context hereGo to the IBM website for WAS and do a search on namespace bindings. That should give you some more information.
    Good luck.

  • Access mirror site using java, download files and other information?

    Hi, I have 2 nodes/servers on the system both running webservers and having the same interface, but at a time user will access one node at a time from their browser, but this interface will be able to allow the user to get information from the both the nodes. the information that the user can get is DB stored as well as files on the disk of either node.
    i can manage the DB, cuz there is nothing to it, but how do I get files from the other node?
    currently any files/web documents are all stored in a application directory of the web root and protected by htaccess i believe, so when a user logs on to node one he can access all plain text/binary files along with web content since the web server authorizes the user to access anything in that dir. but at the same time from the same session I want to be able to access files in a mirror site using the same username and password and not having him to enter it again. the username/pass combo is replicated on both the servers, it this possible?
    currently i use the http password protection provided by apache to access one node, but can i use the same session on another machine with the same credentials?
    If this is not possible how can i do this programatically using java? can i do can "ls" on the directory i want on another server and display the list to the user and then when he clicks on that file name i fetch it from the backup/mirror server and have him save it using http or ftp?
    It would be great if we can get a solution to this.
    Thank you very much in advance.
    Ankur

    If you install the web server on different machines, It is possible to share the informations between them.

  • Accessing BAPI's using JAVA with out using webdynpro URGENT

    hi Experts,
    What is the procedure for calling RFC/BAPI's using JAVA with out using the webdynpro. Please let me know what are the possibilities with step by step implementation.
    Regards
    Vijay

    Hi Boris Rubarth,
    Thaks for relavant information.
    I have kind of the requirement. The clinet is asking for connecting the SAP RFC using java application. The build Jar or .war or .Ear for which are going to develop should be compatible for running on any of the Applications server like they have Tom cat, weblogic, websphere server.
    so the .jar for or .ear file which we are going to develop should be able to run accessing the RFC/ BAPIs from any of these servers other than SAP WAS that is what their target.
    Please give me your suggestion, which is better approach. currently their SAP system is 4.6c . So presently it is not possible the webservice approach. But they have plans to go for upgrade to ECC6.0
    In that case only JCO option is possible. If use this option . Is it possible to access application which is deployed irrespective of the WAS by doing the required configuration.
    Basically i am aware of the ABAP webservice work bech steps and also the JAVA coding also.
    Please suggest me what is the better way to achieve this.
    Regards

  • Can't access adobe website using safari 7

    I can't access adobe.com on my late 2008 MacBook running Mavericks OS X. Every time I try to access the website it says that Safari "can't connect to the server adobe.com"
    I've tried resetting Safari and restarting my computer. I have Adobe Lightroom 3 installed on my computer.
    Any help would be appreciated!

    You, or someone using your computer, may have hacked the system to redirect queries to certain servers. The file modified is /etc/hosts.
    The easiest way to fix the hosts file is to restore it from a backup that predates the modification, or to copy the unmodified file from another Mac. If you can't do that, then do as below.
    Back up all data before proceeding.
    If you have more than one user account, you must be logged in as an administrator.
    Triple-click anywhere in the line below on this page to select it:
    open -e /etc/hosts
    Copy the selected text to the Clipboard by pressing the key combination command-C.
    Launch the built-in Terminal application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Terminal in the icon grid.
    Paste into the Terminal window by pressing command-V. I've tested these instructions only with the Safari web browser. If you use another browser, you may have to press the return key after pasting. A TextEdit window should open. At the top of the window, you should see this:
    # Host Database
    # localhost is used to configure the loopback interface
    # when the system is booting.  Do not change this entry.
    127.0.0.1                              localhost
    255.255.255.255          broadcasthost
    ::1                                        localhost
    fe80::1%lo0                    localhost
    Below that, you may see some other lines. The first 10 lines should be exactly as above, apart from differences in the blank space within lines. Otherwise you can't use this procedure—STOP and ask for guidance.
    If the contents of the TextEdit window are as described, close it, then enter the following command in the Terminal window in the same way as before (by copy and paste):
    sudo sed -i~ '11,$d' /etc/hosts
    This time you'll be prompted for your login password, which won't be displayed when you type it. Type carefully and then press return. If you don’t have a login password, you’ll need to set one before you can run the command. You may get a one-time warning to be careful. Confirm. Quit Terminal.
    If you see a message that your username "is not in the sudoers file," then you're not logged in as an administrator. Log in as one and start over.
    That will fix the hosts file. There is now a copy of the old hosts file with the name "hosts~" in the same folder as "hosts". You can delete the copy if you wish. Don't delete the file named "hosts".

  • Can't access some websites using time capsule

    Everything has been working just fine with my time capsule and my imac and just today I couldn't access some websites for some reason. I tried many other sites including this one and can get to them no problem. I have been through all of the airport settings and trouble shooting and can't find any problems, also the other 2 computers and my blackberry can't access some of the same sites either, I am stumped. Does anyone out there have any idea whats going on? Thanks for your help!

    Welcome to the discussions!
    Suggest that you contact your ISP. It sounds like their DNS server is overloaded at the moment, but also unlikely that they will ever admit it.
    It wouldn't hurt to power cycle your complete network as well. Just power everything down, order is not important.
    Start the modem first and let it run a few minutes by itself.
    Then start the next device connected to the modem, probably your Time Capsule, and let it run a few minutes.
    Then start your computers and devices one by one the same way.
    Message was edited by: Bob Timmons

  • Need Reference to access Beehive WS using JAVA program

    I need to explore/download the files exists in specific Beehive WS through my JAVA prog.
    Can "Oracle Beehive Java Content Repository API" help me to achieve this!! If so, where can I found "oracle.ocs.jcr".
    Or How can this be done!!
    Thanks.

    Hemant,
    That page has all the information we have:
    Java Content Repository (JCR)
    Access Beehive workspaces and documents using the Java Content Repository protocol
    Documentation - Tutorial - Forum
    BeehiveOnline can be accessed with FTPS with several client - the FAQ on the main https://beehiveonline.oracle.com page explain the way top set this up.
    Phil

Maybe you are looking for

  • IPhoto - crash on startup on brand new mac mini

    Hi Just bought a new Mac Mini, ran migration assistant to move all my files over to the new machine.  My iPhoto library is stored on an external hard drive. Every time I launch iPhoto on the new Mac, it immediately crashes.   The first 30-40 lines of

  • File -- IDOC scenario using XI 3.0

    Hi    I tried out a simple flat file to IDOC scenario using XI as the middleware and tried to post documents of type CREMAS03 on the backend R/3 system. Now, I see that there is an IDOC number generated in the XI layer by the IDOC adapter. This IDOC

  • Reading text files in MIDP

    Hello, How can I read a .txt file that is kept under the resource directory in MIDlet. If any one has some code samples, please share.. Thanks Liju

  • Management Tool to manage both Catalyst and Nexus

    Is there a single network management tool to manage both Nexus and Catalyst at the same time?

  • HELP - all words are getting underlined in red while using yahoo mail. How to fix this?

    I am using Firefox browser and already upgraded to the latest 5.0. While using my yahoo mail all words are underlined in red(it is happening as I write this note). How do I stop this from happening and have just he mispelled words underlined? When th