Search code examples
javasap-commerce-cloud

Get Server error when accessing an address, but no stack trace


I have a hybris website with a single mapping. Each time I try to access a particular url:

enter image description here

Is there any way to debug such an error?

This is the controller of the page:

@Controller
@RequestMapping(value = "/cart")
public class CartPageController extends AbstractPageController
{
    private static final String CART_CMS_PAGE = "cartPage";
    private static final Integer DEFAULT_COOKIE_EXPIRY_AGE = 5184000;
    private static final String DEFAULT_CART_IDENTIFIER_COOKIE_NAME = "cart.identifier.cookie.name";
    private static final Logger LOG = Logger.getLogger(CartPageController.class);


    @Resource(name = "cartFacade")
    private CartFacade cartFacade;

    @Resource(name = "userService")
    private UserService userService;

    @Resource(name = "baseStoreService")
    private BaseStoreService baseStoreService;

    @Resource(name = "catalogVersionService")
    private CatalogVersionService catalogVersionService;

    @RequestMapping(method = RequestMethod.GET)
    public String showCart(HttpServletRequest request, HttpServletResponse response, final Model model)
            throws CMSItemNotFoundException
    {

        CartData cartData = cartFacade.getSessionCartWithEntryOrdering(true);

        final String cartCookieIdentifier = getCartCookieIdentifier();

        if (!cartFacade.hasEntries())
        {
            final String cartId = getCookieValue(request, cartCookieIdentifier);

            final Optional<CartData> cartDataOptional = cartFacade.getCartsForCurrentUser().stream()
                    .filter(c -> c.getCode().equals(cartId)).findFirst();

            if (cartDataOptional.isPresent())
            {
                cartData = cartDataOptional.get();
            }
        }

        setCookieValue(response, cartCookieIdentifier, cartData.getCode());
        model.addAttribute("cart", cartData);

        setupPageModel(model);

        String model1 = getViewForPage(model);

        return model1;

    }

    protected void setupPageModel(Model model) throws CMSItemNotFoundException
    {
        storeCmsPageInModel(model, getContentPageForLabelOrId(CART_CMS_PAGE));
        setUpMetaDataForContentPage(model, getContentPageForLabelOrId(CART_CMS_PAGE));
    }

    protected String getCookieValue(final HttpServletRequest request, final String cookieName)
    {
        return Arrays.stream(request.getCookies())
                .filter(c -> c.getName().equals(cookieName))
                .findFirst()
                .map(Cookie::getValue)
                .orElse(null);
    }

    protected void setCookieValue(final HttpServletResponse response, final String cookieName, final String cookieValue)
    {
        final Cookie cookie = new Cookie(cookieName, cookieValue);
        cookie.setMaxAge(DEFAULT_COOKIE_EXPIRY_AGE);

        response.addCookie(cookie);
    }

    protected String getCartCookieIdentifier()
    {
        final String baseStoreId = getCurrentBaseStoreId();
        final String catalogId = getCurrentProductCatalogId();

        if (StringUtils.isNotEmpty(baseStoreId) && StringUtils.isNotEmpty(catalogId))
        {
            return baseStoreId + "-" + catalogId;
        }

        return DEFAULT_CART_IDENTIFIER_COOKIE_NAME;
    }

    protected String getCurrentBaseStoreId()
    {
        final BaseStoreModel baseStore = baseStoreService.getCurrentBaseStore();
        return baseStore == null ? StringUtils.EMPTY : baseStore.getUid();
    }

    protected String getCurrentProductCatalogId()
    {
        for (final CatalogVersionModel catalogVersionModel : catalogVersionService.getSessionCatalogVersions())
        {
            if (!((catalogVersionModel.getCatalog() instanceof ContentCatalogModel) || (catalogVersionModel
                    .getCatalog() instanceof ClassificationSystemModel)))
            {
                return catalogVersionModel.getCatalog().getId();
            }
        }
        return StringUtils.EMPTY;
    }
}

The content of the jsp page is not really that important since it can be empty and this behaviour still happens. I do not know exactly what could be the root of this. Is there any effective way to debug such issues?


Solution

  • This is a usual bug when creating B2B Sites. A workaround is to open the /smartedit and login to your site from there. Hybris will create a proper session and you should be able to open the site.

    Possible long time solution: If you are creating a B2B site, check spring-filter-config.xml in your Storefront extension and check this section. It should look like this:

        <alias name="b2cAcceleratorSiteChannels" alias="acceleratorSiteChannels"/>
        <util:set id="b2cAcceleratorSiteChannels" value-type="de.hybris.platform.commerceservices.enums.SiteChannel">
            <ref bean="SiteChannel.B2C"/>
            <ref bean="SiteChannel.B2B"/>
        </util:set>
    

    You can remove the SiteChannel.B2C if everything is fine