2 Replies Latest reply on Mar 14, 2013 11:59 AM by Jack C. Holt

    Part of URL parameter in jboss-service.xml being truncated

    Jack C. Holt Newbie

      I have JBoss service archive (a SAR file) that I am trying to run under JBoss EAP 6.1.0 Alpha.  I am passing a string that contains a URL through jboss-service.xml but when the parameter is passed in through a setXXX() method only the part of the URL starting with the first ampersand is passed in.

       

      Here is the jboss-service.xml:

      <server>

          <mbean code="org.rta.ith.mmtps.mbean.DrivingCostDataFeed"

              name="org.rta.ith.mmtps:name=DrivingCostDataFeed">

              <attribute name="Active">true</attribute>

              <attribute name="DrivingCostWebSiteUrl">http://www.gsa.gov/Portal/gsa/ep/contentView.do?contentType=GSA_BASIC&amp;contentId=9646&amp;noc=T</attribute>

              <!-- Weekly polling rate -->

              <attribute name="PollingRate">10080</attribute>

          </mbean>

      </server>

       

      In the jboss-service.xml the DrivingCostWebSiteUrl attribute tag is all on one line.

       

      When I run jconsole and take a look at the value of the DrivingCostWebSiteUrl attribute of my MBean I see that it is set to "&contentId=9646&noc=T" (without the quotes, of course).

       

      What am I doing wrong?

        • 1. Re: Part of URL parameter in jboss-service.xml being truncated
          jaikiran pai Master

          There was one other user too who had reported this earlier but did not come back with additional information https://community.jboss.org/message/771559. Can you show us the code in your DrivingCostDataFeed class? This does look like a bug, but before filing a JIRA, I just want to make sure that we aren't missing something obvious.

          • 2. Re: Part of URL parameter in jboss-service.xml being truncated
            Jack C. Holt Newbie

            Here is the DrivingCostDataFeed.java:

             

            package org.rta.ith.mmtps.mbean;

             

            import java.io.StringReader;

            import java.net.URL;

            import javax.sql.DataSource;

            import javax.swing.text.MutableAttributeSet;

            import javax.swing.text.html.HTML;

            import javax.swing.text.html.HTMLEditorKit;

            import javax.swing.text.html.parser.ParserDelegator;

            import org.apache.commons.logging.Log;

            import org.apache.commons.logging.LogFactory;

            import org.rta.ith.mmtps.data.DrivingCostDAO;

            import org.springframework.jndi.JndiObjectFactoryBean;

             

            public class DrivingCostDataFeed extends DataFeed implements DrivingCostDataFeedMBean {

               

                      private double mileageRate = 0.0;

             

                      /**

                 * A Class for handling the events that occur during the parsing of Mileage Reimbursement HTML.

                 *

                */

              protected class MileageReimbursementParser extends HTMLEditorKit.ParserCallback {

             

              private int trTagCount = 0;

              private int tdTagCount = 0;

              private boolean foundMileageInfo = false;

              private boolean foundMileageRow = false;

              private boolean foundMileageRate = false;

             

                                public MileageReimbursementParser(final URL url) {

                        trTagCount = 0;

                        tdTagCount = 0;

                        mileageRate = 0.0;

                                }

             

                                // Parse HTML on Mileage Reimbursement page

                                // Get the mileage rate from the HTML on the page.

                                public void handleStartTag(final HTML.Tag tag, final MutableAttributeSet attrSet,

                                        final int pos) {

                                  

                                          if (tag == HTML.Tag.H2) {

                                        // Found info for "Privately Owned Vehicle Reimbursement Rates"

                                                    foundMileageInfo = true;

                                          } else if (foundMileageInfo && tag == HTML.Tag.TR) {

                                                    // count the TR tags

                                        trTagCount++;

                                              if (trTagCount == 5) {

                                                  // Found row containing data for "If no Government Owned Vehicle available"

                                                  foundMileageRow = true;

                                              }

                                          } else if (foundMileageRow && tag == HTML.Tag.TD) {

                                                         // count the TD tags

                                        tdTagCount++;

                                                  if (tdTagCount == 3) {

                         // Found the html that contains mileage rate data for POV

                         foundMileageRate = true;

                         foundMileageRow = false;

                         foundMileageInfo = false;

                     }

                 }

                                }

             

                                public void handleText(final char[] data, final int pos) {

                                    String text = new String(data);

                      

                                          if (foundMileageRate) {

                                                    // Set Mileage Data

                                                    text = text.replace("$", "");

                                                    mileageRate = Double.parseDouble(text);

                                                    foundMileageRate = false;

                                          }

                                }

                      }

              private static final String DEFAULT_GSA_URL = "http://www.gsa.gov/Portal/gsa/ep/contentView.do?contentType=GSA_BASIC&contentId=9646&noc=T";


                private String drivingCostWebSiteUrl = DEFAULT_GSA_URL;

               

                private DrivingCostDAO drivingCostDao;

                private byte[] drivingCostMD5Hash;

             

              public DrivingCostDataFeed() {

                                super("04/01/2007 12:00 AM");

                                logger = getLogger();

                      }

             

                /**

                 * @return the drivingCostDao

                 */

                public final DrivingCostDAO getDrivingCostDao() {

                    if (this.drivingCostDao == null) {

                        // If no Driving Cost DAO has be created yet, create one using the

                        // connection pool defined in ith2DS.xml

                        this.drivingCostDao = new DrivingCostDAO();

                        JndiObjectFactoryBean objFactory = new JndiObjectFactoryBean();

                        objFactory.setJndiName("java:/ith2DS");

                        this.drivingCostDao.setDs((DataSource)objFactory.getObject());

                    }

                    return this.drivingCostDao;

                }

             

                /**

                 * @param drivingCostDao the drivingCostDao to set

                 */

                public final void setDrivingCostDao(DrivingCostDAO drivingCostDao) {

                    this.drivingCostDao = drivingCostDao;

                }

             

                /**

                 * Do the work of importing the data feed.

                 */

                      @Override

                      protected void performAction() throws Exception

                      {

                                this.processDrivingCostData();

                      }

             

                /**

                 * Parse the HTML of the Driving Cost web site in order to

                 * capture Driving Cost information and insert it into the database.

                 */

                protected void processDrivingCostData() {

                          try {

                              URL url = new URL(this.getDrivingCostWebSiteUrl());

                        String htmlContent = htmlContentDownload(url);

                       

                        byte[] md5 = calculateMD5Hash(htmlContent);

                       

                        if (isByteArraysEqual(drivingCostMD5Hash, md5)) {

                            logger.info("Driving Cost data has not changed. Exiting.");

                            return;

                        }

             

                        logger.info("processDrivingCostData: starting...");

             

                        MileageReimbursementParser parserCallback = new MileageReimbursementParser(url);

             

                        if (htmlContent.contains("<SUP>")) {

                                  htmlContent = htmlContent.replace("<SUP>", "");

                        }

                        if (htmlContent.contains("<sup>")) {

                                  htmlContent = htmlContent.replace("<sup>", "");

                         }

                        if (htmlContent.contains("</SUP>")) {

                                  htmlContent = htmlContent.replace("</SUP>", "");

                        }

                        if (htmlContent.contains("</sup>")) {

                                  htmlContent = htmlContent.replace("</sup>", "");

                        }

             

                        StringReader htmlReader = new StringReader(htmlContent);

                        try {

                            logger.info("Parse Driving Cost HTML content: starting...");

                            new ParserDelegator().parse(htmlReader, parserCallback, true);

                            logger.info("Parse Driving Cost HTML content: done...");

                        } finally {

                            htmlReader.close();

                        }

                       

                        if (mileageRate > 0) {

                                                    logger.info("processDrivingCostData: Set mileageRate to " + mileageRate);

                                        getDrivingCostDao().updateDrivingCostData(mileageRate);

                        }

                        else {

                                  logger.error("Error in processDrivingCostData: Unable to get mileageRate from website.");

                        }

                       

                        this.drivingCostMD5Hash = md5;

                       

                        logger.info("processDrivingCostData: done...");

                          }

                    catch (Exception ex) {

                              logger.fatal("The Driving Cost Data could not be processed. " +

                            ex.getMessage());

                              throw new RuntimeException("The Driving Cost Data could not be processed." +

                                                  ex.getMessage());

                    }

                }

               

                /**

                 * @return the drivingCostWebSiteUrl

                 */

                public final String getDrivingCostWebSiteUrl() {

                    return drivingCostWebSiteUrl;

                }

             

                /**

                 * @param drivingCostWebSiteUrl the URL to set

                 */

                public final void setDrivingCostWebSiteUrl(final String drivingCostWebSiteUrl) {

                    logger.debug("Driving cost web site URL: " + drivingCostWebSiteUrl);

                    this.drivingCostWebSiteUrl = drivingCostWebSiteUrl;

                }

             

                @Override

                protected Log getLogger() {

                    return LogFactory.getLog(getClass());

                }       

            }