Package org.restlet.data

Examples of org.restlet.data.Form


        if (watcherWorks && configWatcher.isStale()) {
            //reload the config if it's stale
            config = ProxyConfig.loadConfFromDisk();
        }
        /* Grab the argument */
        Form f = request.getResourceRef().getQueryAsForm();
        /* The first argument should be the request for a URL to grab by proxy */
        String url = f.getFirstValue("url");
        try {
            /*Construct the connection to the server*/
            URL resolved = new URL(url);
            final HttpURLConnection connection = (HttpURLConnection) resolved.openConnection();;
           
View Full Code Here


        String workspace = (String)getRequest().getAttributes().get("workspace");
        String datastore = (String)getRequest().getAttributes().get("datastore");
        String format = (String)getRequest().getAttributes().get("format");

        getResponse().setStatus(Status.SUCCESS_ACCEPTED);
        Form form = getRequest().getResourceRef().getQueryAsForm();

        //get the directory to put the file into
        //TODO: add a method createDirectory(String...) so as not to specify the file seperator
        File directory;
        try {
            directory = catalog.getResourceLoader().createDirectory( "data/" + datastore );
        }
        catch (IOException e) {
            throw new RestletException( e.getMessage(), Status.SERVER_ERROR_INTERNAL, e );
        }
       
        File uploadedFile = handleFileUpload(datastore, format, directory);

        //create a builder to help build catalog objects
        CatalogBuilder builder = new CatalogBuilder(catalog);
        builder.setWorkspace( catalog.getWorkspaceByName( workspace ) );
       
        //check if the datastore already exists, if not auto configure one
        DataStoreInfo info = catalog.getDataStoreByName( datastore );
       
        boolean add = false;
        if ( info == null ) {
            LOGGER.info("Auto-configuring datastore: " + datastore);
           
            info = builder.buildDataStore( datastore );
            add = true;
        }
        else {
            LOGGER.info("Using existing datastore: " + datastore);
        }
       
        builder.setStore(info);
       
        //update the connection parameters to point to the new file
        Map connectionParameters = info.getConnectionParameters();
        for ( Param p : factory.getParametersInfo() ) {
            //the nasty url / file hack
            if ( File.class == p.type || URL.class == p.type ) {
                File f = uploadedFile;
               
                if ( "directory".equals( p.key ) ) {
                    //set the value to be the directory
                    f = directory;
                }
               
                //convert to the required type
                //TODO: use geotools converter
                Object converted = null;
                if ( URI.class.equals( p.type  ) ) {
                    converted = f.toURI();
                }
                else if ( URL.class.equals( p.type ) ) {
                    try {
                        converted = f.toURL();
                    }
                    catch (MalformedURLException e) {
                    }
                }
                //Converters.convert( f.getAbsolutePath(), p.type );
               
                if ( converted != null ) {
                    connectionParameters.put( p.key, converted );   
                }
                else {
                    connectionParameters.put( p.key, f );
                }
               
                continue;
            }
           
            if ( p.required ) {
                try {
                    p.lookUp( connectionParameters );
                }
                catch( Exception e ) {
                    //set the sample value
                    connectionParameters.put( p.key, p.sample );
                }   
            }
        }
       
        // set the namespace uri
        NamespaceInfo namespace = catalog.getNamespaceByPrefix( info.getWorkspace().getName() );
        connectionParameters.put( "namespace", namespace.getURI() );
       
        // ensure the parameters are valid
        if ( !factory.canProcess( connectionParameters ) ) {
            //TODO: log the parameters at the debug level
            throw new RestletException( "Unable to configure datastore, bad parameters.", Status.SERVER_ERROR_INTERNAL );
        }
       
        //add or update the datastore info
        if ( add ) {
            catalog.add( info );
        }
        else {
            catalog.save( info );
        }
       
        //check configure parameter, if set to none to not try to configure
        // data feature types
        String configure = form.getFirstValue( "configure" );
        if ( "none".equalsIgnoreCase( configure ) ) {
            getResponse().setStatus( Status.SUCCESS_CREATED );
            return;
        }
       
View Full Code Here

            }
        }
        else {
            //check the list flag, if == 'available', just return the list
            // of feature types available
            Form form = request.getResourceRef().getQueryAsForm();
            if ( "available".equalsIgnoreCase( form.getFirstValue( "list" ) ) ) {
                return new AvailableFeatureTypeResource(null,request,response,catalog);
            }
           
            if (request.getMethod() == Method.GET ) {
                return new FeatureTypeListResource(getContext(),request,response,catalog);
View Full Code Here

        // /////////////////////////////////////////////////////////////////////
        //
        // 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 ) {
View Full Code Here

            return;
        }

        // only deal with the form if the content type is "application/x-www-form-urlencoded"
        if (request.getEntity().getMediaType() != null && request.getEntity().getMediaType().equals(MediaType.APPLICATION_WWW_FORM)) {
            Form form = new Form(request.getEntity());
            for (Map.Entry<String, String> entry : form.getValuesMap().entrySet()) {
                if (entry.getValue() == null) {
                    inMessage.setBody(entry.getKey());
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Populate exchange from Restlet request body: " + entry.getValue());
                    }
View Full Code Here

    }

    public void populateRestletRequestFromExchange(Request request, Exchange exchange) {
        request.setReferrerRef("camel-restlet");
        String body = exchange.getIn().getBody(String.class);
        Form form = new Form();
        // add the body as the key in the form with null value
        form.add(body, null);

        MediaType mediaType = exchange.getIn().getHeader(Exchange.CONTENT_TYPE, MediaType.class);
        if (mediaType == null) {
            mediaType = MediaType.APPLICATION_WWW_FORM;
        }

        if (LOG.isDebugEnabled()) {
            LOG.debug("Populate Restlet request from exchange body: " + body + " using media type " + mediaType);
        }

        // login and password are filtered by header filter strategy
        String login = exchange.getIn().getHeader(RestletConstants.RESTLET_LOGIN, String.class);
        String password = exchange.getIn().getHeader(RestletConstants.RESTLET_PASSWORD, String.class);

        if (login != null && password != null) {
            ChallengeResponse authentication = new ChallengeResponse(ChallengeScheme.HTTP_BASIC, login, password);
            request.setChallengeResponse(authentication);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Basic HTTP Authentication has been applied");
            }
        }

        for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet()) {
            if (!headerFilterStrategy.applyFilterToCamelHeaders(entry.getKey(), entry.getValue(), exchange)) {
                // Use forms only for GET and POST/x-www-form-urlencoded
                if (request.getMethod() == Method.GET || (request.getMethod() == Method.POST && mediaType == MediaType.APPLICATION_WWW_FORM)) {
                    if (entry.getKey().startsWith("org.restlet.")) {
                        // put the org.restlet headers in attributes
                        request.getAttributes().put(entry.getKey(), entry.getValue());
                    } else {
                        // put the user stuff in the form
                        form.add(entry.getKey(), entry.getValue().toString());
                    }
                } else {
                    // For non-form post put all the headers in attributes
                    request.getAttributes().put(entry.getKey(), entry.getValue());
                }
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Populate Restlet request from exchange header: "
                            + entry.getKey() + " value: " + entry.getValue());
                }
            }
        }

        if (LOG.isDebugEnabled()) {
            LOG.debug("Using Content Type: " + mediaType + " for POST data: " + body);
        }

        // Only URL Encode for GET and form POST
        if (request.getMethod() == Method.GET || (request.getMethod() == Method.POST && mediaType == MediaType.APPLICATION_WWW_FORM)) {
            request.setEntity(form.getWebRepresentation());
        } else {
            request.setEntity(body, mediaType);
        }
    }
View Full Code Here

  @Override
  public Representation post(Representation entity) {
    try {
      String clusterName = (String) getRequest().getAttributes().get("clusterName");
      Form form = new Form(entity);

      // Get the workflow and submit it
      if (form.size() < 1) {
        throw new HelixException("yaml workflow is required!");
      }
      Parameter payload = form.get(0);
      String yamlPayload = payload.getName();
      if (yamlPayload == null) {
        throw new HelixException("yaml workflow is required!");
      }
      String zkAddr =
View Full Code Here

  // extra parameters map
  final Map<String, ZNRecord> _extraParameterMap = new HashMap<String, ZNRecord>();

  public JsonParameters(Representation entity) throws Exception {
    Form form = new Form(entity);

    // get parameters in String format
    String jsonPayload = form.getFirstValue(JSON_PARAMETERS, true);
    if (jsonPayload == null || jsonPayload.isEmpty()) {
      _parameterMap = Collections.emptyMap();
    } else {
      _parameterMap = ClusterRepresentationUtil.JsonToMap(jsonPayload);
    }

    // get extra parameters in ZNRecord format
    ObjectMapper mapper = new ObjectMapper();
    String newIdealStateString = form.getFirstValue(NEW_IDEAL_STATE, true);

    if (newIdealStateString != null) {
      ZNRecord newIdealState =
          mapper.readValue(new StringReader(newIdealStateString), ZNRecord.class);
      _extraParameterMap.put(NEW_IDEAL_STATE, newIdealState);
    }

    String newStateModelString = form.getFirstValue(NEW_STATE_MODEL_DEF, true);
    if (newStateModelString != null) {
      ZNRecord newStateModel =
          mapper.readValue(new StringReader(newStateModelString), ZNRecord.class);
      _extraParameterMap.put(NEW_STATE_MODEL_DEF, newStateModel);
    }
View Full Code Here

        ConcurrentMap<String, Object> attribs = getContext().getAttributes();
        ServerManager manager = (ServerManager) attribs.get("openid_manager");
        String opEndpoint = manager.getOPEndpointUrl();

        Form query = getQuery();
        String returnTo = query.getFirstValue("returnTo");
        if (returnTo != null && returnTo.length() > 0) { // OP Server lookup
            response = createDocument(TYPE_RETURN_TO, returnTo, null);
        } else {
            String id = query.getFirstValue("id");
            if (id == null || id.length() == 0) { // OP Server lookup
                response = createDocument(TYPE_SERVER, opEndpoint, null);
            } else { // claimed ID lookup
                StringBuilder localId = new StringBuilder();
                localId.append(opEndpoint);
View Full Code Here

                : DefaultOrigRefCookie;
    }

    @Override
    protected boolean authenticate(Request request, Response response) {
        Form f = request.getResourceRef().getQueryAsForm();
        User u = request.getClientInfo().getUser();
        String identifier = request.getCookies()
                .getFirstValue(identifierCookie);
        String origRef;
        if (identifier != null) {
View Full Code Here

TOP

Related Classes of org.restlet.data.Form

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.