Hello,

I remember having to tell restlet to allow cross domain posts using a specific 
route for a crossdomain.xml file like this:

private static final String CLIENT_ACCESS_POLICY = "/crossdomain.xml";
router.attach(CLIENT_ACCESS_POLICY, ClientAccessPolicy.class);
and having the route defined like the code below.  In this one localhost ie 
127.0.0.1 is allowed to post.  This code was written back in the early days of 
restlet 2 so might be a bit out of date now.

import java.io.IOException;
import java.util.logging.Level;
import org.apache.log4j.Logger;


import org.restlet.data.MediaType;
import org.restlet.ext.xml.DomRepresentation;


import org.restlet.representation.Representation;
import org.restlet.representation.Variant;



import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;


import org.w3c.dom.Document;

import org.w3c.dom.Element;

public class ClientAccessPolicy extends ServerResource {
        
        private static final String LOGGER_NAME = "org.mortbay.log";
        private static Logger logger = 
Logger.getLogger(ClientAccessPolicy.class);


        @Get("xml")
        public Representation accessAllowed(Variant variant) {
                
                logger.info("client access");

                if (MediaType.TEXT_XML.equals(variant.getMediaType())) {

                        try {

                                DomRepresentation representation = new 
DomRepresentation(

                                MediaType.TEXT_XML);

                                // Generate a DOM document representing the 
list of

                                // items.

                                Document d = representation.getDocument();

                                Element accesspolicy = 
d.createElement("cross-domain-policy");

                                d.appendChild(accesspolicy);

                                Element crossdomainaccess = d
                                                
.createElement("allow-access-from");
                                crossdomainaccess.setAttribute("domain", 
"127.0.0.1");
                                crossdomainaccess.setAttribute("secure", 
"false");
                

                                accesspolicy.appendChild(crossdomainaccess);

                                d.normalizeDocument();

                                // Returns the XML representation of this 
document.

                                return representation;

                        } catch (IOException e) {

                                e.printStackTrace();

                        }

                }

                return null;

        }

}


Cheers,

Ian

On 29 Mar 2011, at 22:33, Jason Richards wrote:

> I have been trying to do a JSON post request with jquery to a restlet 
> service. Every the post is attempted it shows up on the server as an HTML 
> Options request with an error of 405. From what I have read this is a problem 
> with Cross Domain scripting. How do you do a post to the restlet built in 
> server with javascript or jQuery?
> 
> ------------------------------------------------------
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2715100

Ian Dunlop
myGrid Team
School of Computer Science
University of Manchester

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2715572

Reply via email to