axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/utils Constants.java
Date Mon, 05 Feb 2001 22:30:11 GMT
dug         01/02/05 14:30:11

  Modified:    java/samples/stock GetQuote.java
               java/src/org/apache/axis/client HTTPCall.java
                        HTTPMessage.java
               java/src/org/apache/axis/handlers HTTPDispatchHandler.java
               java/src/org/apache/axis/server/transports AxisServlet.java
               java/src/org/apache/axis/utils Constants.java
  Log:
  Added Basic Auth support - and the GetQuote sample
  
  Revision  Changes    Path
  1.7       +16 -6     xml-axis/java/samples/stock/GetQuote.java
  
  Index: GetQuote.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/samples/stock/GetQuote.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- GetQuote.java	2001/02/02 02:53:25	1.6
  +++ GetQuote.java	2001/02/05 22:30:10	1.7
  @@ -79,6 +79,8 @@
         /***************************/
         String  host    = "localhost" ;
         String  servlet = "/axis/servlet/AxisServlet" ;
  +      String  user    = null ;
  +      String  pwd     = null ;
         int     port    = 8080 ;
   
         for ( int i = 0 ; i < args.length ; i++ ) {
  @@ -89,6 +91,13 @@
               case 'h': if ( args[i].length() > 2 )
                           host = args[i].substring(2);
                         break ;
  +            case 'l': if ( args[i].length() > 2 ) {
  +                        URL tmpurl = new URL(args[i].substring(2));
  +                        host = tmpurl.getHost();
  +                        port = tmpurl.getPort();
  +                        servlet = tmpurl.getPath() ;
  +                      }
  +                      break ;
               case 'p': if ( args[i].length() > 2 )
                           port = Integer.parseInt(args[i].substring(2));
                         break ;
  @@ -97,12 +106,11 @@
                         if ( servlet != null && servlet.charAt(0) != '/' )
                           servlet = "/" + servlet ;
                         break ;
  -            case 'u': if ( args[i].length() > 2 ) {
  -                        URL tmpurl = new URL(args[i].substring(2));
  -                        host = tmpurl.getHost();
  -                        port = tmpurl.getPort();
  -                        servlet = tmpurl.getPath() ;
  -                      }
  +            case 'u': if ( args[i].length() > 2 )
  +                        user = args[i].substring(2);
  +                      break ;
  +            case 'w': if ( args[i].length() > 2 )
  +                        pwd = args[i].substring(2);
                         break ;
               default: System.err.println( "Unknown option '" + 
                                            args[i].charAt(1) + "'" );
  @@ -119,6 +127,8 @@
   
         String url = "http://" + host + ":" + port + servlet ;
         HTTPCall call = new HTTPCall( url, "urn:xmltoday-delayed-quotes" );
  +      if ( user != null ) call.setUserID( user );
  +      if ( pwd  != null ) call.setPassword( pwd );
         String res = (String) call.invoke( "getQuote", new Object[] {symbol} );
   
         System.out.println( symbol + ": " + res );
  
  
  
  1.6       +27 -4     xml-axis/java/src/org/apache/axis/client/HTTPCall.java
  
  Index: HTTPCall.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/HTTPCall.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- HTTPCall.java	2001/02/04 13:45:35	1.5
  +++ HTTPCall.java	2001/02/05 22:30:10	1.6
  @@ -77,6 +77,8 @@
   public class HTTPCall {
     private String  url ;
     private String  action ;
  +  private String  userID ;
  +  private String  passwd ;
   
     public HTTPCall() {
     }
  @@ -98,6 +100,22 @@
       this.action = action ;
     }
   
  +  public void setUserID( String user ) {
  +    userID = user ;
  +  }
  +
  +  public String getUserID() {
  +    return( userID );
  +  }
  +
  +  public void setPassword( String pwd ) {
  +    passwd = pwd ;
  +  }
  +
  +  public String getPassword() {
  +    return( passwd );
  +  }
  +
     public static Object invoke(String url, String act, String m, Object[] args) 
         throws AxisFault
     {
  @@ -130,8 +148,8 @@
         SOAPHeader  header = new SOAPHeader();
         header.setPrefix("d");
         header.setName("Debug");
  -      header.setNamespaceURI( "http://xml.apache.org/axis/debug" );
  -      header.setActor( "http://schemas.xmlsoap.org/soap/actor/next" );
  +      header.setNamespaceURI( Constants.URI_DEBUG );
  +      header.setActor( Constants.URI_NEXT_ACTOR );
         Document doc = new DocumentImpl();
         Node node = doc.createTextNode( "" + Debug.getDebugLevel() );
         header.addDataNode( node );
  @@ -139,8 +157,13 @@
         reqEnv.addHeader( header );
       }
   
  -    msgContext.setProperty( "HTTP_URL", url );   // horrible name!
  -    msgContext.setProperty( "HTTP_ACTION", action );   // horrible name!
  +    msgContext.setProperty( Constants.MC_HTTP_URL, url );   // horrible name!
  +    msgContext.setProperty( Constants.MC_TARGET, action );   // horrible name!
  +    if ( userID != null ) {
  +      msgContext.setProperty( Constants.MC_USERID, userID );
  +      if ( passwd != null )
  +        msgContext.setProperty( Constants.MC_PASSWORD, passwd );
  +    }
       try {
         client.init();
         client.invoke( msgContext );
  
  
  
  1.3       +2 -2      xml-axis/java/src/org/apache/axis/client/HTTPMessage.java
  
  Index: HTTPMessage.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/HTTPMessage.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HTTPMessage.java	2001/02/02 02:53:25	1.2
  +++ HTTPMessage.java	2001/02/05 22:30:10	1.3
  @@ -126,8 +126,8 @@
         // Debug.Print( 1, (String) reqMsg.getAs("String") );
       // }
   
  -    msgContext.setProperty( "HTTP_URL", url );   // horrible name!
  -    msgContext.setProperty( "HTTP_ACTION", action );   // horrible name!
  +    msgContext.setProperty( Constants.MC_HTTP_URL, url );   // horrible name!
  +    msgContext.setProperty( Constants.MC_TARGET, action );   // horrible name!
       try {
         client.init();
         client.invoke( msgContext );
  
  
  
  1.5       +21 -5     xml-axis/java/src/org/apache/axis/handlers/HTTPDispatchHandler.java
  
  Index: HTTPDispatchHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/handlers/HTTPDispatchHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- HTTPDispatchHandler.java	2001/02/02 02:53:25	1.4
  +++ HTTPDispatchHandler.java	2001/02/05 22:30:10	1.5
  @@ -66,6 +66,7 @@
   import org.apache.axis.* ;
   import org.apache.axis.utils.* ;
   import org.apache.axis.message.* ;
  +import org.apache.axis.encoding.Base64 ;
   
   /**
    * This is meant to be used on a SOAP Client to call a SOAP server.
  @@ -92,7 +93,7 @@
       try {
         String   host ;
         int      port = 80 ;
  -      String   action = (String) msgContext.getProperty( "HTTP_ACTION" );
  +      String   action = (String) msgContext.getProperty( Constants.MC_TARGET );
         URL      tmpURL        = new URL( targetURL );
         byte[]   buf           = new byte[4097];
         int      rc            = 0 ;
  @@ -107,10 +108,25 @@
   
         OutputStream  out  = sock.getOutputStream();
         InputStream   inp  = sock.getInputStream();
  -      String        header = "POST " + tmpURL.getPath() + " HTTP/1.0\n" +
  -                             "Content-Length: " + reqEnv.length() + "\n" +
  -                             "Content-Type: text/xml\n" +
  -                             "SOAPAction: " + action + "\n\n" ;
  +      String        otherHeaders = null ;
  +      String        userID = null ;
  +      String        passwd = null ;
  +      
  +      userID = (String) msgContext.getProperty( Constants.MC_USERID );
  +      passwd = (String) msgContext.getProperty( Constants.MC_PASSWORD );
  +
  +      if ( userID != null )
  +        otherHeaders = Constants.HEADER_AUTHORIZATION + ": Basic " + 
  +                       Base64.encode( (userID + ":" + passwd).getBytes() ) + 
  +                       "\n" ;
  +
  +      String  header = Constants.HEADER_POST + " " + 
  +                         tmpURL.getPath() + " HTTP/1.0\n" +
  +                       Constants.HEADER_CONTENT_LENGTH + ": " + 
  +                                          + reqEnv.length() + "\n" +
  +                       Constants.HEADER_CONTENT_TYPE + ": text.xml\n" +
  +                       (otherHeaders == null ? "" : otherHeaders) + 
  +                       Constants.HEADER_SOAP_ACTION + ":" + action + "\n\n" ;
   
         out.write( header.getBytes() );
         out.write( reqEnv.getBytes() );
  
  
  
  1.12      +26 -2     xml-axis/java/src/org/apache/axis/server/transports/AxisServlet.java
  
  Index: AxisServlet.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/server/transports/AxisServlet.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- AxisServlet.java	2001/02/04 13:45:36	1.11
  +++ AxisServlet.java	2001/02/05 22:30:10	1.12
  @@ -63,6 +63,7 @@
   import org.apache.axis.* ;
   import org.apache.axis.server.* ;
   import org.apache.axis.utils.* ;
  +import org.apache.axis.encoding.Base64 ;
   
   /**
    *
  @@ -122,17 +123,40 @@
       /*   for it.                                                        */
       /********************************************************************/
       String  tmp ;
  -    tmp = (String) req.getHeader( "SOAPAction" );
  +    tmp = (String) req.getHeader( Constants.HEADER_SOAP_ACTION );
       if ( tmp != null && "".equals(tmp) )
         tmp = req.getContextPath(); // Is this right?
       if ( tmp != null ) msgContext.setProperty( Constants.MC_TARGET, tmp );
   
  +    tmp = (String) req.getHeader( Constants.HEADER_AUTHORIZATION );
  +    if ( tmp != null ) tmp = tmp.trim();
  +    if ( tmp != null && tmp.startsWith("Basic ") ) {
  +      String user=null ;
  +      int  i ;
  +
  +      tmp = new String( Base64.decode( tmp.substring(6) ) );
  +      i = tmp.indexOf( ':' );
  +      if ( i == -1 ) user = tmp ;
  +      else           user = tmp.substring( 0, i);
  +      msgContext.setProperty( Constants.MC_USERID, user );
  +      if ( i != -1 ) 
  +        msgContext.setProperty( Constants.MC_PASSWORD, tmp.substring(i+1) );
  +    }
  +
       // Invoke the Axis engine...
       try {
         engine.invoke( msgContext );
       }
       catch( Exception e ) {
  -      res.setStatus( HttpServletResponse.SC_INTERNAL_SERVER_ERROR );
  +      if ( e instanceof AxisFault ) {
  +        AxisFault  af = (AxisFault) e ;
  +        if ( "Server.Unauthorized".equals( af.getFaultCode() ) )
  +          res.setStatus( HttpServletResponse.SC_UNAUTHORIZED );
  +        else
  +          res.setStatus( HttpServletResponse.SC_INTERNAL_SERVER_ERROR );
  +      }
  +      else 
  +        res.setStatus( HttpServletResponse.SC_INTERNAL_SERVER_ERROR );
         // msgContext.setOutgoingMessage( new Message(e.toString(), "String" ) );
         if ( !(e instanceof AxisFault) )
           e = new AxisFault( e );
  
  
  
  1.8       +19 -0     xml-axis/java/src/org/apache/axis/utils/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/Constants.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Constants.java	2001/02/01 22:21:34	1.7
  +++ Constants.java	2001/02/05 22:30:10	1.8
  @@ -72,7 +72,22 @@
     public static String MC_SVC_HANDLER      = "ServiceHandler" ;    // Handler
     public static String MC_HTTP_STATUS_CODE = "HTTP_Status_Code" ;  // Integer
     public static String MC_HTTP_STATUS_LINE = "HTTP_Status_Line" ;  // String
  +  public static String MC_HTTP_URL         = "HTTP_URL" ;
  +  public static String MC_USERID           = "UserID" ;
  +  public static String MC_PASSWORD         = "Password" ;
   
  +  // HTTP Stuff
  +  //////////////////////////////////////////////////////////////////////////
  +  public static final String HEADER_POST = "POST";
  +  public static final String HEADER_HOST = "Host";
  +  public static final String HEADER_CONTENT_TYPE = "Content-Type";
  +  public static final String HEADER_CONTENT_TYPE_JMS = "ContentType";
  +  public static final String HEADER_CONTENT_LENGTH = "Content-Length";
  +  public static final String HEADER_CONTENT_LOCATION = "Content-Location";
  +  public static final String HEADER_CONTENT_ID = "Content-ID";
  +  public static final String HEADER_SOAP_ACTION = "SOAPAction";
  +  public static final String HEADER_AUTHORIZATION = "Authorization";
  +
     // Envelope Stuff
     //////////////////////////////////////////////////////////////////////////
     public static String NSPREFIX_SOAP_ENV   = "SOAP-ENV" ;
  @@ -107,4 +122,8 @@
     public static String ATTR_ROOT            = "root" ;
     public static String ATTR_ID              = "id" ;
     public static String ATTR_HREF            = "href" ;
  +
  +  // Misc Strings
  +  //////////////////////////////////////////////////////////////////////////
  +  public static String URI_DEBUG = "http:///xml.apache.org/axis/debug" ;
   }
  
  
  

Mime
View raw message