Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    #16
    Hi,
    Thanks for the fix.
    I just updated my smartGWT version to 12.1-p20201118.

    When I executed the code, It seems that the framework tries to load the applicationContext again. While loading the file, it gives the connectionTimeout error. Though the same file is loaded perfectly fine from the same location while server startup.
    Please find the logs below:

    Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from URL [file://D:/Projects/XXX/YYY/TTT/target/yyy-1.1.8/WEB-INF/applicationContext.xml]; nested exception is java.net.ConnectException: Connection timed out: connect
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:252)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:126)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:614)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:514)
    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:94)
    at com.isomorphic.spring.SpringBeanFactory.getBeanFactory(SpringBeanFactory.java:66)
    at com.isomorphic.spring.SpringBeanFactory.getBean(SpringBeanFactory.java:75)
    at com.isomorphic.rpc.ServerObject.<init>(ServerObject.java:230)
    at com.isomorphic.datasource.DataSourceDMI.execute(DataSourceDMI.java:236)
    at com.isomorphic.datasource.DataSourceDMI.execute(DataSourceDMI.java:64)
    at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:3002)
    at com.xxx.yyy.server.services.impl.PriceAdjustmentSQLServiceImpl.addAdjustments(PriceAdjustmentSQLServiceImpl.java:507)
    ... 14 common frames omitted
    Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at sun.net.ftp.impl.FtpClient.doConnect(Unknown Source)
    at sun.net.ftp.impl.FtpClient.tryConnect(Unknown Source)
    at sun.net.ftp.impl.FtpClient.connect(Unknown Source)
    at sun.net.ftp.impl.FtpClient.connect(Unknown Source)
    at sun.net.http://www.protocol.ftp.FtpURLConnec...onnect(Unknown Source)
    at sun.net.http://www.protocol.ftp.FtpURLConnec...Stream(Unknown Source)
    at org.springframework.core.io.UrlResource.getInputStream(UrlResource.java:169)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330)
    ... 33 common frames omitted

    While debugging the spring's XMLBeanDefenitionReader, the path of file is same as the value present while server startup.


    Please note that in my server.properties I have configured webRoot as "_AUTODETECT_". I have not configured any value for standalone.spring.applicationContext property.

    Thanks.

    Comment


      #17
      This no longer appears to have anything to do with SmartGWT, but rather with Spring. This answer may help - it looks like you probably have bean definitions that are invalid:

      https://stackoverflow.com/questions/...ection-timeout

      We're not sure how the file could become invalid only on the second try, but there is no plausible way that the SmartGWT server could be causing that.

      Comment


        #18
        Hi,
        I would not want that the spring context should be reloaded, as it is currently happening.

        To avoid the same I used
        lookUpStyle="new"
        instead of spring and created a new DS with only one operation binding. My new DS looks like
        Code:
        <DataSource ID="PriceAdjustmentSQLNoSpring"
                    serverType="sql"
                    tableName="aa_bb"
                    dropExtraFields="false"
                    xmlns:fmt="WEB-INF/">
            <fmt:bundle basename="com.aa.pp.client.DSMessages"/>
            <serverObject lookupStyle="new" className="com.aa.pp.server.services.impl.PriceAdjustmentSQLDS"/>
            <fields>
                <field name="price_adjustment_id" type="sequence" primaryKey="true" hidden="true"/>
                <field name="system" type="boolean" sqlStorageStrategy="integer" hidden="true"/>
                <field name="company_id" type="text" length="36" hidden="true" foreignKey="CompanySQL.company_id" joinType="outer">
                    <title>
                        <fmt:message key="company"/>
                    </title>
                </field>
                <field name="vendor_id" type="integer" foreignKey="VVSQL.vendor_id" joinType="outer" required="true"/>
                <field name="price_book_id" type="integer" foreignKey="PBSQL.price_book_id" joinType="outer" required="true"/>
                <field name="project_id" type="integer" hidden="true" foreignKey="ProSQL.project_id" joinType="outer"/>
                <field name="item_id" type="text" length="50" required="true"/>
                <field name="description" type="text" length="100"/>
                <field name="item_type" type="integer" foreignKey="CodeSQL.code_id" joinType="outer"/>
                <field name="modifier_id" type="integer"/>
                <field name="typeDescription" type="text" align="left" includeFrom="CodeSQL.description" canEdit="false">
                    <title>
                        <fmt:message key="productType"/>
                    </title>
                </field>
                <field name="adjustment1" type="float" precision="12" decimalPrecision="2" format="0.0#'%'" javaClass="BigDecimal">
                    <title>
                        <fmt:message key="adjust1"/>
                    </title>
                    <validators>
                        <validator type="required">
                            <applyWhen operator="and">
                                <criteria>
                                    <criterion fieldName="adjustment2" operator="notBlank"/>
                                    <criterion fieldName="callFrom" operator="equals" value="single"/>
                                </criteria> 
                            </applyWhen>
                        </validator>
                        <validator type="floatRange" min="0" max="100"/>
                    </validators>
                </field>
                <field name="adjustment2" type="float" precision="12" decimalPrecision="2" format="0.0#'%'" javaClass="BigDecimal">
                    <title>
                        <fmt:message key="adjust2"/>
                    </title>
                    <validators>
                        <validator type="required">
                            <applyWhen operator="and">
                                <criteria>
                                    <criterion fieldName="adjustment3" operator="notBlank"/>
                                    <criterion fieldName="callFrom" operator="equals" value="single"/>
                                </criteria> 
                            </applyWhen>
                        </validator>
                        <validator type="floatRange" min="0" max="100"/>
                    </validators>
                </field>
                <field name="adjustment3" type="float" precision="12" decimalPrecision="2" format="0.0#'%'" javaClass="BigDecimal">
                    <title>
                        <fmt:message key="adjust3"/>
                    </title>
                    <validators>
                        <validator type="floatRange" min="0" max="100"/>
                    </validators>
                </field>
                <field name="adjustment4" type="float" precision="12" decimalPrecision="2" javaClass="BigDecimal">
                    <validators>
                        <validator type="floatRange" min="0" max="360"/>
                    </validators>
                </field>
                <field name="special_net" type="boolean" sqlStorageStrategy="integer"/>
        
                <field name="special_net_cost" type="localeCurrency" precision="12" decimalPrecision="2" javaClass="BigDecimal">
                    <validators>
                        <validator type="required">
                            <applyWhen fieldName="special_net" operator="equals" value="true"/>
                        </validator>
                    </validators>
                </field>
                <field name="labor" type="integer">
                    <title>
                        <fmt:message key="laborMinutes"/>
                    </title>
                    <validators>
                        <validator type="integerRange" min="0"/>
                    </validators>
                </field>
                <field name="installation" type="integer">
                    <title>
                        <fmt:message key="installMinutes"/>
                    </title>
                    <validators>
                        <validator type="integerRange" min="0"/>
                    </validators>
                </field>
                <field name="markup" type="float" precision="12" decimalPrecision="2" javaClass="BigDecimal"/>
                <field name="created_by" type="creator" hidden="true">
                    <title>
                        <fmt:message key="createdBy"/>
                    </title>
                </field>
                <field name="created_time" type="creatorTimestamp" hidden="true">
                    <title>
                        <fmt:message key="createdTime"/>
                    </title>
                </field>
                <field name="modified_by" type="modifier" hidden="true">
                    <title>
                        <fmt:message key="modifiedBy"/>
                    </title>
                </field>
                <field name="modified_time" type="modifierTimestamp" hidden="true">
                    <title>
                        <fmt:message key="modifiedTime"/>
                    </title>
                </field>
        
                <field name="hdwAttrId" type="integer" customSQL="true"/>
                <field name="hdwTypeId" type="text" customSQL="true">
                    <title>
                        <fmt:message key="intType"/>
                    </title>
                </field>
        
                    </fields>
        
            <operationBindings>
        
                <operationBinding operationType="update" operationId="copyAdjustments" serverMethod="copyAdjustments"/>
        
        
            </operationBindings>
        </DataSource>
        Similarly the Server Side code looks like this:

        Code:
        package com.aa.pp.server.services.impl;
        
        import java.util.ArrayList;
        import java.util.HashMap;
        import java.util.HashSet;
        import java.util.List;
        import java.util.Map;
        import java.util.Set;
        import java.util.stream.Collectors;
        
        import org.apache.commons.collections4.CollectionUtils;
        import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
        
        
        import com.isomorphic.criteria.AdvancedCriteria;
        import com.isomorphic.criteria.Criterion;
        import com.isomorphic.criteria.criterion.IsNullCriterion;
        import com.isomorphic.criteria.criterion.SetCriterion;
        import com.isomorphic.criteria.criterion.SimpleCriterion;
        import com.isomorphic.datasource.DSRequest;
        import com.isomorphic.datasource.DSResponse;
        import com.isomorphic.datasource.DSTransaction;
        import com.isomorphic.servlet.RequestContext;
        import com.isomorphic.sql.SQLDataSource;
        
        import lombok.extern.slf4j.Slf4j;
        
        @Slf4j
        public class PriceAdjustmentSQLDS extends SQLDataSource {
        
            /**
             * Block add operation.
             *
             * @param dsRequest {@link DSRequest}
             * @return {@link DSResponse}
             */
            public DSResponse add(final DSRequest dsRequest) {
                throw new UnsupportedOperationException();
            }
        
            /**
             * Block Fetch operation in this call
             *
             * @param dsRequest {@link DSRequest}
             * @return {@link DSResponse}
             */
            public DSResponse fetch(final DSRequest dsRequest) {
                throw new UnsupportedOperationException();
            }
        
            /**
             * Block update operation.
             *
             * @param dsRequest {@link DSRequest}
             * @return {@link DSResponse}
             */
            public DSResponse update(final DSRequest dsRequest) {
                throw new UnsupportedOperationException();
            }
        
            /**
             * Block remove operation.
             *
             * @param dsRequest {@link DSRequest}
             * @return {@link DSResponse}
             */
            public DSResponse remove(final DSRequest dsRequest) {
                throw new UnsupportedOperationException();
            }
        
            public DSResponse copyAdjustments(final DSRequest priceAdjustmentDSRequest) throws ApplicationException {
        
                log.info("copyAdjustment - Start");
                final DSResponse hdwStdAdjustmentData = new DSResponse();
                final long sourcePriceBookID = (Long) DSUtil.getValue(DSConst.PriceAdjustmentSQL.SOURCE_PRICE_BOOK_ID, priceAdjustmentDSRequest.getOldValues(),
                        priceAdjustmentDSRequest.getValues());
                final long targetPriceBookID = (Long) DSUtil.getValue(DSConst.PriceAdjustmentSQL.TARGET_PRICE_BOOK_ID, priceAdjustmentDSRequest.getOldValues(),
                        priceAdjustmentDSRequest.getValues());
                final Long selectedProjectId = (Long) DSUtil.getValue(DSConst.PriceAdjustmentSQL.PROJECT_ID, priceAdjustmentDSRequest.getOldValues(),
                        priceAdjustmentDSRequest.getValues());
                final String sourcePriceBookName = (String) DSUtil.getValue(DSConst.PriceAdjustmentSQL.SOURCE_PRICE_BOOK_NAME, priceAdjustmentDSRequest.getOldValues(),
                        priceAdjustmentDSRequest.getValues());
                final String targetPriceBookName = (String) DSUtil.getValue(DSConst.PriceAdjustmentSQL.TARGET_PRICE_BOOK_NAME, priceAdjustmentDSRequest.getOldValues(),
                        priceAdjustmentDSRequest.getValues());
                final String selectedTab = (String) DSUtil.getValue(DSConst.PriceAdjustmentSQL.SELECTED_TAB, priceAdjustmentDSRequest.getOldValues(),
                        priceAdjustmentDSRequest.getValues());
                final String userCompany = getCompanyId();
                log.debug(
                        "The Source price book id is {} with name {}. The target price book id is {}  with name {}. "
                                + "The project is {}  and selected tab is {} , for the company {}",
                        sourcePriceBookID, sourcePriceBookName, targetPriceBookID, targetPriceBookName, selectedProjectId, selectedTab, userCompany);
        
                final long jobId = getJobSql().add("CopyAdjustments", BatchJobStatusConstants.IN_PROGRESS);
        
                // Process the copy adjustment logic in another thread
                getTaskExecutor().execute(() -> {
                    // boolean value to control whether to mark the job is failed in the finally block
                    boolean exception = true;
                    try {
                        handleCopyAdjusments(selectedProjectId, userCompany, sourcePriceBookID, targetPriceBookID, targetPriceBookName, selectedTab, jobId,
                                priceAdjustmentDSRequest.getContext());
                        exception = false;
                    } catch (final ApplicationException e) {
                        // Handle exceptions, send back the exception as the job note
                        exception = false;
                        log.error("Error copying adjustments", e);
                        getJobSql().update(jobId, BatchJobStatusConstants.ERROR, e.getMessage());
                    } finally {
                        // Mark the job as error if something else went wrong
                        if (exception) {
                            getJobSql().update(jobId, BatchJobStatusConstants.ERROR);
                        }
                    }
                });
        
                // Handle all the three lists with PriceAdjustment data in a single transaction
        
                hdwStdAdjustmentData.setData(jobId);
                return hdwStdAdjustmentData;
        
            }
        
            private void handleCopyAdjusments(final Long selectedProjectId, final String userCompany, final long sourcePriceBookId, final long targetPriceBookId,
                    final String targetPriceBookName, final String selectedTab, final long jobId, final RequestContext context) throws ApplicationException {
                log.info("handleCopyAdjusments - START");
                String message = Constants.SUCCESS_WITH_OUT_DELETE;
                final List<Map<String, Object>> toBeAddedList = new ArrayList<>();
                final List<Map<String, Object>> toBeUpdatedList = new ArrayList<>();
                final List<Map<String, Object>> toBeDeletedList = new ArrayList<>();
                final DSTransaction dsTransaction = new DSTransaction();
                try {
                    // Remember that the price books will have same vendor material and hence the adjustments Item Types will always be same for both target and source
                    // price books.
                    // Step 1: Get discounts if present for the source & target price book id and project ID (if null then only company)
                    final Map<Long, List<Map<String, Object>>> sourcePerItemTypeMap = fetchData(selectedProjectId, userCompany,
                            dsTransaction, sourcePriceBookId);
                    final Map<Long, List<Map<String, Object>>> targetPerItemTypeMap = fetchData(selectedProjectId, userCompany,
                            dsTransaction, targetPriceBookId);
                    // Step 3: If source and target does not have discount entries for any level, just return a message can not be copied
                    // Step 5: If the source does not have price adjustment entries and the target has, then remove the target entries completely. By the virtue of
                    // Database cascading, the values from price_adjustment_attribute tables will also be deleted for target price books.
                    // Step 6:If both the source price book and target price book has price_adjustment entries, then classify the entries based on item_type.
                    // Step 6.a: For Item Type Hdw_price_book, just check of the source and target has entries, update, if only soyrce then add else remove.
                    // Step 6.b: For material_price_book same as above. FOr price_adjustment_attributes fetch entries and handle similarly as above.
                    // Step 6.c: For hdw_tpe entries just check by the item_id and same as 6.a
                    // Step 6.d: for hdw_line entries just check by item_id and same as 6.a
                    // Stem 6.e: for hdw_std entries, check if the ones from source are present for target (based on hdwXREFId). If presentthen update the entry
                    // else , add the entry. For all the unmatched entries in target, delete them
                    // based on the key of source map, pass the list of values from source and target maps to specific handlers.
                    /// Specific handlers will determine the list of records to be updated, added and deleted. The specific handlers will convert the list to map
                    // corresponding to enitityId->Record.
                    // the all the keys from source will be looked into target price book.
                    // We will call handlers for all the ItemType Enum entries and will then decide upon the entries to be handled
        
                    if (Constants.HARDWARE.equals(selectedTab)) {
                        // Hardware specific handling
                        // Call the hardware price book handler
                        handlePriceBookPriceAdjustmentsEntries(sourcePerItemTypeMap.get(ItemTypeEnum.PRICE_BOOK_ADJ.getTitanCodeId()),
                                targetPerItemTypeMap.get(ItemTypeEnum.PRICE_BOOK_ADJ.getTitanCodeId()), toBeAddedList, toBeUpdatedList, toBeDeletedList,
                                sourcePriceBookId, targetPriceBookId, targetPriceBookName);
                        handleHdwTypePriceAdjustmentsEntries(sourcePerItemTypeMap.get(ItemTypeEnum.HDW_TYPE_ADJ.getTitanCodeId()),
                                targetPerItemTypeMap.get(ItemTypeEnum.HDW_TYPE_ADJ.getTitanCodeId()), toBeAddedList, toBeUpdatedList, toBeDeletedList,
                                sourcePriceBookId, targetPriceBookId, dsTransaction);
                        handleHdwLinePriceAdjustmentsEntries(sourcePerItemTypeMap.get(ItemTypeEnum.HDW_LINE_ADJ.getTitanCodeId()),
                                targetPerItemTypeMap.get(ItemTypeEnum.HDW_LINE_ADJ.getTitanCodeId()), toBeAddedList, toBeUpdatedList, toBeDeletedList,
                                sourcePriceBookId, targetPriceBookId, dsTransaction);
                        handleHdwStdPriceAdjustmentsEntries(sourcePerItemTypeMap.get(ItemTypeEnum.HDW_STD_ADJ.getTitanCodeId()),
                                targetPerItemTypeMap.get(ItemTypeEnum.HDW_STD_ADJ.getTitanCodeId()), toBeAddedList, toBeUpdatedList, toBeDeletedList, sourcePriceBookId,
                                targetPriceBookId, dsTransaction);
                        handleHdwModifierPriceAdjustmentsEntries(sourcePerItemTypeMap.get(ItemTypeEnum.HARDWARE_MODIFIERS.getTitanCodeId()),
                                targetPerItemTypeMap.get(ItemTypeEnum.HARDWARE_MODIFIERS.getTitanCodeId()), toBeAddedList, toBeUpdatedList, toBeDeletedList,
                                sourcePriceBookId, targetPriceBookId, dsTransaction);
        
                    } else if (Constants.MATERIAL.equals(selectedTab)) {
                        // Material specific handling
                        handlePriceBookPriceAdjustmentsEntries(sourcePerItemTypeMap.get(ItemTypeEnum.MATERIAL_PRICE_BOOK_ADJ.getTitanCodeId()),
                                targetPerItemTypeMap.get(ItemTypeEnum.MATERIAL_PRICE_BOOK_ADJ.getTitanCodeId()), toBeAddedList, toBeUpdatedList, toBeDeletedList,
                                sourcePriceBookId, targetPriceBookId, targetPriceBookName);
        
                        handleMaterialAttributePriceAdjustmentsEntries(sourcePerItemTypeMap.get(ItemTypeEnum.MATERIAL_ATTR_ADJ.getTitanCodeId()),
                                targetPerItemTypeMap.get(ItemTypeEnum.MATERIAL_ATTR_ADJ.getTitanCodeId()), toBeAddedList, toBeUpdatedList, toBeDeletedList,
                                sourcePriceBookId, targetPriceBookId, dsTransaction);
                    }
        
                    if (CollectionUtils.isNotEmpty(toBeAddedList)) {
                        for (final Map<String, Object> rec : toBeAddedList) {
                            final DSRequest addRequest = new DSRequest(DSConst.PriceAdjustmentSQL.DATASOURCE, DSOperationType.UPDATE.getValue());
                            addRequest.setDsTransaction(dsTransaction);
                            addRequest.setOperationId(DSConst.PriceAdjustmentSQL.ADD_ADJUSTMENT_OPERATION);
                            addRequest.setValues(rec);
                            addRequest.setContext(context);
                            addRequest.execute();
                        }
        
                    }
        
                    if (CollectionUtils.isNotEmpty(toBeUpdatedList)) {
                        for (final Map<String, Object> rec : toBeUpdatedList) {
                            final DSRequest updateRequest = new DSRequest(DSConst.PriceAdjustmentSQL.DATASOURCE, DSOperationType.UPDATE.getValue());
                            updateRequest.setDsTransaction(dsTransaction);
                            updateRequest.setValues(rec);
                            updateRequest.setCriteria(DSConst.PriceAdjustmentSQL.PRICE_ADJUSTMENT_ID, rec.get(DSConst.PriceAdjustmentSQL.PRICE_ADJUSTMENT_ID));
                            updateRequest.setContext(context);
                            updateRequest.execute();
                        }
                    }
        
                    if (CollectionUtils.isNotEmpty(toBeDeletedList)) {
                        final Set<Long> priceadustmemtIdsTobeDeleted = toBeDeletedList.stream()
                                .map(rec -> (Long) rec.get(DSConst.PriceAdjustmentSQL.PRICE_ADJUSTMENT_ID)).collect(Collectors.toSet());
                        final DSRequest deleteRequest = new DSRequest(DSConst.PriceAdjustmentSQL.DATASOURCE, DSOperationType.REMOVE.getValue());
                        deleteRequest.setDsTransaction(dsTransaction);
                        // TODO deleteRequest.setAllowMultiUpdate(true);
                        deleteRequest.addToCriteria(DSConst.PriceAdjustmentSQL.PRICE_ADJUSTMENT_ID, OperatorId.IN_SET.getValue(), priceadustmemtIdsTobeDeleted);
                        deleteRequest.setContext(context);
                        deleteRequest.execute();
                        message = Constants.SUCCESS_WITH_DELETE;
                    }
                    getJobSql().update(jobId, BatchJobStatusConstants.COMPLETED, message);
                } catch (final Exception ex) {
                    throw new ApplicationException("Error while Copying discounts", ex, SmartGWTStatusCode.STATUS_FAILURE);
                } finally {
                    // We put this in a "finally" block to ensure it always runs even on exceptions.
                    dsTransaction.complete();
        
                }
        
                log.info("handleCopyAdjusments - END");
            }
        
        
        
            /**
             * Returns the {@link JobSQLService} bean from the Spring context.
             *
             * @return {@link JobSQLService}
             */
            private JobSQLService getJobSql() {
                return ApplicationContextProvider.getApplicationContext().getBean(JobSQLService.class);
            }
        
            /**
             * Returns the CompanyId from {@link UserAccountService} bean.
             *
             * @return companyId of currently logged in user
             */
            private String getCompanyId() {
                return ApplicationContextProvider.getApplicationContext().getBean(UserAccountService.class).getCurrentLoggedInUserDetails().getCompany();
            }
        
            /**
             * Returns the {@link ThreadPoolTaskExecutor} bean from the Spring context.
             *
             * @return {@link ThreadPoolTaskExecutor}
             */
            private ThreadPoolTaskExecutor getTaskExecutor() {
                return ApplicationContextProvider.getApplicationContext().getBean("psTaskExecutor", ThreadPoolTaskExecutor.class);
            }
        }
        Please note that this is not complete code and will not compile. This is just to give you an idea about how I am using t he standalone DS approach. In the above file, while doing a
        addRequest.execute();
        It is still trying to load the spring context and giving the same exception.

        Please help me in figuring out how I should should stop spring context from getting loaded again.

        Comment


          #19
          Hi,

          Any update on this?
          I need to know how can I stop spring context from getting loaded again. As per me, my above implementation should be working but it is not. Can you please help me with this.

          Comment


            #20
            We don't really have anything to add because you have not provided a test case we can run ourselves, and you are simply pointing us to an error from Spring, not from our software.

            The only new thing we add at this point is: it looks like you have probably configured Spring in such a way that it can't run outside of the context of a servlet engine. Probably if you directly called Spring APIs on your separate thread, you would get the same error that is being indirectly reported to you via SmartGWT. You can very easily verify this. And if true, then there is nothing that SmartGWT can do to help here: your problem is with Spring.

            Comment


              #21
              Hi Team,

              I was able to resolve the issue of Spring context being loaded while executing the DSRequest in a separate thread. Now that the issue seems resolved and the spring context is not reloaded, I am getting an exception while excuting the DSRequest. The log says:

              DEBUG DataSourceDMI - Invocation threw exception
              com.assaabloy.exceptionhandling.core.ApplicationException: Error while adding adjustments
              at com.aa.pp.server.services.impl.PriceAdjustmentSQLDS.addAdjustments(PriceAdjustmentSQLDS.java:79)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.lang.reflect.Method.invoke(Unknown Source)
              at com.isomorphic.base.Reflection._invokeMethod(Reflection.java:581)
              at com.isomorphic.base.Reflection.adaptArgsAndInvoke(Reflection.java:896)
              at com.isomorphic.datasource.DataSourceDMI.execute(DataSourceDMI.java:434)
              at com.isomorphic.datasource.DataSourceDMI.execute(DataSourceDMI.java:64)
              at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:3002)
              at com.aa.pp.server.services.impl.PriceAdjustmentSQLDS.handleCopyAdjusments(PriceAdjustmentSQLDS.java:214)
              at com.aa.pp.server.services.impl.PriceAdjustmentSQLDS.lambda$0(PriceAdjustmentSQLDS.java:122)
              at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
              at java.lang.Thread.run(Unknown Source)
              Caused by: java.lang.IllegalStateException: No SessionManager
              at org.eclipse.jetty.server.Request.getSession(Request.java:1403)
              at org.eclipse.jetty.server.Request.getSession(Request.java:1378)
              at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:279)
              at com.isomorphic.velocity.Velocity.getServletContextMap(Velocity.java:630)
              at com.isomorphic.velocity.Velocity.getStandardContextMap(Velocity.java:576)
              at com.isomorphic.velocity.Velocity.getStandardContextMap(Velocity.java:510)
              at com.isomorphic.sql.SQLDataSource.getVariablesContext(SQLDataSource.java:3666)
              at com.isomorphic.sql.SQLDataSource.SQLExecute(SQLDataSource.java:1786)
              at com.isomorphic.sql.SQLDataSource.processRequest(SQLDataSource.java:441)
              at com.isomorphic.sql.SQLDataSource.executeAdd(SQLDataSource.java:394)
              at com.isomorphic.datasource.DataSource.execute(DataSource.java:2525)
              at com.isomorphic.application.AppBase.executeDefaultDSOperation(AppBase.java:655)
              at com.isomorphic.application.AppBase.executeAppOperation(AppBase.java:556)
              at com.isomorphic.application.AppBase.execute(AppBase.java:499)
              at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:3007)
              at com.aa.pp.server.services.impl.PriceAdjustmentSQLDS.addAdjustments(PriceAdjustmentSQLDS.java:60)
              ... 14 more
              Can you please help me with this.?

              Comment


                #22
                Are you taking a DSRequest, RPCManager, or other object you had in the servlet thread, and trying to use it on your new thread which needs to be standalone? That would cause this issue, and several others, and is invalid usage.

                Comment


                  #23
                  Hi,
                  I am passing the original DSRequest's requestContext object to the new thread. This same was suggested in this post only.

                  My code looks like:

                  Code:
                   getTaskExecutor().execute(() -> {
                              // boolean value to control whether to mark the job is failed in the finally block
                              boolean exception = true;
                              try {
                                  handleCopyAdjusments(spID, uC sPBID, tPBID, tPBName, selectedTab, jobId,
                                          originalRequest.getContext());
                  All the other parameter values are extracted from original request and then passed to new thread task along with the RequestContext object

                  Comment

                  Working...
                  X