0

English is not my native language; please excuse typing errors.
Hope I improved the question.

  1. I start a Script over Selenium, automated testing, WebDriver.
  2. I perform a Link on HTML-Page
  3. This link creates a new Browser Tab
  4. This BrowserTab display a PDF/A Standard Document
  5. I want to parse the PDF an verify its content

After HttpURLConnection I got Hypertext Transfer Protocol (HTTP) response status code: 400
and parsing the InputStream can not be done.
Over localhost it can be done.
Also I can hit link "curent URL" without any problems.
Selenium v2.45.0
Tested on IE 9 and Firefox 39.0.

How can I examine the problem?
I read about HTTP response code: 400
But didn't find solution for my problem
Could it be a redirect-problem?
Thank you
Here is my code:

public class httperrorStack {
public static void main ( String[] args )
{
    // Selnium WebDriver
    WebDriver driver = null;
    //driver = new FirefoxDriver();
    // Test with Browser IE 9 same Problem withFirefox 39.0
    System.setProperty("webdriver.ie.driver","C:\\dir\\IEDriverServer.exe");
    driver = new InternetExplorerDriver();

    String baseUrl = "http://##.###.###.##:#####/wps/portal"; //ATU2                
    // launch direct to Base URL
    driver.get(baseUrl);    
    // launch to Documentlink: opens PDF/A-Document in a new Browser Tab
    driver.findElement(By.xpath("//a[@title='document_link']")).click();    

    //Get all the window handles in a set
    Set <String> handles =driver.getWindowHandles();
    Iterator<String> it = handles.iterator();
    //iterate through windows
    while (it.hasNext()){
    String parent = it.next();
    String newwin = it.next();
    driver.switchTo().window(newwin);       

    URL url = null;
    try {
        // The CurrentURL of the documentlink
        // url = "http://##.###.###.###:#####/wps/myportal/dirname/dirname/dir-name/!dir/p/b1/about50characters/In"
        url = new URL(driver.getCurrentUrl());
    } catch (MalformedURLException e1) {            
        e1.printStackTrace();
    }                

    // verify connection
    HttpURLConnection connection = null;
    HttpURLConnection httpConn = (HttpURLConnection)connection;
    try {
        httpConn = (HttpURLConnection)url.openConnection();
    } catch (IOException e1) {            
        e1.printStackTrace();
    }
    InputStream is = null;

    // Response Code = 400
    try {
        if (httpConn.getResponseCode() >= 400) {
            is = httpConn.getErrorStream();
            // httpConn.getResponseCode() = 400
            //httpConn.getErrorStream() = "sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@1d082e88"
        } else {
            is = httpConn.getInputStream();
        }
    } catch (IOException e1) {
            e1.printStackTrace();
    }              

    try{            
        connection = (HttpURLConnection)url.openConnection();                    
        InputStream is2;
        if (connection.getResponseCode() >= 400) {
            is2 = connection.getErrorStream();
            //connection.getErrorStream() = "sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@60704c"                
        } else {
            is2 = connection.getInputStream();
        }                   


    }
    catch (Exception e){
        e.printStackTrace();
    }

    BufferedInputStream fileToParse = null;
    try {
        fileToParse = new BufferedInputStream(
                url.openStream());
    } catch (IOException e) {
        e.printStackTrace();
        // output of StackTrace
        /*java.io.IOException: Server returned HTTP response code: 400 for URL: http://##.###.###.##:#####/wps/redirect
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
        at java.net.URL.openStream(Unknown Source)
        at mypackage.httperrorStack.main(httperrorStack.java:134)*/
    }

    // Close Window
    driver.close();
    driver.switchTo().window(parent);
    driver.quit();  
    // exit the program explicitly
    System.exit(0);
      }
   }
}
Tilman Hausherr
  • 17,731
  • 7
  • 58
  • 97
Bob
  • 1
  • 1
  • 1
    This is very confusing. What is meant with "When I invoke the write protected pdf across the server I cannot interact with the PDF PopUp" - what does "across the server" mean? Is the problem that you get http error 400 or that you get an IllegalStateException? What is the variable "driver"? How is this related to PDFBox at all? I.e. can you reproduce the error without the PDFBox code? Please do also read this: https://stackoverflow.com/help/mcve – Tilman Hausherr Jul 19 '15 at 12:24
  • You can edit the question. Just remove everything that isn't part of the problem. – Tilman Hausherr Jul 19 '15 at 14:41
  • In thence contents I recognize some redirection being observed. Have you allowed following redirects? – mkl Jul 19 '15 at 15:27
  • @Tilman Hausherr The Link to the PDF-File (performed over Selenium (automated testing) opens an new browser-window (PDF/A-Side) I try to perform the link not at my local-Installation. I got httpConn.getResponseCode() = 400. I started a Selenium Webdriver Script. With Apache PDFBox I would like to parse PDF document. Yes. I think the script stopped after "BufferedInputStream" with http error 400. – Bob Jul 23 '15 at 09:01
  • @mkl I tried to test your hint in this way in Firefox: Preferencies, Advanced Settings, Accessibility "Warn me when websites try to redirect or reload the page" Result: I got no warning for Redirection. java.io.IOException: Server returned HTTP response code: 400 for URL: http://##.###.###.##:#####/wps/redirect Is this a hint for redirection? Normaly Redirection should be HTTP-Status 3xx see: [link]https://en.wikipedia.org/wiki/List_of_HTTP_status_codes – Bob Jul 23 '15 at 09:03
  • I had seen the `Server returned HTTP response code: 400 for URL: http://##.###.###.##:#####/wps/redirect` error message. Thus, it looks like some error occurs while some redirection is attempted, at least if the URL parts can be taken seriously. If normally no redirection occurs, then probably this 400 error merely is a follow-up error of some former problem which results in the redirection attempt. – mkl Jul 23 '15 at 11:09
  • Many Thanks for quick reply. It seems to be a redict-Problem. Therefore I have no access to the environment. I try to follow this way. [stackoverflow] http://stackoverflow.com/questions/3563147/can-selenium-verify-text-inside-a-pdf-loaded-by-the-browser _.... use keyboard shortcut keys to select all text (CTRL+A), then copy it to the clipboard (CTRL+C) and then you can verify the text in the clipboard. eg: ..._ – Bob Jul 27 '15 at 04:24

0 Answers0