Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. java.net.MalformedURLException when creating an URL object [Solved]

java.net.MalformedURLException when creating an URL object [Solved]

Scheduled Pinned Locked Moved Java
questioncsharpjavadatabasewcf
8 Posts 4 Posters 13 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bob Stanneveld
    wrote on last edited by
    #1

    Hi all, I'm picking up Java for an integration project. I'm trying to utilize to a webservice from our externally hosted CRM application. I got some code from the CRM web services guide to log on to the application. However, when constructing the URL for logon purposes, the URL constructor throws the java.net.MalformedURLException. See the following line of code:

    URL wsURL = new URL(pstrServer + "/Services/Integration?command=ssoitsurl&ssoid=" + pstrSSOID);

    This should construct the following URL: https://abc.crmapplication.com/Services/Integration?command=ssoitsurl&ssoid=SSOID. When I remove the second query parameter (ssoid) the URL is constructed fine. Does anybody know why the construction of this URL object fails? How can I set the multiple query parameters for the URL? Thanks in advance and I'm looking forward to your reply. Kind regards, Bob Stanneveld

    T L D B 4 Replies Last reply
    0
    • B Bob Stanneveld

      Hi all, I'm picking up Java for an integration project. I'm trying to utilize to a webservice from our externally hosted CRM application. I got some code from the CRM web services guide to log on to the application. However, when constructing the URL for logon purposes, the URL constructor throws the java.net.MalformedURLException. See the following line of code:

      URL wsURL = new URL(pstrServer + "/Services/Integration?command=ssoitsurl&ssoid=" + pstrSSOID);

      This should construct the following URL: https://abc.crmapplication.com/Services/Integration?command=ssoitsurl&ssoid=SSOID. When I remove the second query parameter (ssoid) the URL is constructed fine. Does anybody know why the construction of this URL object fails? How can I set the multiple query parameters for the URL? Thanks in advance and I'm looking forward to your reply. Kind regards, Bob Stanneveld

      T Offline
      T Offline
      TorstenH
      wrote on last edited by
      #2

      What Every Developer Should Know About URLs might be those slashes, are they converted correctly? greets Torsten

      I never finish anyth...

      1 Reply Last reply
      0
      • B Bob Stanneveld

        Hi all, I'm picking up Java for an integration project. I'm trying to utilize to a webservice from our externally hosted CRM application. I got some code from the CRM web services guide to log on to the application. However, when constructing the URL for logon purposes, the URL constructor throws the java.net.MalformedURLException. See the following line of code:

        URL wsURL = new URL(pstrServer + "/Services/Integration?command=ssoitsurl&ssoid=" + pstrSSOID);

        This should construct the following URL: https://abc.crmapplication.com/Services/Integration?command=ssoitsurl&ssoid=SSOID. When I remove the second query parameter (ssoid) the URL is constructed fine. Does anybody know why the construction of this URL object fails? How can I set the multiple query parameters for the URL? Thanks in advance and I'm looking forward to your reply. Kind regards, Bob Stanneveld

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        I just tried this using the strings you show and it works fine. Check the values of your two variables are set correctly.

        It's time for a new signature.

        1 Reply Last reply
        0
        • B Bob Stanneveld

          Hi all, I'm picking up Java for an integration project. I'm trying to utilize to a webservice from our externally hosted CRM application. I got some code from the CRM web services guide to log on to the application. However, when constructing the URL for logon purposes, the URL constructor throws the java.net.MalformedURLException. See the following line of code:

          URL wsURL = new URL(pstrServer + "/Services/Integration?command=ssoitsurl&ssoid=" + pstrSSOID);

          This should construct the following URL: https://abc.crmapplication.com/Services/Integration?command=ssoitsurl&ssoid=SSOID. When I remove the second query parameter (ssoid) the URL is constructed fine. Does anybody know why the construction of this URL object fails? How can I set the multiple query parameters for the URL? Thanks in advance and I'm looking forward to your reply. Kind regards, Bob Stanneveld

          D Offline
          D Offline
          David Skelly
          wrote on last edited by
          #4

          A MalformedURLException normally includes a message to tell you what it thinks is wrong with the URL. For example, if I try to construct a URL from this string:

          xyz://www.google.com

          I get the following message in the MalformedURLException:

          unknown protocol: xyz

          What error message do you get?

          B 1 Reply Last reply
          0
          • D David Skelly

            A MalformedURLException normally includes a message to tell you what it thinks is wrong with the URL. For example, if I try to construct a URL from this string:

            xyz://www.google.com

            I get the following message in the MalformedURLException:

            unknown protocol: xyz

            What error message do you get?

            B Offline
            B Offline
            Bob Stanneveld
            wrote on last edited by
            #5

            Hi, Thanks for your reply. I don't get any error message... Here's the stack trace / exception printout:

            Exception in component tWebServiceInput_1
            java.net.MalformedURLException
            at java.net.URL.<init>(Unknown Source)
            at java.net.URL.<init>(Unknown Source)
            at java.net.URL.<init>(Unknown Source)
            at routines.CRMLogin.logonSSO(CRMLogin.java:97)
            at crmtest.testcrm_0_1.TestCRM.tWebServiceInput_1Process(TestCRM.java:338)
            at crmtest.testcrm_0_1.TestCRM.runJobInTOS(TestCRM.java:632)
            at crmtest.testcrm_0_1.TestCRM.main(TestCRM.java:506)

            The strange thing is that a bogus domain in the URL results in a correctly constructed URL object. When the correct URL is passed to the constructor (checked it with Internet Explorer), the exception gets thrown... Kind regards, Bob Stanneveld

            L D 2 Replies Last reply
            0
            • B Bob Stanneveld

              Hi, Thanks for your reply. I don't get any error message... Here's the stack trace / exception printout:

              Exception in component tWebServiceInput_1
              java.net.MalformedURLException
              at java.net.URL.<init>(Unknown Source)
              at java.net.URL.<init>(Unknown Source)
              at java.net.URL.<init>(Unknown Source)
              at routines.CRMLogin.logonSSO(CRMLogin.java:97)
              at crmtest.testcrm_0_1.TestCRM.tWebServiceInput_1Process(TestCRM.java:338)
              at crmtest.testcrm_0_1.TestCRM.runJobInTOS(TestCRM.java:632)
              at crmtest.testcrm_0_1.TestCRM.main(TestCRM.java:506)

              The strange thing is that a bogus domain in the URL results in a correctly constructed URL object. When the correct URL is passed to the constructor (checked it with Internet Explorer), the exception gets thrown... Kind regards, Bob Stanneveld

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Bob Stanneveld wrote:

              When the correct URL is passed to the constructor (checked it with Internet Explorer), the exception gets thrown.

              I don't think this is your problem. I have tried URLs with real and bogus domains and, as long as they are correctly formed, then there is no problem. You need to catch the exception that is being thrown and check exactly what message it is producing. Also check the validity of all your variables within your exception handler.

              It's time for a new signature.

              1 Reply Last reply
              0
              • B Bob Stanneveld

                Hi, Thanks for your reply. I don't get any error message... Here's the stack trace / exception printout:

                Exception in component tWebServiceInput_1
                java.net.MalformedURLException
                at java.net.URL.<init>(Unknown Source)
                at java.net.URL.<init>(Unknown Source)
                at java.net.URL.<init>(Unknown Source)
                at routines.CRMLogin.logonSSO(CRMLogin.java:97)
                at crmtest.testcrm_0_1.TestCRM.tWebServiceInput_1Process(TestCRM.java:338)
                at crmtest.testcrm_0_1.TestCRM.runJobInTOS(TestCRM.java:632)
                at crmtest.testcrm_0_1.TestCRM.main(TestCRM.java:506)

                The strange thing is that a bogus domain in the URL results in a correctly constructed URL object. When the correct URL is passed to the constructor (checked it with Internet Explorer), the exception gets thrown... Kind regards, Bob Stanneveld

                D Offline
                D Offline
                David Skelly
                wrote on last edited by
                #7

                Bob Stanneveld wrote:

                a bogus domain in the URL results in a correctly constructed URL object

                The URL constructor does not check that the domain exists, it merely checks that the URL is properly formed according to the documented standard (whatever that happens to be).

                Bob Stanneveld wrote:

                When the correct URL is passed to the constructor (checked it with Internet Explorer), the exception gets thrown

                Do you mean that you have checked the actual string value being passed to the URL constructor at runtime? This works for me:

                String a = "https://abc.crmapplication.com";
                String b = "SSOID";
                URL url = new URL(a + "/Services/Integration?command=ssoitsurl&ssoid=" + b);

                If that exact same piece of code does not work for you, then I am at a loss to understand what is happening, I'm afraid.

                1 Reply Last reply
                0
                • B Bob Stanneveld

                  Hi all, I'm picking up Java for an integration project. I'm trying to utilize to a webservice from our externally hosted CRM application. I got some code from the CRM web services guide to log on to the application. However, when constructing the URL for logon purposes, the URL constructor throws the java.net.MalformedURLException. See the following line of code:

                  URL wsURL = new URL(pstrServer + "/Services/Integration?command=ssoitsurl&ssoid=" + pstrSSOID);

                  This should construct the following URL: https://abc.crmapplication.com/Services/Integration?command=ssoitsurl&ssoid=SSOID. When I remove the second query parameter (ssoid) the URL is constructed fine. Does anybody know why the construction of this URL object fails? How can I set the multiple query parameters for the URL? Thanks in advance and I'm looking forward to your reply. Kind regards, Bob Stanneveld

                  B Offline
                  B Offline
                  Bob Stanneveld
                  wrote on last edited by
                  #8

                  Hi all, I'm using the Talend Open Studio ETL tool for my integration. Unfortunately, this tool doesn't have advaneced debuging facilities and I don't have access to a nice IDE. So after a couple of hours, pain and agony I discovered that the exception is thrown elsewhere in the code where a URL object is constructed with an empty string (a redirection URL should have been obtained from the reply from the server, but this is a different issue). Thank you all for your help. Perhaps I'll post another question soon :-D. Kind regards, Bob Stanneveld

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups