Persistent Query Execution Works fine in Local Instance Programmatically but not on AEM dev instance
Hi,
I have created below method to execute the graphql query , It works fine on the local but on the dev server it's not working due to unauthorized, I tried to create using service user but that also not working . Does anyone excuted graphql query using basic authentication or any other approach in AEM 6.5
HttpPost httpPost = new HttpPost(GRAPHQL_ENDPOINT);
httpPost.setHeader("Content-Type", "application/json");
RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(5000)
.setConnectTimeout(5000)
.build();
try (CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build()) {
String username = "admin";
String password = "admin";
String auth = username + ":" + password;
String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes());
httpPost.setHeader("Authorization", "Basic " + encodedAuth);
StringEntity requestEntity = new StringEntity("{\"variables\":" + variables + "}");
httpPost.setEntity(requestEntity);
try (CloseableHttpResponse httpResponse = httpClient.execute(httpPost)) {
int statusCode = httpResponse.getStatusLine().getStatusCode();
logger.debug("HTTP Response Status Code: {}", statusCode);
if (statusCode == 200) {
HttpEntity responseEntity = httpResponse.getEntity();
String jsonResponse = EntityUtils.toString(responseEntity);