Hi Everyone,
Can anyone help me how to write sevlet for this dialog, I want fetch html from external URL.
Thanks in advance.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @vinuu123 I am referring the API to the external URL. You can get it via annoations.
@Inject
@Optional
@Named("externalUrl")
protected String externalUrl;
Thanks
Hi @vinuu123
I am not sure if I am exactly following the requirement here but in case your ask is to invoke the servlet from dialog you can try the implementation in the below link.
https://aemsimplifiedbynikhil.wordpress.com/2018/07/30/call-any-servlet-in-touchui-dialog-aem-6-3/
You can also bind with a slingmodel in backend and then read the content in backend with URL configured from the dialog also and can avoid servlet if that works.
Hi @vinuu123 You can read the value of the URL in the sling dialog and then use the below code to get the extract of the entire html section
@Model(adaptables = {Resource.class, SlingHttpServletRequest.class}, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class HtmlModel{
private static final Logger logger = LoggerFactory.getLogger(HtmlModel.class);
@Getter
private String body;
@PostConstruct
void init() {
final String api = <read it from dialog>;
final HttpGet httpRequest = new HttpGet(api);
try (final CloseableHttpResponse response = HttpClients.createDefault().execute(httpRequest)) {
body = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
} catch (final IOException e) {
logger.error("IOException while reading HTML API %s: ", e);
}
}
}
Hope this helps!
Thanks
@ShaileshBassi , here what is api ?
this is my html for entering external url from dialog
can you help me here?
Hi @vinuu123 I am referring the API to the external URL. You can get it via annoations.
@Inject
@Optional
@Named("externalUrl")
protected String externalUrl;
Thanks
Views
Likes
Replies