Getting Image full URL path for REST API

Dear Experts,

Following up with

I added image to the document type thus now the Document Type call Orang (Person) has the following fields a name (nama) and age and an image.

I used essential → Bean Writer to generate the Java files
I used essential → REST Service Setup to generate the API (generic and manual)

In the generic REST Resource I get this very nice JSON


My intention was to hold the image URL for example:

package org.finexus.xxxxxx.beans;
public class Orang_POJO{
	public String nama;
	public String age;
	public String imageURL;

	public Orang_POJO(Orang data) {
		nama = data.getNama();
		age = data.getAge();
		imageURL = data.getImage.getPath(); <---- this one
	public String getNama() {return nama;}
	public void setNama(String nama) {this.nama = nama;}
	public String getAge() {return age;}
	public void setAge(String age) {this.age = age;}	
	public String getImageURL() {return imageURL;}
	public void setImageURL(String age) {this.imageURL = imageURL;}	

BUT for my java file above (refer to ← this one) it shows me only the xpath below
missing the entire “http://localhost:8080/site/binaries/

I can always add the missing part to my string but that will be cheating.
How do I get the full path like the one in generic?

Sola Lee

          // ----> like this:
          HstRequestContext requestContext = RequestContextProvider.get();
          HstLink hstLink = requestContext.getHstLinkCreator().create(data.getImage(), requestContext);
          imageURL = hstLink.toUrlForm(requestContext, true);
1 Like

Dear @woonsanko

Thank you for your reply,

I am going to try this our and if successful I will share the codes (Edited: Yes it works beautiful)

	public String test(@Context HttpServletRequest request) throws Exception {
		Session session = null;
		String myURL = null;
		try {
			HippoRepository repository = HippoRepositoryFactory.getHippoRepository("vm://");
			session = repository.login("admin","admin".toCharArray());	
			Node node = session.getRootNode().getNode("content/documents/xxxxxx/cubaorang/cubaorang[3]/xxxxxx:Orang");	
			HstRequestContext context = RequestContextProvider.get();		
			Orang org = (Orang) context.getObjectConverter().getObject(node);

			HstLink hstLink = context.getHstLinkCreator().create(org.getImage(), context);
			myURL = hstLink.toUrlForm(context, true);

		}catch(Exception e) {
			throw  e;	
		}finally {
		return Response.ok(myURL ,MediaType.TEXT_HTML).build();

The terminal screen will show


Orang org is generated by HIPPO (via essential bean writer) which extends BaseDocument
and org.getImage() will return a HippoGalleryImageSet.

Sola Lee