Package org.restlet.data

Examples of org.restlet.data.Response


                "'prop2':2," +
                "'prop3':3" +
             "}}";

        Request request = newRequestPOST("foo",json,"text/json");
        Response response = new Response(request);
       
        FooReflectiveResource resource = new FooReflectiveResource( null, request, response );
        resource.handlePost();
       
        assertEquals( "one", resource.posted.prop1 );
View Full Code Here


                "<prop1>one</prop1>" +
                "<prop2>2</prop2>" +
                "<prop3>3.0</prop3>" +
            "</org.geoserver.rest.Foo>";
        Request request = newRequestPOST("foo",xml,"text/xml");
        Response response = new Response(request);
       
        FooReflectiveResource resource = new FooReflectiveResource( null, request, response );
        resource.handlePut();
       
        assertEquals( "one", resource.puted.prop1 );
View Full Code Here

    }
   
    public void testGetWithAcceptsHeader() throws Exception {
        Request request = newRequestGET( "foo" );
        request.getClientInfo().getAcceptedMediaTypes().add( new Preference<MediaType>(MediaType.TEXT_XML) );
        Response response = new Response(request);
       
        FooReflectiveResource resource = new FooReflectiveResource( null, request, response );
        resource.handleGet();
       
        Document dom = getDOM( response );
View Full Code Here

public class MapResourceTest extends RestletTestSupport {

    public void testMapGET() throws Exception {
        Request request = newRequestGET( "foo.xml" );
        Response response = new Response(request);
       
        FooMapResource resource = new FooMapResource( null, request, response );
        resource.handleGet();
       
        Document dom = getDOM( response );
View Full Code Here

                "<prop1>one</prop1>" +
                "<prop2>2</prop2>" +
                "<prop3>3.0</prop3>" +
            "</org.geoserver.rest.Foo>";
        Request request = newRequestPOST("foo",xml,"text/xml");
        Response response = new Response(request);
       
        FooMapResource resource = new FooMapResource( null, request, response );
        resource.handlePost();
       
        assertEquals( "one", resource.posted.get("prop1") );
View Full Code Here

                "<prop1>one</prop1>" +
                "<prop2>2</prop2>" +
                "<prop3>3.0</prop3>" +
            "</root>";
        Request request = newRequestPOST("foo",xml,"text/xml");
        Response response = new Response(request);
       
        FooMapResource resource = new FooMapResource( null, request, response );
        resource.handlePut();
       
        assertEquals( "one", resource.puted.get("prop1") );
View Full Code Here

public class ReflectiveResourceTest extends RestletTestSupport {

    public void testObjectGetAsXML() throws Exception {
        Request request = newRequestGET( "foo.xml" );
        Response response = new Response(request);
       
        FooReflectiveResource resource = new FooReflectiveResource( null, request, response );
        resource.handleGet();
       
        Document dom = getDOM( response );
View Full Code Here

    }
   
    @Override
    public void handlePut() {
        Request request = getRequest();
        Response response = getResponse();
       
        String workspace = (String)request.getAttributes().get("workspace");
        String coveragestore = (String)request.getAttributes().get("coveragestore");
        String format = (String)request.getAttributes().get("format");
        String method = ((String) request.getResourceRef().getLastSegment()).toLowerCase();
       
        File directory = null;
        boolean isExternal = true;
       
        // Prepare the directory only in case this is not an external upload
        if (method != null && (method.startsWith("file.") || method.startsWith("url."))){
            isExternal = false;
            try {
                 directory = catalog.getResourceLoader().createDirectory( "data/" + coveragestore );
            }
            catch (IOException e) {
                throw new RestletException( e.getMessage(), Status.SERVER_ERROR_INTERNAL, e );
            }
        }
        final File uploadedFile = handleFileUpload(coveragestore, format, directory);
       
        // /////////////////////////////////////////////////////////////////////
        //
        // Add overviews to the Coverage
        //
        // /////////////////////////////////////////////////////////////////////
        Form form = request.getResourceRef().getQueryAsForm();
        if ("yes".equalsIgnoreCase(form.getFirstValue("overviews")) ) {
            /* TODO: Add overviews here */;
        }
           
        //create a builder to help build catalog objects
        CatalogBuilder builder = new CatalogBuilder(catalog);
        builder.setWorkspace( catalog.getWorkspaceByName( workspace ) );
       
        //create the coverage store
        CoverageStoreInfo info = catalog.getCoverageStoreByName(workspace, coveragestore);
        boolean add = false;
        if ( info == null ) {
            //create a new coverage store
            LOGGER.info("Auto-configuring coverage store: " + coveragestore);
           
            info = builder.buildCoverageStore(coveragestore);
            add = true;
        }
        else {
            //use the existing
            LOGGER.info("Using existing coverage store: " + coveragestore);
        }
       
        info.setType(coverageFormat.getName());
        if (!isExternal) {
            info.setURL("file:data/" + coveragestore + "/" + uploadedFile.getName() );
        }
        else {
            try {
                info.setURL( uploadedFile.toURL().toExternalForm());
            } catch (MalformedURLException e) {
                throw new RestletException( "url error", Status.SERVER_ERROR_INTERNAL, e );
            }
        }
       
        //add or update the datastore info
        if ( add ) {
            catalog.add( info );
        }
        else {
            catalog.save( info );
        }
       
        builder.setStore(info);
       
        //check configure parameter, if set to none to not try to configure coverage
        String configure = form.getFirstValue( "configure" );
        if ( "none".equalsIgnoreCase( configure ) ) {
            getResponse().setStatus( Status.SUCCESS_CREATED );
            return;
        }
       
        String coverage = uploadedFile.getName();
        if ( coverage.indexOf( '.') != -1 ) {
            coverage = coverage.substring( 0, coverage.indexOf( '.') );
        }
       
        try {
            AbstractGridCoverage2DReader reader =
                (AbstractGridCoverage2DReader) ((AbstractGridFormat) coverageFormat).getReader(uploadedFile.toURL());
            if ( reader == null ) {
                throw new RestletException( "Could not aquire reader for coverage.", Status.SERVER_ERROR_INTERNAL );
            }
           
            CoverageInfo cinfo = builder.buildCoverage( reader );
           
            //check if the name of the coverage was specified
            String coverageName = form.getFirstValue("coverageName");
            if ( coverageName != null ) {
                cinfo.setName( coverageName );
            }
           
            if ( !add ) {
                //update the existing
                CoverageInfo existing = catalog.getCoverageByCoverageStore(info,
                    coverageName != null ? coverageName : coverage );
                if ( existing == null ) {
                    //grab the first if there is only one
                    List<CoverageInfo> coverages = catalog.getCoveragesByCoverageStore( info);
                    if ( coverages.size() == 1 ) {
                        existing = coverages.get(0);
                    }
                    if ( coverages.size() == 0 ) {
                        //no coverages yet configured, change add flag and continue on
                        add = true;
                    }
                    else {
                        // multiple coverages, and one to configure not specified
                        throw new RestletException( "Unable to determine coverage to configure.", Status.SERVER_ERROR_INTERNAL);
                    }
                }
               
                if ( existing != null ) {
                    builder.updateCoverage(existing,cinfo);
                    catalog.save( existing );
                    cinfo = existing;
                }
            }
           
            //do some post configuration, if srs is not known or unset, transform to 4326
            if ("UNKNOWN".equals(cinfo.getSRS())) {
                //CoordinateReferenceSystem sourceCRS = cinfo.getBoundingBox().getCoordinateReferenceSystem();
                //CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326", true);
                //ReferencedEnvelope re = cinfo.getBoundingBox().transform(targetCRS, true);
                cinfo.setSRS( "EPSG:4326" );
                //cinfo.setCRS( targetCRS );
                //cinfo.setBoundingBox( re );
            }

            //add/save
            if ( add ) {
                catalog.add( cinfo );
               
                LayerInfo layerInfo = builder.buildLayer( cinfo );
                //JD: commenting this out, these sorts of edits should be handled
                // with a second PUT request on the created coverage
                /*
                String styleName = form.getFirstValue("style");
                if ( styleName != null ) {
                    StyleInfo style = catalog.getStyleByName( styleName );
                    if ( style != null ) {
                        layerInfo.setDefaultStyle( style );
                        if ( !layerInfo.getStyles().contains( style ) ) {
                            layerInfo.getStyles().add( style );
                        }
                    }
                    else {
                        LOGGER.warning( "Client specified style '" + styleName + "'but no such style exists.");
                    }
                }

                String path = form.getFirstValue( "path");
                if ( path != null ) {
                    layerInfo.setPath( path );
                }
                */

                catalog.add(layerInfo);
            }
            else {
                catalog.save( cinfo );
               
                //TODO: update the layers pointing at this coverage
            }
           
            //poach the coverage store data format
            DataFormat df = new CoverageStoreResource(getContext(),request,response,catalog)
                .createXMLFormat(request, response);
            response.setEntity(df.toRepresentation(info));
            response.setStatus(Status.SUCCESS_CREATED);
        }
        catch( Exception e ) {
            throw new RestletException( "Error auto-configuring coverage", Status.SERVER_ERROR_INTERNAL, e );
        }
    }
View Full Code Here

  }
  public void populateHostNames() {
    try {
      Request request = new Request(Method.GET,"http://info.teragrid.org/web-apps/XML/ctss-resources-v1/");
      Client client = new Client(Protocol.HTTP);
      Response response = client.handle(request);
      DomRepresentation representation = response.getEntityAsDom();
      Document document = representation.getDocument();
      NodeList nodeList = document.getElementsByTagName("Resource");
      for(int i=0;i<nodeList.getLength();i++){
        this.hostNameItems.add(new SelectItem(nodeList.item(i).getAttributes().getNamedItem("UniqueID").getNodeValue()));
      }
View Full Code Here

  public void populateGridFtpEndPoints(String hostName) {
    if(!hostName.isEmpty()){
    try{
      Request request = new Request(Method.GET,"http://info.teragrid.org/web-apps/xml/kit-services-v1/type/gridftp/");
      Client client = new Client(Protocol.HTTP);
      Response response = client.handle(request);
      DomRepresentation representation = response.getEntityAsDom();
      Document document = representation.getDocument();
      NodeList nodeList = document.getElementsByTagName("Service");
      for(int i=0;i<nodeList.getLength();i++){
        Node node = nodeList.item(i);
        if(node.getNodeType()==Node.ELEMENT_NODE) {
View Full Code Here

TOP

Related Classes of org.restlet.data.Response

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.