Error connecting Java with SSRS URL access method


  • I am trying to connect my java application with SSRS 2008 R2 using the URL access method .Servlets in my application connect to SSRS reports.

    I am forming http urls in the servlets and trying to connect to report server but i am geting 401 unauthorised for URL

    I am passing a userid and password from the java application.below is the code for Servlet

     public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
                Authenticator.setDefault(new ReportAuthenticator("domain\\username","password"));

                  String urlString = "http://mydev/ReportServer/Pages/ReportViewer.aspx?"
               +"/Test&rs:Command=Render&county="+ new Integer(1)
                   + "&rs:format=pdf";
                 System.out.println("The url string is"+urlString);
                URL url = new URL(urlString);

                 HttpURLConnection repCon = (HttpURLConnection)url.openConnection();

                repCon.setRequestProperty("User-Agent", "Mozilla/5.0");
                repCon.setRequestProperty("Content-type", "application/pdf" );
                repCon.setRequestProperty("Content-length", Integer.toString(parameterString.length()));
                System.out.println("the response code"+repCon.getResponseCode());

                   // Send parameter string to report server
                PrintWriter repOutStream = new PrintWriter(repCon.getOutputStream());



    I get response code 401 .Its not able to connect to the url

    If i type the same url in the browser i am able to get the reports but from the Java application it gives 401 error.

    What could be the possible reason.Is it that Weblogic on which my java application is deployed is not able to talk to SSRS or some configuration missing on ssrs end ?

    Please help. I have been working on This for days now with no result.The network admin says that SSRS configurations are correct though I am not sure of it.


    Tuesday, April 02, 2013 8:38 PM

All replies

  • Someone please help?
    Wednesday, April 03, 2013 2:38 PM
  • Hello,

    I am trying to involve someone more familiar with this topic for a further look at this issue. Sometime delay might be expected from the job transferring. Your patience is greatly appreciated.
    Thank you for your understanding and support

    Fanny Liu

    Fanny Liu
    TechNet Community Support

    Thursday, April 11, 2013 9:48 AM
  • Thanks fanny ,I will wait.
    Thursday, April 11, 2013 8:07 PM
  • Hello Pink123,

    I believe what you are trying to achieve is not possible and it is failing with Authentication.

    You might need to try WebService API and we have a code sample for C# here, which you can use for reference to make modification:


    Durai Murugan

    Monday, April 15, 2013 4:40 PM
  • Thanks for your reply. Is there a reason why the above code which i am using is not possible.Its a simple Java servlet code which connects to a url and brings back the response.This is one of the sample code i found which is used to connect from Java to SSRS

    I tried the web service approach before and used weblogic(the webserver I am using for Java) tool clientgen to generate the client stubs for the wsdl file and it was giving n numbers of errors for missing jar files not on compilation but when I was trying to run the code.Though I included almost every jar file possible

    Can anyone suggest any document or reference I can use to generate the client stub and necessary libraries needed when generating client code from SSRS wsdl for Java

    I have not found any latest article on internet which says how we can connect SSRS with Java using webservice approach with example.

    Does microsoft provides any document for java users to connect to SSRS everywhere it is .NET examples.

    Also Fanny - Could anyone suggest a solution for this?

    Thanks everyone for helping!

    Thursday, April 18, 2013 8:31 PM
  • Hello Pink123,

    Usually 401 Error occurs when the authentication is not attached to the request sent. Now the method you are using may not be a reliable way to pass the request. So that is why we recommend using Web service API.

    You can refer the below blog to build the solution based on the information and code sample provided, which uses Web Service API. Hope this should help you in getting a solution built.

    Accessing MS Reporting Services with Java

    However this also covers the max boundary we can cover on this forum request as we don't have a readymade solution or document available.


    Durai Murugan

    • Proposed as answer by s_cebi Friday, August 25, 2017 5:03 PM
    • Unproposed as answer by s_cebi Friday, August 25, 2017 5:04 PM
    Thursday, April 25, 2013 2:00 PM