0

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
  • Why are you using HTTPS with a proxy? Commented Oct 3, 2017 at 5:09
  • @Jenna , I removed the System.setProperty code and still the issue is there. I had even printed the properties http.proxyHost and http.proxyPort and values are null. Please guide further. Commented Oct 3, 2017 at 7:18

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

I just realized that the code which I have pasted here is incomplete. I will edit the post tomorrow as I am travelling now.
Please check once you get time, @AJavaCoder
I think the issue is the same as I have mentioned in my answer that you will need to access the web service using the web service client code generated from the WSDL file provided by the service provider. You are still trying to access the service as if it is a website. It will not work any more as they have made this a chargeable service.
I got the wsdl link as well. But not sure how to use it in the code: deanumber.com/Websvc/deaWebsvc.asmx?wsdl
Hey @AJavaCoder , as suggested by Loic ; I was able to generate the code. But there are still few issues. Please check my comment on Loic's answer.
|
1

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")

5 Comments

Thanks again @Loic . I was able to generate the code using the given steps. A separate package got created with more than 20 .java files. I just instantiated their GetQuery class by passing user name , password and DEA number and tried to print some of the values I need like zip. When I printed the values, nothing is getting displayed. There are no errors/exceptions.
Code is pasted below. GetQuery gq = new GetQuery( getDeaUsername(), getDeaPassword(), deaNumber, "", "", "", "", "", "", "", ""); System.out.println("Zip is available? "+ gq.getZip());
I analyzed their java files extensively and was able to write some code to submit the request. The response is also coming as I can see the values in debug mode. Now , I just need to identify the nodes and write some code to get the required values. Thanks for suggesting me this approach @Loic
"their code" ;) : it is not their code, it was generated by Eclipse from the WSDL file... I would say this approach is the standard/common one, if the service change in the future, you can then simply re-generate the client classes.
Cool. Thanks a ton.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.