On Tue, May 31, 2011 at 2:58 PM, StephanDiplom <
[email protected]> wrote:

>  Hi,
>
> I'm trying to add a simple resource to the REST API but I cannot get access
> to it.
>
> First I wrote a new resouce class:
>
> package org.sipfoundry.sipxconfig.rest;
>
> import static org.restlet.data.MediaType.TEXT_XML;
>
> import java.util.List;
>
> import org.dom4j.Document;
> import org.dom4j.DocumentFactory;
> import org.dom4j.Element;
> import org.restlet.Context;
> import org.restlet.data.Request;
> import org.restlet.data.Response;
> import org.restlet.resource.Representation;
> import org.restlet.resource.Resource;
> import org.restlet.resource.ResourceException;
> import org.restlet.resource.Variant;
> import org.sipfoundry.sipxconfig.admin.callgroup.CallGroup;
> import org.sipfoundry.sipxconfig.common.SipxHibernateDaoSupport;
>
> public class CallGroupResource extends Resource {
>     private static final String QUERY_CALL_GROUP_IDS_WITH_ALIAS =
> "callGroupIdsWithAlias";
>
>     private CallGroup m_callGroup;
>
>
>     @Override
>     public void init(Context context, Request request, Response response) {
>         super.init(context, request, response);
>         String name = (String) getRequest().getAttributes().get("name");
>         PrivateCallGroupFinder finder = new PrivateCallGroupFinder();
>         m_callGroup = finder.getCallGroup("TestGruppe3");
>
>         if (m_callGroup == null) {
>             //setAvailable(false);
>         }
>         getVariants().add(new Variant(TEXT_XML));
>
>     }
>
>     @Override
>     public Representation represent(Variant variant) throws
> ResourceException {
>         if (TEXT_XML.equals(variant.getMediaType())) {
>             return new Dom4jRepresentation(getCallGroupXml());
>         }
>         return new Dom4jRepresentation(getCallGroupXml());
>     }
>
>     static Document getCallGroupXml() {
>         DocumentFactory factory = DocumentFactory.getInstance();
>         Document document = factory.createDocument();
>         Element rootItem = document.addElement("callGroupTest");
>
>         return document;
>     }
>
>     static class PrivateCallGroupFinder extends SipxHibernateDaoSupport{
>         public CallGroup getCallGroup(String name){
>             List ids =
> getHibernateTemplate().findByNamedQueryAndNamedParam(QUERY_CALL_GROUP_IDS_WITH_ALIAS,
> "value", name);
>             CallGroup cg = (CallGroup)
> getHibernateTemplate().load(CallGroup.class, (Integer)ids.get(0));
>
>             return cg;
>         }
>     }
>
> }
>
> After that I added the resouce to rest.beans.xml:
>
> <bean id="callGroupResource"
> class="org.sipfoundry.sipxconfig.rest.CallGroupResource" scope="prototype">
>     <property name="callGroup" ref="callGroup" />
>     <property name="modifiable" value="false" />
> </bean>
> <alias name="callGroupResource" alias="/callgroup" />
>
> Then I ran "ant install" from sipXconfig directory but I always get error
> 404:
>
> <html>
>    <head>
>       <title>Error 404 The server has not found anything matching the
> request URI</title>
>    </head>
>    <body>
>       <h2>HTTP ERROR: 404</h2>
>       <pre>The server has not found anything matching the request URI</pre>
>       <p>RequestURI=/sipxconfig/rest/callgroup</p>
>       <p>
>          <i>
>             <small>
>                <a 
> href="http://jetty.mortbay.org";<http://jetty.mortbay.org>>Powered
> by Jetty://</a>
>             </small>
>          </i>
>       </p>
>    </body>
> </html>
>
> Is there anything I forgot or did wrong?
>
> It looks good. The only thing I can say at first look is to try make &&
make install from your build sipXconfig directory.
Assuming BUILD is the directory where your sipXecs is built, run make &&
make install from BUILD/sipXconfig
Mircea

>
> Regards
> Stephan
>
>
>
> _______________________________________________
> sipx-dev mailing list
> [email protected]
> List Archive: http://list.sipfoundry.org/archive/sipx-dev/
>
_______________________________________________
sipx-dev mailing list
[email protected]
List Archive: http://list.sipfoundry.org/archive/sipx-dev/

Reply via email to