6 Replies Latest reply: Sep 4, 2012 7:15 PM by 953426 RSS

    Trying to use the classes in casStubs.jar and get crawl metrics

    953426
      I was going through the class files available in casStubs.jar and was trying to come up with a script in AppConfig.xml to connect to the CAS server and obtain the crawl status and metrics. I was trying this option because the class com.endeca.eac.toolkit.component.cas.ContentAcquisitionServerComponent does not provide me these features.

      +<script id="CheckCrawlStatus">+
      +<bean-shell-script><![CDATA[+

      import javax.xml.namespace.QName;
      import com.endeca.cas.wsdl.*;


      final String wsdlUrl = "http://" "${cas.host}" + ":" + "${cas.port}" + "/cas?wsdl";+
      final QName name = new QName("http://endeca.com/itl/cas/2010-07", "CasCrawlerService");
      CasCrawlerServiceLocator service =  new CasCrawlerServiceLocator(wsdlUrl, name);
      CasCrawler crawler = service.getCasCrawlerPort();

      String crawlName = "myFirstCrawl";
      CrawlId crawlId = new CrawlId(crawlName);

      Metric[] metricArray = crawler.getMetrics(crawlId);
      + // rest of the code to retrieve crawl metrics +

      +]]></bean-shell-script>+
      +</script>+

      Unfortunately, I am always getting connection refused exception - "java.net.ConnectException: Connection refused". My cas wsdl is loading fine in my browser.
      Any ideas about the shortcomings in the code or missing configuration in CAS or DT or platformservices?

      Thanks
      Dev
        • 1. Re: Trying to use the classes in casStubs.jar and get crawl metrics
          Brett R-Oracle
          Hi,

          Is your CAS server on the same machine/localhost, or remote? If remote, could it be that your browser is accessing the WSDL via a proxy-server? Can you access the CAS port directly without a proxy server?

          Best
          Brett
          • 2. Re: Trying to use the classes in casStubs.jar and get crawl metrics
            953426
            Hey Brett,
            I was trying to run the script in the AppConfig.xml from the same machine which is hosting the CAS server but encountered the connection problem. But practically, I would need to run the AppConfig.xml script from a remote machine in the same / different cluster to access the crawl metrics.

            Yes, my browser was accessing the wsdl through a proxy server.

            Let me know if you have any other questions.

            Thanks
            Dev
            • 3. Re: Trying to use the classes in casStubs.jar and get crawl metrics
              Brett R-Oracle
              Try explicitly setting the service endpoint before obtaining the port. So if you are connecting to localhost:8500:

              service.setCasCrawlerPortEndpointAddress("http://localhost:8500/cas");

              You can substitute your host/port parameters. This call is normally made by the toolkit component-wrappers, but since you are using the service stubs directly, you will need to set the endpoint yourself. Without this, the stubs are using a test port which won't match yours.

              Best
              Brett
              • 4. Re: Trying to use the classes in casStubs.jar and get crawl metrics
                953426
                Hey Brett,
                Awesome, it works now. I went through the source code by de-compiling the class files and figured out why you referred to this extra line of code; great that it didn't miss your "laser eyes". It was really helpful.

                Another question for you; a stupid one maybe -

                I was also trying to call the web-services through the browser -

                http://{cas-host}:{cas-port}/cas/listCrawls - this one works great; gives me the list of all the crawls
                http://{cas-host}:{cas-port}/cas/getAllMetrics - this one work great too

                But when I try to pass a parameter my service call fails with an exception

                http://{cas-host}:{cas-port}/cas/getMetrics?crawlId={crawl-id}

                <soap:Body>
                <soap:Fault>
                <faultcode>soap:Server</faultcode>
                <faultstring>java.lang.ClassCastException@1b3bf979 while invoking public java.util.List com.endeca.itl.service.CasCrawlerImpl.getMetrics(com.endeca.itl.cas.api.CrawlId) throws com.endeca.itl.cas.api.CrawlNotFoundException with params {crawl-id}.</faultstring>
                </soap:Fault>
                </soap:Body>

                Note : {cas-host}, {cas-port} and {crawl-id} are placeholders for actual values.

                Any idea where I am going wrong?

                Thanks
                Dev

                Edited by: 950423 on Sep 4, 2012 3:13 PM
                • 5. Re: Trying to use the classes in casStubs.jar and get crawl metrics
                  Brett R-Oracle
                  You can't properly invoke the SOAP web service with a browser and a GET request, although you appear to get away with it for services taking no parameters. Grab a SOAP client testing tool and use that to load the WSDL and invoke the service with POST with parameters:

                  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://endeca.com/itl/cas/2010-07">
                  <soapenv:Header/>
                  <soapenv:Body>
                  <ns:getMetrics>
                  <ns:crawlId>
                  <ns:id>FileCrawl</ns:id>
                  </ns:crawlId>
                  </ns:getMetrics>
                  </soapenv:Body>
                  </soapenv:Envelope>
                  • 6. Re: Trying to use the classes in casStubs.jar and get crawl metrics
                    953426
                    Makes sense! Will try soapUI for that. Our idea was to send some request from a monitoring tool through GET and do a health check of the crawls and record-stores. Let me know if you have any suggestions to make use of the web-services in CAS.

                    Also, I was trying to access the recordstore information (record count, etc. etc.) from AppConfig.xml but unfortunately I don't find any class file available in casStubs.jar. I think casStubs.jar provides code to perform same functions that we can do through cas.-cmd.sh from command line. Do you have any suggestion how to work with recordstores from the bean-shells in AppConfig.xml? Should I load the recordstore-cmd or recordstore api jar in the classpath and try the api available there?
                    Please let me know.

                    Thanks again for your guidance and help.

                    Thanks
                    Dev

                    Edited by: 950423 on Sep 4, 2012 5:00 PM

                    Edited by: 950423 on Sep 4, 2012 5:15 PM