Package org.fao.geonet.utils

Examples of org.fao.geonet.utils.XmlRequest


      this.log = log;

    ListIdentifiersRequest req = new ListIdentifiersRequest(context.getBean(GeonetHttpRequestFactory.class));
    req.setSchemaPath(new File(context.getAppPath() + Geonet.SchemaPath.OAI_PMH));

        XmlRequest t = req.getTransport();
    try {
      t.setUrl(new URL(params.url));
        } catch (MalformedURLException e1) {
            HarvestError harvestError = new HarvestError(e1, log);
            harvestError.setDescription(harvestError.getDescription() + " " + params.url);
            errors.add(harvestError);
            throw new AbortExecutionException(e1);
        }

    if (params.useAccount) {
            t.setCredentials(params.username, params.password);
        }

    //--- set the proxy info if necessary
    Lib.net.setupProxy(context, t);
View Full Code Here


     */
 
  private void harvestFeatures(Element xmlQuery, FragmentHarvester fragmentHarvester)
            throws FactoryConfigurationError, Exception {
   
    XmlRequest req = context.getBean(GeonetHttpRequestFactory.class).createXmlRequest(params.url);
    req.setRequest(xmlQuery);
    Lib.net.setupProxy(context, req);
   
    File tempFile = File.createTempFile("temp-", ".xml");

    try {
      // Read response into temporary file
      req.executeLarge(tempFile);

        List<Namespace> namespaces = new ArrayList<Namespace>();
        namespaces.add(Namespace.getNamespace("gml", "http://www.opengis.net/gml"));
       
          XmlElementReader reader = new XmlElementReader(new FileInputStream(tempFile), "gml:featureMembers/*", namespaces);
View Full Code Here

        if(log.isDebugEnabled()) {
            log.debug("GetCapabilities document: " + this.capabilitiesUrl);
        }
   
        XmlRequest req = context.getBean(GeonetHttpRequestFactory.class).createXmlRequest();
        req.setUrl(new URL(this.capabilitiesUrl));
        req.setMethod(XmlRequest.Method.GET);
        Lib.net.setupProxy(context, req);

        if (params.useAccount) {
            req.setCredentials(params.username, params.password);
        }

        xml = req.execute();

    //-----------------------------------------------------------------------
    //--- remove old metadata
    for (String uuid : localUuids.getUUIDs())
    {
View Full Code Here

  {

      this.log = log;
    //--- perform all searches

    XmlRequest request = context.getBean(GeonetHttpRequestFactory.class).createXmlRequest(new URL(params.baseUrl+"/rest/find/document"));

    Set<RecordInfo> records = new HashSet<RecordInfo>();


        for (Search s : params.getSearches()) {
View Full Code Here

  public HarvestResult harvest(Logger log) throws Exception
  {
      this.log = log;

        XmlRequest req = context.getBean(GeonetHttpRequestFactory.class).createXmlRequest(params.host, Integer.valueOf(params.port));

    Lib.net.setupProxy(context, req);

    //--- perform all searches
View Full Code Here

   */
  private CswServer retrieveCapabilities(Logger log) throws Exception {   
    if (!Lib.net.isUrlValid(params.capabUrl))
      throw new BadParameterEx("Capabilities URL", params.capabUrl);

    XmlRequest req;
    // Support both full GetCapbilities URL or CSW entry point
        final GeonetHttpRequestFactory requestFactory = context.getBean(GeonetHttpRequestFactory.class);
        if (params.capabUrl.contains("GetCapabilities")) {
            req = requestFactory.createXmlRequest(new URL(params.capabUrl));
    } else {
      req = requestFactory.createXmlRequest(new URL(params.capabUrl + (params.capabUrl.contains("?") ? "&" : "?") + GETCAPABILITIES_PARAMETERS));
    }

    Lib.net.setupProxy(context, req);

    if (params.useAccount)
      req.setCredentials(params.username, params.password);
    CswServer server = null;
    try{
        Element capabil = req.execute();
   
            if(log.isDebugEnabled())
                log.debug("Capabilities:\n"+Xml.getString(capabil));
           
        if (capabil.getName().equals("ExceptionReport"))
View Full Code Here

  public void doHarvest(Logger log) throws Exception
  {
    CategoryMapper localCateg = new CategoryMapper(context);

        XmlRequest req = context.getBean(GeonetHttpRequestFactory.class).createXmlRequest(params.host);

        servletName = req.getAddress();

    Lib.net.setupProxy(context, req);

    String name = getParams().name;

    //--- login

    if (params.useAccount)
    {
      log.info("Login into : "+ name);

      req.setAddress(servletName +"/srv/en/"+ Geonet.Service.XML_LOGIN);
      req.addParam("username", params.username);
      req.addParam("password", params.password);

      Element response = req.execute();

      if (!response.getName().equals("ok"))
        throw new UserNotFoundEx(params.username);
    }

    //--- search

    result = new GeonetResult();

    Aligner aligner = new Aligner(log, req, params, dataMan, context,
                        localCateg);

    for(Search s : params.getSearches())
    {
      log.info("Searching on : "+ name +"/"+ s.siteId);

      req.setAddress(servletName +"/srv/en/"+ Geonet.Service.XML_SEARCH);

      Element searchResult = req.execute(s.createRequest());

            if(log.isDebugEnabled()) log.debug("Obtained:\n"+Xml.getString(searchResult));

      //--- site alignment
      HarvestResult ar = aligner.align(searchResult, s.siteId);

      //--- collect some stats
      result.alResult.add(ar);
    }

    //--- logout

    if (params.useAccount)
    {
      log.info("Logout from : "+ name);

      req.clearParams();
      req.setAddress("/"+ params.getServletPath() +"/srv/en/"+ Geonet.Service.XML_LOGOUT);
    }

        dataMan.flush();
    }
View Full Code Here

    localUris = new UriMapper(context, params.uuid);

    //--- Try to load thredds catalog document
    String url = params.url;
    try {
      XmlRequest req = context.getBean(GeonetHttpRequestFactory.class).createXmlRequest();
      req.setUrl(new URL(url));
      req.setMethod(XmlRequest.Method.GET);
      Lib.net.setupProxy(context, req);

      xml = req.execute();
    } catch (SSLHandshakeException e) {
      throw new BadServerCertificateEx(
        "Most likely cause: The thredds catalog "+url+" does not have a "+
        "valid certificate. If you feel this is because the server may be "+
        "using a test certificate rather than a certificate from a well "+
View Full Code Here

  //--------------------------------------------------------------------------

  public HarvestResult harvest(Logger log) throws Exception
  {
        this.log = log;
    XmlRequest req = context.getBean(GeonetHttpRequestFactory.class).createXmlRequest(new URL(params.host));

        Lib.net.setupProxy(context, req);

    //--- login

    if (params.useAccount)
    {
     
      try {
        log.info("Login into : "+ params.name);
        req.setCredentials(params.username, params.password);
                req.setPreemptiveBasicAuth(true);
        req.setAddress(params.getServletPath()+"/srv/eng/xml.info");
                req.addParam("type", "me");

        Element response = req.execute();
        if(!response.getName().equals("info") || response.getChild("me") == null) {
          pre29Login(req);
        } else if(!"true".equals(response.getChild("me").getAttributeValue("authenticated"))) {
                    log.warning("Authentication failed for user: " + params.username);
                    throw new UserNotFoundEx(params.username);
        }
      } catch (Exception e) {
        pre29Login(req);
      }
    }

    //--- retrieve info on categories and groups

    log.info("Retrieving information from : "+ params.host);

    req.setAddress(params.getServletPath() +"/srv/en/"+ Geonet.Service.XML_INFO);
    req.clearParams();
    req.addParam("type", "sources");
    req.addParam("type", "groups");

    Element remoteInfo = req.execute();

    if (!remoteInfo.getName().equals("info"))
      throw new BadServerResponseEx(remoteInfo);

    //--- perform all searches
View Full Code Here


    private void retrieveLogo(ServiceContext context, String url, String uuid) throws MalformedURLException {
        String logo = uuid + ".gif";

        XmlRequest req = context.getBean(GeonetHttpRequestFactory.class).createXmlRequest(new URL(url));
        Lib.net.setupProxy(context, req);
        req.setAddress(req.getAddress() + "/images/logos/" + logo);

        File logoFile = new File(Resources.locateLogosDir(context) + File.separator + logo);

        try {
            req.executeLarge(logoFile);
        } catch (IOException e) {
            context.warning("Cannot retrieve logo file from : " + url);
            context.warning("  (C) Logo  : " + logo);
            context.warning("  (C) Excep : " + e.getMessage());
View Full Code Here

TOP

Related Classes of org.fao.geonet.utils.XmlRequest

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.