0
votes

I'm working on Hybris Version 5.4.0, and specifically on a Job exporting my datas. I would like the full external path (i.e. the URL) of my media to be exported instead of the relative path

Ex: /medias/sys_master/h76/hd6/8865465963102.jpg --> http://myserver:myport/medias/sys_master/h76/hd6/8865465963102.jpg

I've seen ways to do it in Hybris Wiki using static declarations in locale, but I would like to programatically do it, as my app could be run on various servers and environments.

I've already tried common ways to get server address in Java (for example using INet) but it didn't work.

Finally, I've seen that in HMC, the exact information I want is displayed at the end here :

Copyright (c) 2000-2013 hybris AG - hybris   
Version:    null
    5.4.0.0
    Last compile: 20180410 1543
    Release date: 20141113 1921
Server: localhost:9101
Locale: English (United Kingdom) - en_GB
Timezone:   Central European Time - Europe/Paris

but it's catching a servlet request in defaultContent_jsp.java (then out.print(request.getServerName()+":"+request.getServerPort());), do I have a way to spread this information to my Jobs ?

1

1 Answers

2
votes

Configure media URL in property file

change mycmssite and mysite with your respective value

media.mycmssite.http=https\://www.mysite.com
media.mycmssite.https=https\://www.mysite.com

Get MediaUrlForSite in your job

  • Get current session site
  • Get getMediaUrlForSite
  • Concate getMediaUrlForSite and mediaURL

@Resource(name = "cmsSiteService")
private CMSSiteService cmsSiteService;

@Resource(name = "siteBaseUrlResolutionService")
private SiteBaseUrlResolutionService siteBaseUrlResolutionService;

MediaModel media = ...
final CMSSiteModel currentSite = cmsSiteService.getCurrentSite();

final String mediaUrlForSite = siteBaseUrlResolutionService.getMediaUrlForSite(currentSite, true, "");

String downloadURL = mediaUrlForSite + media .getURL()