11-07-2016 03:29 AM
Hello,
I would like to use some of the methods in Alfresco's SiteService and respectively its implementation.
For example - I want to list all currently created Sites in Alfresco system in a Java code.
What exactly should I inject in my code and what bean should I include.....Its not exactly clear for me.
Thank you in advance.
11-07-2016 07:08 AM
You also need to add the setter, ie.
public void setSiteService(SiteService siteService)
{
this.siteService = siteService;
}
Regards,
Jan
11-07-2016 03:45 AM
If you want to develop alfresc extensions you can refer to building and packaging extensions into AMPs using Apache Maven ,add <property name="siteService" ref="SiteService"/> into your spring module context.
If you want to develop client application ,you can use apache commons httpclient to call alfresco site webscript api.
11-07-2016 07:04 AM
I have already generated AMP using maven and have folder 'context' with 2 xml service-context and webscript-context.
I want the SiteService as property in my java CustomWebScript class, so I have define the CustomWebScript class in webscript-context.xml
<bean id="webscript.custom.get" class="xxx.demoamp.CustomWebScript" parent="webscript" ></bean>
If I include in this bean <property name="siteService" ref="SiteService"/>
<bean id="webscript.custom.get" class="xxx.demoamp.CustomWebScript" parent="webscript" >
<property name="siteService" ref="SiteService"/>
</bean>
also included private SiteService siteService; as field in my custom Java class.
I receive the following error...
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webscript.custom.get' defined in class path resource [alfresco/module/xxx/context/webscript-context.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException:
Invalid property 'siteService' of bean class [xxx.demoamp.CustomWebScript]: Bean property 'siteService' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
So maybe I don't understand how exactly it works or I miss something...
Thank you in advance for your assistance.
11-07-2016 07:08 AM
You also need to add the setter, ie.
public void setSiteService(SiteService siteService)
{
this.siteService = siteService;
}
Regards,
Jan
11-07-2016 07:40 AM
After added the setting everything is working fine. Thanks!
Would it work with @Inject or @Autowired annotations above the field or ?
In general I can use the existing webscript -> /alfresco/service/api/sites using HttpConnection and get the json object.
However, I will need the server context(host,port) or something in order not to hard-coded it , could you please advise with that option as well ?
11-07-2016 07:45 AM
You can try to use org.springframework.beans.factory.annotation.Autowired.
I'm not clear what you mean about the second question.
11-07-2016 08:02 AM
Well, My second questions is based on your 2nd suggestion ",you can use apache commons httpclient to call alfresco site webscript api."
For example:
URL loginUrl = new URL("http://localhost:8080/alfresco/service/api/sites");
HttpURLConnection connection = (HttpURLConnection) loginUrl.openConnection();
connection.setRequestMethod("GET");
connection.connect();
InputStream is = connection.getInputStream();
//... and get the json object...
dont want to hard code the http://localhost:8080/ (since it can be changed) I want to get the current server/url context or something...not sure if there is such thing at all.
Or there is some other internal option all webscripts to communicate each other?
I will be really glad if you can answer me to the above questions as I am new with Alfresco and trying to understand how it works.....
Thanks.
11-07-2016 10:51 AM
You can configure the base part(http://localhost:8080/alfresco/) in a property file in your application,every time when you call webscript api,you can build the full url by concating base part and path part.
11-08-2016 03:56 AM
I just found that there is SysAdminParams service, which provide the protocol, host, port and alfresco context.
11-08-2016 08:01 AM
You want to call webscript api in alfresco ??
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.