# Getting Image full URL path for REST API

**URL:** <https://community.bloomreach.com/t/getting-image-full-url-path-for-rest-api/617>\
**Category:** Experience Manager (PaaS/OnPrem)\
**Created:** [November 26, 2018, 5:32am UTC](https://community.bloomreach.com/t/getting-image-full-url-path-for-rest-api/617 "2018-11-26T05:32:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sola\_lee](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/sola_lee/32/81_2.png) [@sola\_lee](https://community.bloomreach.com/u/sola_lee)\
**Post date:** [November 26, 2018, 5:32am UTC](https://community.bloomreach.com/t/getting-image-full-url-path-for-rest-api/617/1 "2018-11-26T05:32:38Z")

</div>

Dear Experts,

Following up with

> [@Return Object as POJO](https://community.bloomreach.com/t/return-object-as-pojo/556):
>
> Dear experts, Referring to my previous Topic "From JCR Node to JSON where @Thole wonderfully helped me find a solution. I am able to get the Orang Object from the JCR successfully,. Now I am trying return that object as a Response to a Rest API call. I think HIPPO Bean object are serialized and if I return a POJO (Plain Old Java Object) ,it can be converted as a JSON or XML. This codes is me trying to achieve that: @GET @Path("/test") public Response test(@Context HttpServletRequest r…

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

```JSON
{  
   "id":"a54902a6-114f-45c1-9535-032cab9ab862",
   "name":"cubaorang",
   "displayName":"cubaorang",
   "type":"xxxxxx:OrangDT",
   "locale":"document-type-locale",
   "pubState":"published",
   "pubwfCreationDate":"2018-11-26T13:13:57.287+08:00",
   "pubwfLastModificationDate":"2018-11-26T13:57:37.254+08:00",
   "pubwfPublicationDate":"2018-11-26T13:57:39.528+08:00",
   "items":{  
      "xxxxxx:nama":"Sola",
      "xxxxxx:age":48,
      "xxxxxx:image":{  
         "type":"hippogallerypicker:imagelink",
         "link":{  
            "type":"binary",
            "url":"http://localhost:8080/site/binaries/content/gallery/xxxxxx/orang/test_image.jpg"
         }
      }
   }
}

```

My intention was to hold the image URL for example:  
**“[http://localhost:8080/site/binaries/content/gallery/xxxxxx/orang/test\_image.jpg](http://localhost:8080/site/binaries/content/gallery/xxxxxx/orang/test_image.jpg)”**

```java
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  
**“content/gallery/xxxxxx/orang/test\_image.jpg”**  
missing the entire “[http://localhost:8080/site/binaries/](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?

Regards  
Sola Lee

---

<div class="post-metadata">

**Author:** ![woonsanko](https://avatars.discourse-cdn.com/v4/letter/w/b5a626/32.png) [@woonsanko](https://community.bloomreach.com/u/woonsanko)\
**Post date:** [November 27, 2018, 6:56pm UTC](https://community.bloomreach.com/t/getting-image-full-url-path-for-rest-api/617/2 "2018-11-27T18:56:29Z")

</div>

> [@sola\_lee](#):
>
> My intention was to hold the image URL for example:  
> **“[http://localhost:8080/site/binaries/content/gallery/xxxxxx/orang/test\_image.jpg](http://localhost:8080/site/binaries/content/gallery/xxxxxx/orang/test_image.jpg)”**
> 
> ```java
> package org.finexus.xxxxxx.beans;
> public class Orang_POJO{
> // SNIP
> public Orang_POJO(Orang data) {
> // SNIP
> //imageURL = data.getImage.getPath(); <---- this one
> 
> ```

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

```

---

<div class="post-metadata">

**Author:** ![sola\_lee](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/sola_lee/32/81_2.png) [@sola\_lee](https://community.bloomreach.com/u/sola_lee)\
**Post date:** [November 28, 2018, 5:49am UTC](https://community.bloomreach.com/t/getting-image-full-url-path-for-rest-api/617/3 "2018-11-28T05:49:00Z")

</div>

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)

```java
	@GET
	@Path("/test")
	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);
			System.out.println(myURL);	

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

```

The terminal screen will show

```nohighlight
http://localhost:8080/site/binaries/content/gallery/xxxxxx/orang/test_image.jpg

```

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

Regards  
Sola Lee
