DocumentBuilder.parse() throwing java.net.UnknownH

2019-08-18 23:32发布

Previously , we had following code in our application and it used to fetch the required data. We just used to read the required fields by forming a web-service URL by passing username , password and search parameter (DEA number). The same URL (with parameters) could also be hit from browser directly to see the results :

 {    DocumentBuilderFactory factory = 
      DocumentBuilderFactory.newInstance();

      DocumentBuilder parser = factory.newDocumentBuilder();

      System.setProperty("http.proxyHost", getProxyHost());
      System.setProperty("http.proxyPort", getProxyPort());

      System.out.println("Before URL formation");

      URL url = new URL(
        "http://www.deanumber.com/Websvc/deaWebsvc.asmx/GetQuery?UserName=" + getDeaUsername() + "&Password=" + getDeaPassword() + "&DEA=" + 
        deaNumber + 
        "&BAC=&BASC=&ExpirationDate=&Company=&Zip=&State=&PI=&MaxRows=");

      System.out.println("After URL formation");
      System.out.println("URL formed is: "+url);
      Document document = null;
      try {

        System.out.println("toExternalForm");

        String strURL = url.toExternalForm();

        System.out.println("toExternalForm done: "+strURL);

        **document = parser.parse(strURL);** //This is causing exception
          }
      catch (SAXParseException spe)
         {  System.out.println("Inside SAXParseException");
            spe.printStackTrace();
         }
    }

Now, the web-service URL has got changed from http to https with rest of the things same. The new URL also works from the browser. Moreover, even if I enter the http URL in the browser , it automatically redirects to https and shows the data. However, the above code is not doing the same and it gave following exception : java.net.ProtocolException: Unsupported protocol: https'

So, I changed the code to use https in the url, but now a new exception is coming - java.net.UnknownHostException. From the console log, I can see that the exception is coming at ==> document = parser.parse(strURL). Here , parser is a reference variable for a DocumentBuilder object as you can see from the code above. I am pasting the complete stack trace below.

Complete stack trace for UnknownHostException:

{java.net.UnknownHostException: www.deanumber.com
[2017-23-28 08:23,     0]ERROR[[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'](DeaFetcher.java:123) - Exception in DeaFetcher.getDeaFromUrl java.net.UnknownHostException: www.deanumber.com
            at java.net.InetAddress.getAllByName0(InetAddress.java:1250)
            at java.net.InetAddress.getAllByName(InetAddress.java:1162)
            at java.net.InetAddress.getAllByName(InetAddress.java:1098)
            at weblogic.net.http.HttpsClient.openServer(HttpsClient.java:265)
            at weblogic.net.http.HttpsClient.openServer(HttpsClient.java:350)
            at weblogic.net.http.HttpsClient.New(HttpsClient.java:553)
            at weblogic.net.http.HttpsURLConnection.getHttpClient(HttpsURLConnection.java:332)
            at weblogic.net.http.HttpURLConnection.getInputStream(HttpURLConnection.java:711)
            at weblogic.net.http.SOAPHttpsURLConnection.getInputStream(SOAPHttpsURLConnection.java:37)
            at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:643)
            at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:189)
            at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:812)
            at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
            at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
            at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243)
            at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:347)
            at weblogic.xml.jaxp.RegistryDocumentBuilder.parse(RegistryDocumentBuilder.java:163)
            at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:177)
            at com.company.project.service.DeaFetcher.fetchDeaFromUrl(DeaFetcher.java:358)
            at com.company.project.service.DeaFetcher.fetchDeas(DeaFetcher.java:330)
            at com.company.project.service.DeaFetcher.fetchDeas(DeaFetcher.java:239)
            at com.company.project.service.DeaFetcher.fetchDeaMastersList(DeaFetcher.java:46)
            at com.company.project.service.DeaFetcher$$FastClassByCGLIB$$8f6b7575.invoke(<generated>)
            at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
            at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:695)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
            at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
            at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:630)
            at com.company.project.service.DeaFetcher$$EnhancerByCGLIB$$a5bf2c5a.fetchDeaMastersList(<generated>)
            at com.company.project.web.MainFormController.onSubmit(EntryFormController.java:137)
            at org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:267)
            at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:250)
            at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
            at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
            at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:857)
            at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:792)
            at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:475)
            at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:440)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:751)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
            at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
            at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
            at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
            at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:346)
            at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:243)
            at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3432)
            at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3402)
            at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
            at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
            at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
            at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2285)
            at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2201)
            at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
            at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1572)
            at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:255)
            at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311)
            at weblogic.work.ExecuteThread.run(ExecuteThread.java:263)
}

2条回答
Luminary・发光体
2楼-- · 2019-08-19 00:08

It looks like you are still trying call a web service using the same URL, but this time with HTTPS in the URL. If that is the case, then you may need to invoke the web service using the client code generated by the WSDL of the web service along with proper authentication code.

If you are calling the web service using a valid client code generated from the WSDL, then please provide the client code details in your question to see what exactly it is trying to do here.

查看更多
霸刀☆藐视天下
3楼-- · 2019-08-19 00:11

You write in the comments that you have the WSDL, then let eclipse generate the client for this, for example following: How do you convert wsdl to java classes using Eclipse? (or search in the internet for "generate client from wsdl")

查看更多
登录 后发表回答