My goal is to create a token whenever a page is rendered that contains a component called someTeaser. This someTeaser component renders in the template after the content and before the footer and is not editable. It is configured fixed in the template structure.
The problem appears when I want to create a servlet for someTeaser. This component is not in the Content Repository crxde.
#SlingServletResourceTypes(
resourceTypes = {Constants.ResourceTypes.SOME_TEASER},
selectors = {"token"},
extensions = Constants.Extensions.JSON
)
The resource for this component is /conf/xx/settings/wcm/templates/someTemplate/structure/jcr:content/root/main/container/someTeaser. This resource cannot be resolved in publish. It is not under content but rather under conf.
Request URL: https://publish_server/conf/xxx/settings/wcm/templates/someTemplate/structure/jcr:content/root/main/...
Request Method: GET
Status Code: 404 Not Found
An alternative solution would be to use define resourceTypes = {Constants.ResourceTypes.PAGE} in the servlet but then every page will be checked for the selector token.
Can someone suggest an alternative solution for the task?
I was able to request the token for the container that is avaliable in the JCR repository.
String containerPath = PathBuilder.with(currentPage.getPath())
.slash(AemConstants.JCR_CONTENT)
.slash("root/main/container")
.build();
and resolve the container url nicely using resourceResolver.map(path).
Related
I'm struggling with how to find the content status of a page in Confluence.
My end goal is to be able to change/update via the API.
I've added the list of statuses already in the Manage space section. I have successfully pulled the content of a page as well as its properties, but I can’t seem to find where the content status is stored.
Here is the URI I'm using:
https://MyDomain.atlassian.net/wiki/rest/api/content/145468621376?expand=space,body.storage,view,version.status,container,extentions
That Status is not present in OOB Confluence, so I suppose it is some third-party app from Atlassian Marketplace and you need to check with their documentation how to interact with it.
Of course, you can directly use the REST API to get page content as a string (HTML) and change its content, e.g. using Python (Atlassian Python API’s documentation)
Page actions
def my_page = confluence.get_page_property(page_id, page_property_key)
def new_body = my_page.body.replace("<macro .....>", "<new status in HTML>")
confluence.update_or_create(parent_id, title, new_body, representation='storage')
Finally sorted it out with the help of Atlassian support. If their documentation was correct it would've been super easy to do this.
https://developer.atlassian.com/cloud/confluence/rest/api-group-content-states/#api-group-content-states
Heres the catch. when you GET the status you have to add on the parameter for status even though its optional. so your get string needs to look like this:
your-domain.atlassian.net/wiki/rest/api/content{id}/state?status=current
Same goes for setting the new state. You have to add on the status parameter to the uri.
I'm using AEM 6.3
My servlet config is
#Component(service= Servlet.class,
property={
Constants.SERVICE_DESCRIPTION + "=Example Servlet",
"sling.servlet.methods=" + HttpConstants.METHOD_GET,
"sling.servlet.resourceTypes="+ "my-project/components/general/my-component",
"sling.servlet.extensions=" + "extension",
"sling.servlet.selectors=" + "selector"
})
As you can see I'm not using a page as a resourceType so I'm a little confused. Can anyone tell me what wil be the url to hit on browser so it runs my doGet Method.
And yes My servlet works as I have tested it by giving path.
After a long search and asking help in the AEM community I finally figured it out.
My url will be: http://localhost:4502/content/my-project/homepage/profile-page/test/en/jcr:content/par/my-component.selector.extension
Steps to get your url:
1: Add your component to a parsys in a page.
2: Find your component inside the page in crx/de and copy the url from there which will be like this-> /content/my-project/your-page/jcr:content/(name of your parsys)/your-component
3: now paste this with localhost:4502 in front and add your selector and extension which you have configured. for reference look at my url above.
I generated the json file and gave the path /bin//filename.json . I am able to see the json file in author mode but not in publish. Our aem ops team says they cannot make bin as public. Tried to change the path, using js generated the json path file now at path /content//***/filename.json which I am able to see in author mode but not in publish.
My question is is there any other way that I can try . Please if any other ideas do comment.
Thank you.
Or just simple: Angular get content of page by call .infinity.json
Examp:
Your page is: /mysite/en/home.html
We change to : /mysite/en/home.infinity.json
For more detail: https://forums.adobe.com/thread/2337725
Good luck
We open using url under /bin/.. for SlingServlet
First create a slingSevlet
#SlingServlet(paths="/bin/filename.json", methods = "GET", metatype=true)
Then check the filter and make sure that /bin/filename.json accepts GET requests:
curl 'http://localhost:4502/system/console/configMgr'
Search for 'Apache Sling Referrer Filter'
Check the configuration
I wanted to know if there is a way to get the rendered HTML output of a Page node in CQ5 without hitting the actual url. I have the Page node and I want to get the rendered HTML output of that Page node programmatically in java and store it in a string without hitting the page URL.
Any help is appreciated, thanks in advance!
Node itself it's just a data. Sling framework responsible for rendering this data. It use a bunch of rules to determine how this data should be rendered.Sling Script Resolution Cheet Sheet As Sling is web framework it renders data via http requests.
To emulate this request in CQ/AEM I suggest to use com.day.cq.contentsync.handler.util.RequestResponseFactory service
import org.apache.sling.engine.SlingRequestProcessor;
import com.day.cq.contentsync.handler.util.RequestResponseFactory;
#Reference
private RequestResponseFactory requestResponseFactory;
#Reference
private SlingRequestProcessor requestProcessor;
public String doStuff(){
HttpServletRequest request = requestResponseFactory.createRequest("GET", "/path/to/your/node.html");
request.setAttribute(WCMMode.REQUEST_ATTRIBUTE_NAME, WCMMode.DISABLED);
ByteArrayOutputStream out = new ByteArrayOutputStream();
HttpServletResponse response = requestResponseFactory.createResponse(out);
requestProcessor.processRequest(request, response, resourceResolver);
return out.toString(response.getCharacterEncoding());
}
Hope it helps.
You can access node by providing a correct view. As you need rendered html view, use .html with your node to get rendered html. So your node path will be
/content/path/to/page/jcr:content/par/node_name.html
Now to read html programmatically, you can make an http request to above path from your path, and save response as string.
My Problem: I want to introduce a new field in JIRA with status information from external REST Service (response is json).
Plan: Every Jira issue has a input field with some reference string. Behind this field there should be a panel, what should display informations from the external REST call (parsing response JSON is required).
Can someone give me some good info pages, how to tell JIRA to call external REST Service?
If you don't want to build it see:
nFeed
HTTP Feed Custom Field
If you want to build it yourself then start by following this tutorial on Creating a custom field type which is to more or less store a basic String within the database. (This would be the reference string)
You then have two options, the first is within the JiraCustomField class override the getVelocityParameters which was taken from How to call a java method from velocity Atlassian Answers question.
Then create a method (fetchValueFromWebService(String val)) that you would call that would contain code to query the REST Service based off the fields value that would be passed in from the velocity template. (E.g. $instance.fetchValueFromWebService($value))
To perform the actual web service call you can use any library you want, just see the Managing Dependencies documentation so it gets included in the plugin. (For example using the Jira Jersey version see this)
Your other option would be to within the view-basictext.vm have it use javascript and perform an AJAX to the web service by calling a function in your own JS file and dump that into a span that you have defined: (See Including Javascript and CSS resources)
<span id="webServiceValue"></span>
<script type="text/javascript">
fetchValueFromWebService($value);
</script>
You would however need to ensure that the webservice has Cross-origin resource sharing (CORS) enabled if you go the AJAX route.