<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    軟件是對質量的不懈追求

    2010年6月30日 #

    linux du 查看文件夾占用空間


    du -sh *

    posted @ 2011-04-15 08:39 BlakeSu 閱讀(280) | 評論 (0)編輯 收藏

    Building Standalone Application with Maven2

    If you are building standalone application in Java, Maven is your friend when packing your application,
    There are two way to let Maven package your application, either as a single jar with all your dependencies jar.


     <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
       <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
       </descriptorRefs>
      </configuration>
     </plugin>



    One advantage if you choose to do this way is if you need to sign your application jar.
    This is needed if you are building a Java Web Start client and you need more access than connecting back to the server.
    To read more about have Maven signing your jar read http://maven.apache.org/plugins/maven-jar-plugin/usage.html.
    But if you choose to go this way, make sure that all license agreement are shipped with your one single jar.

    Another way is to let Maven package your source code only and then referring the dependent jar file from the MANIFEST file.


     <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <configuration>
       <archive>
        <manifest>
         <addClasspath>true</addClasspath>
         <mainClass>se.msc.adapter.Main</mainClass>
         <classpathPrefix>lib/</classpathPrefix>
        </manifest>
       </archive>
      </configuration>
     </plugin>

    posted @ 2011-02-24 13:03 BlakeSu 閱讀(329) | 評論 (0)編輯 收藏

    eclipse 終于有了列編輯功能

    eclipse 3.5之后終于有了列編輯,快捷鍵是alt+shift+a,再次按此快捷鍵返回常規編輯狀態。


    posted @ 2010-10-15 11:33 BlakeSu 閱讀(1484) | 評論 (0)編輯 收藏

    LineNumberReader 指定文件編碼


    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.LineNumberReader;


    public class Main {
        
        
    public static void main(String[] args) throws IOException {

            InputStreamReader isr 
    = new InputStreamReader(new FileInputStream("15370720.pdf4"), "utf-16");
            LineNumberReader lnr
    =new LineNumberReader(isr);
            String line 
    = null;
            
    while((line=lnr.readLine())!=null){  
               System.out.println(lnr.getLineNumber()
    +"\t"+line);
            }
       }
    }

    posted @ 2010-08-05 09:13 BlakeSu 閱讀(1049) | 評論 (0)編輯 收藏

    Class.getResourceAsStream 和 ClassLoader.getResourceAsStream

    兩個方法的區別是資源的定義不同, 一個主要用于相對與一個object取資源,而另一個用于取相對于classpath的
    資源,用的是絕對路徑。

    在使用Class.getResourceAsStream 時, 資源路徑有兩種方式, 一種以 / 開頭,則這樣的路徑是指定絕對
    路徑, 如果不以 / 開頭, 則路徑是相對與這個class所在的包的。

    在使用ClassLoader.getResourceAsStream時, 路徑直接使用相對于classpath的絕對路徑。

    舉例,下面的三個語句,實際結果是一樣的:
       com.explorers.Test.class.getResourceAsStream("abc.jpg")
    = com.explorers.Test.class.getResourceAsStream("/com/explorers/abc.jpg")
    = ClassLoader.getResourceAsStream("com/explorers/abc.jpg")

    posted @ 2010-07-28 16:31 BlakeSu 閱讀(294) | 評論 (0)編輯 收藏

    Standalone Java CAS Client

    There's a variety of clients for CAS. The Java-based clients (JA-SIG, Yale, see JA-SIG website) typically handle the browser-based client interaction with CAS very well through ServletFilter implementations.

    Now what about programmatic authentication, i.e. achieving authentication through non-browser based applications? There exists a CAS .NET client but I did not manage to find the appropriate Java implementation. So here goes - it is based on the Apache HttpClient.

    In case I missed any existing implementation achieving the same purpose, let's look at the bright side: at least now I understand the CAS protocol :-)

    My CAS client works within any application. It uses the HttpClient and behaves like a browser client as CAS requires cookie support.

    Here's the code:
    import org.apache.commons.httpclient.Header;
    import org.apache.commons.httpclient.HttpClient;
    import org.apache.commons.httpclient.HttpMethod;
    import org.apache.commons.httpclient.HttpStatus;
    import org.apache.commons.httpclient.methods.GetMethod;
    import org.apache.commons.httpclient.methods.PostMethod;
    import org.apache.log4j.Logger;

    /**
    * The CasClient allows users to programmatically login
    * to CAS protected services based on the CAS 2 protocol.
    * This client behaves like a browser-client in terms of
    * cookie handling.<br>
    *
    @author Mathias Richter
    */
    public class CasClient
    {
      
       
    public static Logger LOG = Logger.getLogger( CasClient.class  );

       
    public static final String LOGIN_URL_PART = "login";
       
    public static final String SERVICE_VALIDATE_URL_PART = "serviceValidate";
       
    public static final String TICKET_BEGIN = "ticket=";
       
    private static final String LT_BEGIN = "name="lt" value="";
       public static final String CAS_USER_BEGIN = "<cas:user>";
       
    public static final String CAS_USER_END = "</cas:user>";
      
       
    private HttpClient fClient;
       
    private String fCasUrl;
      
       
    /**
        * Construct a new CasClient.
        *
        * 
    @param casUrl The base URL of the CAS service to be used.
        
    */
       
    public CasClient( String casBaseUrl )
       {
           
    thisnew HttpClient(), casBaseUrl );
       }
      
       
    /**
        * Construct a new CasClient which uses the specified HttpClient
        * for its HTTP calls.
        *
        * 
    @param client
        * 
    @param casBaseUrl
        
    */
       
    public CasClient( HttpClient client, String casBaseUrl )
       {
           fClient 
    = client;
           fCasUrl 
    = casBaseUrl;
       }
      
       
    /**
        * Authenticate the specified username with the specified password.
        * This will not yield any ticket, as no service is authenticated
        * against. This wil just set the CAS cookie in this client upon
        * successful authentication.
        *
        * 
    @param username
        * 
    @param password
        
    */
       
    public void authenticate( String username, String password )
       {
           authenticate( 
    null, username, password );
       }
      
       
    /**
        * Validate the specified service ticket against the specified service.
        * If the ticket is valid, this will yield the clear text user name
        * of the autenticated user.<br>
        * Note that each service ticket issued by CAS can be used exactly once
        * to validate.
        *
        * 
    @param serviceUrl
        * 
    @param serviceTicket
        *
        * 
    @return Clear text username of the authenticated user.
        
    */
       
    public String validate( String serviceUrl, String serviceTicket )
       {
           String result 
    = null;
           PostMethod method 
    = new PostMethod( fCasUrl + SERVICE_VALIDATE_URL_PART );
           method.setParameter( 
    "service", serviceUrl );
           method.setParameter( 
    "ticket", serviceTicket );
           
    try
           {
               
    int statusCode = fClient.executeMethod(method);
               
    if (statusCode != HttpStatus.SC_OK)
               {
                   LOG.error( 
    "Could not validate: " + method.getStatusLine() );
                   method.releaseConnection();
               } 
    else
               {   
                   result 
    = extractUser( new String( method.getResponseBody() ) );
               }
           } 
    catch ( Exception x )
           {
               LOG.error( 
    "Could not validate: " + x.toString () );
               x.printStackTrace();
           }
           method.releaseConnection();
           
    return result;
       }
      
       
    /**
        * Authenticate the specified user with the specified password against the
        * specified service.
        *
        * 
    @param serviceUrl May be null. If a url is specified, the authentication will happen against this service, yielding a service ticket which can be validated.
        * 
    @param username
        * 
    @param password
        * 
    @return A valid service ticket, if and only if the specified service URL is not null.
        
    */
       
    public String authenticate( String serviceUrl, String username, String password )
       {
           String lt 
    = getLt( serviceUrl );
           
    if ( lt == null )
           {
               LOG.error( 
    "Cannot retrieve LT from CAS. Aborting authentication for '" + username + "'" );
               
    return null;
           }
           String result 
    = null;
           PostMethod method 
    = new PostMethod( fCasUrl + LOGIN_URL_PART );
           
    if ( serviceUrl != null ) // optional
               method.setParameter( "service", serviceUrl );
           method.setParameter( 
    "_eventId""submit" );
           method.setParameter(
    "username", username );
           method.setParameter(
    "password", password );
           method.setParameter(
    "lt", lt );
           method.setParameter( 
    "gateway""true" );
           
    try
           {
               fClient.executeMethod(method);
               
    if ( serviceUrl == null )
               {
                   
    if ( extractLt( new String( method.getResponseBody() ) ) != null ) // if CAS does not return a login page with an LT authentication was successful
                   {
                       LOG.error( 
    "Authentication for '" +  username + "' unsuccessful" );
                       
    if ( LOG.isDebugEnabled() )
                           LOG.debug( 
    "Authentication for '" + username + "' unsuccessful." );
                   } 
    else
                   {
                       
    if ( LOG.isDebugEnabled() )
                           LOG.debug( 
    "Authentication for '" + username + "' unsuccessful." );
                   }
               } 
    else
               {
                   Header h 
    = method.getResponseHeader( "Location" );
                   
    if ( h != null )
                       result 
    = extractServiceTicket( h.getValue() );
                   
    if ( result == null )
                       LOG.error( 
    "Authentication for '" + username + "' unsuccessful." );
               }
           } 
    catch ( Exception x )
           {
               LOG.error( 
    "Could not authenticate'" + username + "':" + x.toString () );
           }
           method.releaseConnection();
           
    return result;
       }
      
       
    /**
        * Helper method to extract the user name from a "service validate" call to CAS.
        *
        * 
    @param data Response data.
        * 
    @return The clear text username, if it could be extracted, null otherwise.
        
    */
       
    protected String extractUser( String data )
       {
           String user 
    = null;
           
    int start = data.indexOf( CAS_USER_BEGIN  );
           
    if ( start >= 0 )
           {
               start 
    += CAS_USER_BEGIN.length();
               
    int end = data.indexOf( CAS_USER_END );
               
    if ( end > start )
                   user 
    = data.substring( start, end );
               
    else
                   LOG.warn( 
    "Could not extract username from CAS validation response. Raw data is: '" + data + "'" );
           } 
    else
           {
               LOG.warn( 
    "Could not extract username from CAS validation response. Raw data is: '" + data + "'" );
           }
           
    return user;
       }
      
       
    /**
        * Helper method to extract the service ticket from a login call to CAS.
        *
        * 
    @param data Response data.
        * 
    @return The service ticket, if it could be extracted, null otherwise.
        
    */
       
    protected String extractServiceTicket( String data )
       {
           String serviceTicket 
    = null;
           
    int start = data.indexOf( TICKET_BEGIN  );
           
    if ( start > 0 )
           {
               start 
    += TICKET_BEGIN.length();
               serviceTicket 
    = data.substring( start );
           }
           
    return serviceTicket;
       }
      
       
    /**
        * Helper method to extract the LT from a login form from CAS.
        *
        * 
    @param data Response data.
        * 
    @return The LT, if it could be extracted, null otherwise.
        
    */
       
    protected String extractLt( String data )
       {
           String token 
    = null;
           
    int start = data.indexOf( LT_BEGIN  );
           
    if ( start < 0 )
           {
               LOG.error( 
    "Could not obtain LT token from CAS: LT Token not found in response." );
           } 
    else
           {
               start 
    += LT_BEGIN.length();
               
    int end = data.indexOf( """, start );
               token = data.substring( start, end );
           }       
           
    return token;
       }
      
       
    /**
        * This method requests the original login form from CAS.
        * This form contains an LT, an initial token that must be
        * presented to CAS upon sending it an authentication request
        * with credentials.<br>
        * If a service URL is provided (which is optional), this method
        * will post the URL such that CAS authenticates against the
        * specified service when a subsequent authentication request is
        * sent.
        *
        * 
    @param serviceUrl
        * 
    @return The LT token if it could be extracted from the CAS response.
        
    */
       
    protected String getLt( String serviceUrl )
       {
           String lt 
    = null;
           HttpMethod method 
    = null;
           
    if ( serviceUrl == null )
               method 
    = new GetMethod( fCasUrl + LOGIN_URL_PART );
           
    else
           {
               method 
    = new PostMethod( fCasUrl + LOGIN_URL_PART );
               ( ( PostMethod ) method ).setParameter( 
    "service", serviceUrl );
           }
           
    try
           {
               
    int statusCode = fClient.executeMethod(method);
               
    if (statusCode != HttpStatus.SC_OK)
               {
                   LOG.error( 
    "Could not obtain LT token from CAS: " + method.getStatusLine() );
                   method.releaseConnection();
               } 
    else
               {
                   Object o 
    = method.getResponseHeaders() ;
                   
    return extractLt( new String( method.getResponseBody() ) );
               }
           } 
    catch ( Exception x )
           {
               LOG.error( 
    "Could not obtain LT token from CAS: " + x.toString () );
           }
           method.releaseConnection();
           
    return lt;
       }
      
    }

    posted @ 2010-07-15 17:59 BlakeSu 閱讀(415) | 評論 (0)編輯 收藏

    java取文件換行符

    System.getProperty("line.separator")

    posted @ 2010-06-30 15:45 BlakeSu 閱讀(311) | 評論 (0)編輯 收藏

    主站蜘蛛池模板: 国产又大又黑又粗免费视频| 亚洲精品无码一区二区| 免费jlzzjlzz在线播放视频| 日本免费xxxx| 国产精成人品日日拍夜夜免费| 牛牛在线精品免费视频观看| 亚洲国产日韩视频观看| 亚洲精品美女在线观看| 亚洲va久久久噜噜噜久久男同 | 国产亚洲福利精品一区| 亚洲福利视频一区二区| 成人av免费电影| 99re热免费精品视频观看| 99热精品在线免费观看| a国产成人免费视频| 国产99精品一区二区三区免费 | 在线a人片天堂免费观看高清| 最近2019免费中文字幕视频三| 日本免费中文视频| 中国国语毛片免费观看视频| 一级女性全黄久久生活片免费| 在线观看亚洲专区| 久久精品熟女亚洲av麻豆| 亚洲一区二区三区写真| 亚洲AV成人影视在线观看| 亚洲一区二区三区免费在线观看| 777亚洲精品乱码久久久久久| 亚洲午夜精品一区二区| 久久久久久久久亚洲| 亚洲第一极品精品无码久久| 亚洲国产AV无码专区亚洲AV| 久久亚洲国产视频| 亚洲AV无码一区二区乱孑伦AS| 亚洲精品无码精品mV在线观看| 久久香蕉国产线看观看亚洲片| 亚洲精品国产成人99久久| 久久亚洲精品无码VA大香大香| 亚洲国产精品久久久久婷婷老年| 亚洲国产综合91精品麻豆| 亚洲资源在线观看| 亚洲一级免费视频|