dspace/modules/jspui/src/main/java/org/dspace/identifier/NbnIdentifierProvider.java
public static String register(String Handle) throws HttpException, IOException
    {

    	
   /** Set credentials of NBN server*/
    
    
    String credenziali = ConfigurationManager.getProperty("identifier","nbn.user")+":"+ConfigurationManager.getProperty("identifier","nbn.passwd");
    String MyNBN="";
    
    

    /** Set URL  **/

    String HandlUrl = ConfigurationManager.getProperty("dspace.url") + "/handle/" + Handle;
    String OaiUrl=    ConfigurationManager.getProperty("oai","dspace.oai.url") + "/request?verb=GetRecord&metadataPrefix=oai_dc&identifier=oai:" + ConfigurationManager.getProperty("dspace.hostname") +":"+ Handle;

   
     /** set json string for post to NBN server **/
    String content;
  
        content ="{\"action\":\"nbn_create\",\"url\":\""+HandlUrl+"\",\"metadataURL\":\"" + OaiUrl+ "\"}";


      
         HttpClient myClient = new HttpClient();
    
         myClient.getState().setCredentials(
                 new AuthScope( ConfigurationManager.getProperty("identifier","nbn.host"),80),
                 new UsernamePasswordCredentials(ConfigurationManager.getProperty("identifier","nbn.user"),ConfigurationManager.getProperty("identifier","nbn.passwd"))
                 );
              
         StringRequestEntity  jsonContent = new StringRequestEntity(content,"application/json","UTF-8");  
         PostMethod post = new PostMethod(ConfigurationManager.getProperty("identifier","nbn.url"));
         post.setDoAuthentication(true);
         post.setParameter("Content-Type", "application/json");
         post.setRequestEntity(jsonContent);            
        try {
             
            
            int status = myClient.executeMethod(post);
            
            if (status == 201){
            	log.warn("NBN assigned: "+ post.getResponseBodyAsString() );
            DataInputStream input = new DataInputStream (post.getResponseBodyAsStream());
            int i =0;
            String str;

            while (null != ((str = input.readLine())))
               {
                 i=i+1;
                 if (i==3) {
                     if (str.indexOf("urn:") != -1)  {   MyNBN = str.substring(str.indexOf("urn:"),str.length()-1); }
                   } // if i = 3 row

               } // end WHILE

               input.close ();
              
         } // end status=201
       else
       {
    	   log.warn("NBN not assigned: "+ post.getResponseBodyAsString() );
       
       }
  
        } // end of Try..catch
        finally {
        	post.releaseConnection();
        }	
        
            
        return MyNBN;
  
        }
/* Request new NBN: giving the handle of the ITEM  */
Request new NBN: giving the handle of the ITEM
Request new NBN : giving the handle of the ITEM
public static String register(String Handle) throws HttpException, IOException
    {
   /** Set credentials of NBN server*/
    String credenziali = ConfigurationManager.getProperty("identifier","nbn.user")+":"+ConfigurationManager.getProperty("identifier","nbn.passwd");
    String MyNBN="";
    /** Set URL  **/
    String HandlUrl = ConfigurationManager.getProperty("dspace.url") + "/handle/" + Handle;
    String OaiUrl=    ConfigurationManager.getProperty("oai","dspace.oai.url") + "/request?verb=GetRecord&metadataPrefix=oai_dc&identifier=oai:" + ConfigurationManager.getProperty("dspace.hostname") +":"+ Handle;
     /** set json string for post to NBN server **/
    String content;
        content ="{\"action\":\"nbn_create\",\"url\":\""+HandlUrl+"\",\"metadataURL\":\"" + OaiUrl+ "\"}";
         HttpClient myClient = new HttpClient();
         myClient.getState().setCredentials(
                 new AuthScope( ConfigurationManager.getProperty("identifier","nbn.host"),80),
                 new UsernamePasswordCredentials(ConfigurationManager.getProperty("identifier","nbn.user"),ConfigurationManager.getProperty("identifier","nbn.passwd"))
                 );
         StringRequestEntity  jsonContent = new StringRequestEntity(content,"application/json","UTF-8");  
         PostMethod post = new PostMethod(ConfigurationManager.getProperty("identifier","nbn.url"));
         post.setDoAuthentication(true);
         post.setParameter("Content-Type", "application/json");
         post.setRequestEntity(jsonContent);            
        try {
            int status = myClient.executeMethod(post);
            if (status == 201){
            	log.warn("NBN assigned: "+ post.getResponseBodyAsString() );
            DataInputStream input = new DataInputStream (post.getResponseBodyAsStream());
            int i =0;
            String str;
            while (null != ((str = input.readLine())))
               {
                 i=i+1;
                 if (i==3) {
                     if (str.indexOf("urn:") != -1)  {   MyNBN = str.substring(str.indexOf("urn:"),str.length()-1); }
                   } 
               } 
               input.close ();
         } 
       else
       {
    	   log.warn("NBN not assigned: "+ post.getResponseBodyAsString() );
       }
        } 
        finally {
        	post.releaseConnection();
        }	
        return MyNBN;
        }
public static String register ( String Handle ) throws HttpException , IOException { /** Set credentials of NBN server*/ String credenziali = ConfigurationManager . getProperty ( "identifier" , "nbn.user" ) + ":" + ConfigurationManager . getProperty ( "identifier" , "nbn.passwd" ) ; String MyNBN = "" ; /** Set URL  **/ String HandlUrl = ConfigurationManager . getProperty ( "dspace.url" ) + "/handle/" + Handle ; String OaiUrl = ConfigurationManager . getProperty ( "oai" , "dspace.oai.url" ) + "/request?verb=GetRecord&metadataPrefix=oai_dc&identifier=oai:" + ConfigurationManager . getProperty ( "dspace.hostname" ) + ":" + Handle ; /** set json string for post to NBN server **/ String content ; content = "{\"action\":\"nbn_create\",\"url\":\"" + HandlUrl + "\",\"metadataURL\":\"" + OaiUrl + "\"}" ; HttpClient myClient = new HttpClient ( ) ; myClient . getState ( ) . setCredentials ( new AuthScope ( ConfigurationManager . getProperty ( "identifier" , "nbn.host" ) , 80 ) , new UsernamePasswordCredentials ( ConfigurationManager . getProperty ( "identifier" , "nbn.user" ) , ConfigurationManager . getProperty ( "identifier" , "nbn.passwd" ) ) ) ; StringRequestEntity jsonContent = new StringRequestEntity ( content , "application/json" , "UTF-8" ) ; PostMethod post = new PostMethod ( ConfigurationManager . getProperty ( "identifier" , "nbn.url" ) ) ; post . setDoAuthentication ( true ) ; post . setParameter ( "Content-Type" , "application/json" ) ; post . setRequestEntity ( jsonContent ) ; try { int status = myClient . executeMethod ( post ) ; if ( status == 201 ) { log . warn ( "NBN assigned: " + post . getResponseBodyAsString ( ) ) ; DataInputStream input = new DataInputStream ( post . getResponseBodyAsStream ( ) ) ; int i = 0 ; String str ; while ( null != ( ( str = input . readLine ( ) ) ) ) { i = i + 1 ; if ( i == 3 ) { if ( str . indexOf ( "urn:" ) != - 1 ) { MyNBN = str . substring ( str . indexOf ( "urn:" ) , str . length ( ) - 1 ) ; } } } input . close ( ) ; } else { log . warn ( "NBN not assigned: " + post . getResponseBodyAsString ( ) ) ; } } finally { post . releaseConnection ( ) ; } return MyNBN ; }
Request new NBN: giving the handle of the ITEM
Request new NBN : giving the handle of the ITEM
// if i = 3 row // end WHILE // end status=201 // end of Try..catch