0

I have Page

getRootRequestMapperAsCompound().add(new NoVersionMapper("/card/${cardId}", CardPage.class));. 

On this page there is TinyMCE4 editor. Which try to load images using relative path "images/1.jpg" I've added resource mapping to allow images successfuly loaded.

mountResource("/card/image/${imageId}", imageResourceReference);

In DEVELOPMENT mode everything work nice, image are loaded in to editor, but in DEPLOYMENT mode, Page has been called twice, first time for /card/1 and second time for /card/image/1.jpg.

How to correctly mount resources for DEPLOYMENT mode?

UPDATE look like found the reason

public int getCompatibilityScore(Request request)
{
    return 0; // pages always have priority over resources
}

, but then the question is: "Why it is working nice in development mode"?

Update 2 I haven't find better solution then add my own Resource Mapper with overrided getCompatibilityScore()

public class ImageResourceMapper extends ResourceMapper {

    private String[] mountSegments;

    public ImageResourceMapper(String path, ResourceReference resourceReference) {
        super(path, resourceReference);
        mountSegments = getMountSegments(path);
    }

    public ImageResourceMapper(String path, ResourceReference resourceReference, IPageParametersEncoder encoder) {
        super(path, resourceReference, encoder);
        mountSegments = getMountSegments(path);
    }

    @Override
    public int getCompatibilityScore(Request request) {
        if (urlStartsWith(request.getUrl(), mountSegments)) {
            return 10;
        }
        return 0;
    }
}
Yevgen Kulik
  • 5,713
  • 2
  • 22
  • 44
  • There is no difference between mounting pages and resources in DEV and PROD modes. There must be another reason the page to be hit twice in PROD mode. – martin-g Oct 24 '16 at 15:07
  • Well Could you please help define the difference? i read that there is difference in Resource Locator, but i am aware from it... for mow i see that image mapping have pretty same path. in 2nd circle of page loading in PROD mode i've getting "image" as ${cardID} – Yevgen Kulik Oct 24 '16 at 16:05
  • @Martin What could you suggest to debug in case find the issue? – Yevgen Kulik Oct 24 '16 at 16:33
  • I've just start debug of request mapping and see that Page mapper has score 3 but resource has 0. http://screencloud.net/v/jv21 (on the screenshot 1- look like some behaviour. it has null hander,) 2- it's page one 3- it's my Resource – Yevgen Kulik Oct 24 '16 at 16:43

0 Answers0