This tutorial shows you how to develop SOAP and REST CXF Web Services in Alfresco.
1. CXF to get at /services/ context File : web.xml
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
2. CXF SOAP Service – Alfresco
@WebService(targetNamespace = "http://soap.sample.alfresco.org", name = "AlfrescoSearchService")
public interface AlfrescoSearchService {
@WebMethod
public SearchResponse searchAlfrescoRepository(@WebParam(name = "searchString") String searchString) throws java.rmi.RemoteException;
}
*Note: Configuration file is present in Source Code and Binaries.
3. Access CXF SOAP Service – Alfresco From Chrome Client
http://localhost:8080/alfresco/services/AlfrescoSearchService?wsdl
Request Object
Output/Response
<soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:body>
<ns2:searchalfrescorepositoryresponse xmlns:ns2="http://soap.sample.alfresco.org">
<return>
<jsonresult>{"JSONKey":[{"created":"Fri May 03 17:41:15 IST 2013","nodename":"alfresco docs.js.sample","modified":"Fri May 03 17:41:15 IST 2013"},{"created":"Fri May 03 17:41:18 IST 2013","nodename":"emailbody_textplain_alfresco.ftl","modified":"Fri May 03 17:41:18 IST 2013"},{"created":"Fri May 03 17:41:18 IST 2013","nodename":"emailbody_texthtml_alfresco.ftl","modified":"Fri May 03 17:41:18 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_textplain_alfresco_it.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_texthtml_alfresco_it.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:18 IST 2013","nodename":"emailbody_textplain_alfresco_de.ftl","modified":"Fri May 03 17:41:18 IST 2013"},{"created":"Fri May 03 17:41:18 IST 2013","nodename":"emailbody_texthtml_alfresco_de.ftl","modified":"Fri May 03 17:41:18 IST 2013"},{"created":"Fri May 03 17:41:18 IST 2013","nodename":"emailbody_textplain_alfresco_es.ftl","modified":"Fri May 03 17:41:18 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_texthtml_alfresco_es.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_textplain_alfresco_fr.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_texthtml_alfresco_fr.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_textplain_alfresco_ja.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_texthtml_alfresco_ja.ftl","modified":"Fri May 03 17:41:19 IST 2013"}]}
</jsonresult>
</return>
</ns2:searchalfrescorepositoryresponse>
</soap:body>
</soap:envelope>
4. CXF REST Service – Alfresco
You will need to add “javax.ws.rs-api-2.0-m02.jar” and WEB-INF lib of your alfresco deployed folder.
@WebService(serviceName = "AlfrescoRestSearchService", targetNamespace = "http://soap.sample.alfresco.org")
public class AlfrescoRestSearchServiceImpl {
.................
@GET
@Path("/query")
public Response searchAlfrescoRepository(@QueryParam("searchString") String searchString){
SearchResponse responseObject = searchObject.searchRepository(searchString);
return Response.ok(responseObject).build();
}
}
*Note: Configuration file is present in Source Code and Binaries.
5. Access CXF REST Service
Request
http://localhost:8080/alfresco/services/AlfrescoRestSearchService/query?searchString=Alfresco
Output/Response
<SearchResponse>
<jsonResult>
{"JSONKey":[{"created":"Fri May 03 17:41:15 IST 2013","nodename":"alfresco docs.js.sample","modified":"Fri May 03 17:41:15 IST 2013"},{"created":"Fri May 03 17:41:18 IST 2013","nodename":"emailbody_textplain_alfresco.ftl","modified":"Fri May 03 17:41:18 IST 2013"},{"created":"Fri May 03 17:41:18 IST 2013","nodename":"emailbody_texthtml_alfresco.ftl","modified":"Fri May 03 17:41:18 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_textplain_alfresco_it.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_texthtml_alfresco_it.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:18 IST 2013","nodename":"emailbody_textplain_alfresco_de.ftl","modified":"Fri May 03 17:41:18 IST 2013"},{"created":"Fri May 03 17:41:18 IST 2013","nodename":"emailbody_texthtml_alfresco_de.ftl","modified":"Fri May 03 17:41:18 IST 2013"},{"created":"Fri May 03 17:41:18 IST 2013","nodename":"emailbody_textplain_alfresco_es.ftl","modified":"Fri May 03 17:41:18 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_texthtml_alfresco_es.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_textplain_alfresco_fr.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_texthtml_alfresco_fr.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_textplain_alfresco_ja.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_texthtml_alfresco_ja.ftl","modified":"Fri May 03 17:41:19 IST 2013"}]}
</jsonResult>
</SearchResponse>
1. CXF to get at /services/ context File : web.xml
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
2. CXF SOAP Service – Alfresco
@WebService(targetNamespace = "http://soap.sample.alfresco.org", name = "AlfrescoSearchService")
public interface AlfrescoSearchService {
@WebMethod
public SearchResponse searchAlfrescoRepository(@WebParam(name = "searchString") String searchString) throws java.rmi.RemoteException;
}
*Note: Configuration file is present in Source Code and Binaries.
3. Access CXF SOAP Service – Alfresco From Chrome Client
http://localhost:8080/alfresco/services/AlfrescoSearchService?wsdl
Request Object
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<searchAlfrescoRepository xmlns="http://soap.sample.alfresco.org">
<searchString xmlns="">Alfresco</searchString>
</searchAlfrescoRepository>
</Body>
</Envelope>
Output/Response
<soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:body>
<ns2:searchalfrescorepositoryresponse xmlns:ns2="http://soap.sample.alfresco.org">
<return>
<jsonresult>{"JSONKey":[{"created":"Fri May 03 17:41:15 IST 2013","nodename":"alfresco docs.js.sample","modified":"Fri May 03 17:41:15 IST 2013"},{"created":"Fri May 03 17:41:18 IST 2013","nodename":"emailbody_textplain_alfresco.ftl","modified":"Fri May 03 17:41:18 IST 2013"},{"created":"Fri May 03 17:41:18 IST 2013","nodename":"emailbody_texthtml_alfresco.ftl","modified":"Fri May 03 17:41:18 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_textplain_alfresco_it.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_texthtml_alfresco_it.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:18 IST 2013","nodename":"emailbody_textplain_alfresco_de.ftl","modified":"Fri May 03 17:41:18 IST 2013"},{"created":"Fri May 03 17:41:18 IST 2013","nodename":"emailbody_texthtml_alfresco_de.ftl","modified":"Fri May 03 17:41:18 IST 2013"},{"created":"Fri May 03 17:41:18 IST 2013","nodename":"emailbody_textplain_alfresco_es.ftl","modified":"Fri May 03 17:41:18 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_texthtml_alfresco_es.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_textplain_alfresco_fr.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_texthtml_alfresco_fr.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_textplain_alfresco_ja.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_texthtml_alfresco_ja.ftl","modified":"Fri May 03 17:41:19 IST 2013"}]}
</jsonresult>
</return>
</ns2:searchalfrescorepositoryresponse>
</soap:body>
</soap:envelope>
4. CXF REST Service – Alfresco
You will need to add “javax.ws.rs-api-2.0-m02.jar” and WEB-INF lib of your alfresco deployed folder.
@WebService(serviceName = "AlfrescoRestSearchService", targetNamespace = "http://soap.sample.alfresco.org")
public class AlfrescoRestSearchServiceImpl {
.................
@GET
@Path("/query")
public Response searchAlfrescoRepository(@QueryParam("searchString") String searchString){
SearchResponse responseObject = searchObject.searchRepository(searchString);
return Response.ok(responseObject).build();
}
}
*Note: Configuration file is present in Source Code and Binaries.
5. Access CXF REST Service
Request
http://localhost:8080/alfresco/services/AlfrescoRestSearchService/query?searchString=Alfresco
Output/Response
<SearchResponse>
<jsonResult>
{"JSONKey":[{"created":"Fri May 03 17:41:15 IST 2013","nodename":"alfresco docs.js.sample","modified":"Fri May 03 17:41:15 IST 2013"},{"created":"Fri May 03 17:41:18 IST 2013","nodename":"emailbody_textplain_alfresco.ftl","modified":"Fri May 03 17:41:18 IST 2013"},{"created":"Fri May 03 17:41:18 IST 2013","nodename":"emailbody_texthtml_alfresco.ftl","modified":"Fri May 03 17:41:18 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_textplain_alfresco_it.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_texthtml_alfresco_it.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:18 IST 2013","nodename":"emailbody_textplain_alfresco_de.ftl","modified":"Fri May 03 17:41:18 IST 2013"},{"created":"Fri May 03 17:41:18 IST 2013","nodename":"emailbody_texthtml_alfresco_de.ftl","modified":"Fri May 03 17:41:18 IST 2013"},{"created":"Fri May 03 17:41:18 IST 2013","nodename":"emailbody_textplain_alfresco_es.ftl","modified":"Fri May 03 17:41:18 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_texthtml_alfresco_es.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_textplain_alfresco_fr.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_texthtml_alfresco_fr.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_textplain_alfresco_ja.ftl","modified":"Fri May 03 17:41:19 IST 2013"},{"created":"Fri May 03 17:41:19 IST 2013","nodename":"emailbody_texthtml_alfresco_ja.ftl","modified":"Fri May 03 17:41:19 IST 2013"}]}
</jsonResult>
</SearchResponse>