You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2002/09/07 08:53:40 UTC
cvs commit: jakarta-avalon-apps/enterprise/corbaloc/src/java/org/apache/orb/corbaloc CorbalocCarrier.java CorbalocURLConnection.java CorbalocURLFactory.java Handler.java package.html
mcconnell 2002/09/06 23:53:40
Added: enterprise/corbaloc/src/java/org/apache/orb/corbaloc
CorbalocCarrier.java CorbalocURLConnection.java
CorbalocURLFactory.java Handler.java package.html
Log:
Upgrade of the implementation to support the excalibur/meta type descriptors and Merlin packaged deployment descriptors.
Revision Changes Path
1.1 jakarta-avalon-apps/enterprise/corbaloc/src/java/org/apache/orb/corbaloc/CorbalocCarrier.java
Index: CorbalocCarrier.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*
* Original contribution OSM SARL 2002, http://www.osm.net
*/
package org.apache.orb.corbaloc;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
/**
* Utility class used to return a CORBA Object and resulting URL fragment.</p>
* @see org.apache.orb.corbaloc.CorbalocURLConnection
* @author <a href="mailto:mcconnell@osm.net">Stephen McConnell</a>
*/
class CorbalocCarrier
{
/**
* the CORBA Object reference.
*/
private org.omg.CORBA.Object m_object;
/**
* The resolved part of the URL
*/
private String m_path;
/**
* The remaining unresolved part of the url.
*/
private String m_fragment;
/**
* <p>Creation of a new carrier.</p>
* @param object the CORBA object reference
* @param path the resolved element of the path
* @param fragment the unresolved path element
*/
public CorbalocCarrier( org.omg.CORBA.Object object, String path, String fragment )
{
m_object = object;
m_path = path;
m_fragment = fragment;
}
/**
* Returns the CORBA Object reference.
* @return the object reference
*/
protected org.omg.CORBA.Object getObject()
{
return m_object;
}
/**
* Returns the resolved part of the URL path
* @return the resolved part
*/
protected String getPath()
{
return m_path;
}
/**
* Returns the unresolved corbaloc URL fragment
* @return the fragment
*/
protected String getFragment()
{
return m_fragment;
}
}
1.1 jakarta-avalon-apps/enterprise/corbaloc/src/java/org/apache/orb/corbaloc/CorbalocURLConnection.java
Index: CorbalocURLConnection.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*
* Original contribution OSM SARL 2002, http://www.osm.net
*/
package org.apache.orb.corbaloc;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import org.apache.orb.corbaloc.InvalidQuery;
import org.apache.orb.corbaloc.ServiceRedirection;
import org.apache.orb.corbaloc.UnknownReference;
import org.apache.orb.corbaloc.InvalidReference;
import org.omg.CORBA.ORB;
import org.omg.CORBA.Any;
import org.omg.CORBA.TCKind;
/**
* URL connection handler for the corbaloc protocol. New instances of
* the <code>CorbalocURLConnection</code> are created by a corbaloc
* URL <code>Handler</code> class.
* @see org.apache.orb.corbaloc.Handler
* @author <a href="mailto:mcconnell@osm.net">Stephen McConnell</a>
*/
public class CorbalocURLConnection extends URLConnection
{
/**
* The current ORB.
*/
private ORB m_orb;
/**
* The corbaloc URL.
*/
private URL m_url;
/**
* the primary object resolved during the establishment of a connection.
*/
private CorbalocCarrier m_carrier;
/**
* Creation of a new <code>CorbalocURLConnection</code> handler.
* @param orb the current orb
* @param url the corbaloc URL
*/
public CorbalocURLConnection( ORB orb, URL url )
{
super( url );
m_orb = orb;
m_url = url;
}
/**
* Establishment of a connection to the object defined by the URL.
* The implementation uses the underlying ORB to resolve a CORBA
* object reference using the <code>org.omg.CORBA.ORB.string_to_object</code>
* operation.
*
* @exception IOException if an error is raised while attempting to
* establish the connection.
*/
public void connect() throws IOException
{
if(( m_orb == null ) || ( m_url == null ))
{
throw new IOException("ORB or URL has not been initialized.");
}
//
// make sure that we are only dealing with the strict corbaloc URL
// (i.e. no query or ref elements in the URL)
//
String path = url.toExternalForm();
int queryIndex = path.indexOf("?");
if( queryIndex > -1 )
{
path = path.substring( 0, queryIndex );
}
int refIndex = path.indexOf("#");
if( refIndex > -1 )
{
path = path.substring( 0, refIndex );
}
//
// establish the primary object reference using the strict URL
//
m_carrier = getCORBAObject( path );
}
/**
* Return the CORBA Object associated with the supplied path or null if
* no object exists relative to the path.
* @param path the path
* @return the CORBA OBject reference
*/
private CorbalocCarrier getCORBAObject( String path ) throws IOException
{
return getCORBAObject( path, "" );
}
/**
* Return the CORBA Object associated with the supplied path or null if
* no object exists relative to the path.
* @param path the path
* @return the CORBA OBject reference
*/
private CorbalocCarrier getCORBAObject( String path, String remainder ) throws IOException
{
try
{
org.omg.CORBA.Object object = m_orb.string_to_object( path );
if( object._non_existent() )
{
final int i = path.lastIndexOf("/");
if( i > -1 )
{
try
{
return getCORBAObject( path.substring(0, i ), path.substring( i ) + remainder );
}
catch( IOException ioe )
{
throw new IOException("Object does not exist: " + path );
}
}
else
{
throw new IOException("Object does not exist: " + path );
}
}
else
{
return new CorbalocCarrier( object, path, remainder );
}
}
catch( Throwable e )
{
throw new IOException( e.toString() );
}
}
/**
* Returns the object referenced by the URL. If a connection has not been
* performed, a commection and retrival of the object reference will be
* performed. A client application should narrow the object to the
* appropriate CORBA type.
* @return and instance of org.omg.CORBA.Object
* @exception IOException if an error occurs whhile attempting to retireve
* the object reference.
*/
public Object getContent() throws IOException
{
return getContent( new Class[0] );
}
/**
* Retrieves the contents of this URL connection.
*
* @param classes the <code>Class</code> array
* indicating the requested types
* @return the object fetched that is the first match of the type
* specified in the classes array. null if none of
* the requested types are supported.
* The <code>instanceOf</code> operation should be used to
* determine the specific kind of object returned.
* @exception IOException if an I/O error occurs while
* getting the content.
*/
public Object getContent( Class[] classes ) throws IOException
{
//
// currently returns the primary object established by the
// raw corbaloc URL - could be upgraded to allow association
// of a content handler factory and handling of responses via
// return getContentHandler().getContent(this, classes);
//
if( m_carrier == null )
{
connect();
}
//
// if the url is fully resolved, return the corba object reference
//
if( m_carrier.getFragment().equals("") )
{
return m_carrier.getObject();
}
//
// the corbaloc reference is not fully resolved which means that
// we still need to apply the unresolved fragment aginst the
// remote object
//
URL redirect = null;
Resolver resolver;
try
{
//
// the corbaloc URL is referencing an object that implements the
// remotely accessible Resolver interface - narrow the object to
// that type and apply resolve using a unresolved URL fragment
//
resolver = ResolverHelper.narrow( m_carrier.getObject() );
}
catch( ClassCastException e )
{
final String error =
"Partial resolution of the corbaloc url " + m_url
+ ". Could not resolve the fragment: '" + m_carrier.getFragment()
+ "' against the remote reference.";
throw new IOException( error );
}
catch( Throwable e )
{
final String error =
"Cannot locate a remotely resolvable object form the URL: " + m_url
+ " due to: " + e.getMessage();
throw new IOException( error );
}
//
// we have both a reference to a Resolver and an unresolved url - continue
// url resolution
//
try
{
String path = m_carrier.getFragment();
if( path.startsWith("/") )
{
path = path.substring(1);
}
if( m_url.getQuery() != null )
{
path = path + "?" + m_url.getQuery();
}
if( m_url.getRef() != null )
{
path = path + "#" + m_url.getRef();
}
//
// pass the unresolved fragement onto the remote resolver
//
return resolver.resolve( path );
//
// unpack the result and return it to the client
//
//try
//{
// return getResult( any );
//}
//catch( Throwable e )
//{
// final String error =
// "Failed to extact query result from url: " + m_url
// + " due to: " + e.getMessage();
// throw new IOException( error );
//}
}
catch( ServiceRedirection redirection )
{
//
// the resolver has redirected the request to another
// target
//
redirect = new URL( m_url, redirection.path, new Handler( m_orb ) );
if( m_url.equals( redirect ) )
{
final String error =
"Service replied with a recursive redirection address: "
+ redirect + " from the url " + m_url;
throw new IOException( error );
}
return redirect.getContent( classes );
}
catch( InvalidQuery e )
{
final String error = e.message + " from the url " + m_url;
throw new IOException( error );
}
catch( UnknownReference e )
{
final String error = e.message + " from the url " + m_url;
throw new IOException( error );
}
catch( InvalidReference e )
{
final String error = e.message + " from the url " + m_url;
throw new IOException( error );
}
catch( Throwable e )
{
final String error =
"Remote service raised an unexpected exception: "
+ e.getMessage() + " while handling the url " + m_url;
throw new IOException( error );
}
}
/**
* Unpack the value in the any as a Java object.
* @param any the Any
* @return Object the any contents as a Java Object
*/
private Object getResult( Any any )
{
if( any == null )
{
return null;
}
switch ( any.type().kind().value() )
{
case TCKind._tk_objref:
return any.extract_Object();
case TCKind._tk_abstract_interface:
return any.extract_Object();
case TCKind._tk_value:
return any.extract_Value();
case TCKind._tk_short:
return new Short( any.extract_short() );
case TCKind._tk_long:
return new Integer( any.extract_long() );
case TCKind._tk_ushort:
return new Short( any.extract_ushort() );
case TCKind._tk_ulong:
return new Integer( any.extract_ulong() );
case TCKind._tk_float:
return new Float( any.extract_float() );
case TCKind._tk_double:
return new Double( any.extract_double() );
case TCKind._tk_boolean:
return new Boolean( any.extract_boolean() );
case TCKind._tk_char:
return new Character( any.extract_char() );
case TCKind._tk_octet:
return new Byte( any.extract_octet() );
case TCKind._tk_any:
return any.extract_any();
case TCKind._tk_string:
return any.extract_string();
case TCKind._tk_longlong:
return new Long( any.extract_longlong() );
case TCKind._tk_ulonglong:
return new Long( any.extract_ulonglong() );
case TCKind._tk_longdouble:
throw new org.omg.CORBA.NO_IMPLEMENT();
case TCKind._tk_wchar:
return new Character( any.extract_wchar() );
case TCKind._tk_wstring:
return any.extract_wstring();
case TCKind._tk_fixed:
return any.extract_fixed();
case TCKind._tk_TypeCode:
return any.extract_TypeCode();
default:
throw new IllegalStateException(
"Object type: " + any.type().kind().value() + " unsupported.");
}
}
}
1.1 jakarta-avalon-apps/enterprise/corbaloc/src/java/org/apache/orb/corbaloc/CorbalocURLFactory.java
Index: CorbalocURLFactory.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*
* Original contribution OSM SARL 2002, http://www.osm.net
*/
package org.apache.orb.corbaloc;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandlerFactory;
import java.net.URLStreamHandler;
import org.omg.CORBA.ORB;
/**
* URL protocol handler factory for the corbaloc protocol.
*
* @see Handler
* @author <a href="mailto:mcconnell@osm.net">Stephen McConnell</a>
*/
public class CorbalocURLFactory implements URLStreamHandlerFactory
{
/**
* The default host name.
*/
private final ORB m_orb;
/**
* Creation of a new URL factory for the corbaloc protocol.
* @param orb the orb
*/
public CorbalocURLFactory( ORB orb )
{
m_orb = orb;
}
/**
* Returns a stream URL handler for the service protocol.
* @param protocol the protocol
* @return a service protocol handler if the supplied protocol is "service" else null
*/
public URLStreamHandler createURLStreamHandler( String protocol )
{
if( protocol.equals("corbaloc") )
{
return new Handler( m_orb );
}
else
{
return null;
}
}
}
1.1 jakarta-avalon-apps/enterprise/corbaloc/src/java/org/apache/orb/corbaloc/Handler.java
Index: Handler.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*
* Original contribution OSM SARL 2002, http://www.osm.net
*/
package org.apache.orb.corbaloc;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import org.omg.CORBA.ORB;
/**
* <p>Corbaloc URL protocol handler. Creation of a new corbaloc URL
* requires that the appropriate handler be supplied to the URL
* constructor. The handler (this class) is created with a an
* ORB as a constructor argument. The ORB is subsequently passed
* by the handler to its connection handler which in turn handles
* URL to object dereferencing using the ORB string_to_object
* operation. This URL handler implementation is limited to the
* representation of a single CORBA end-point (whereas corbaloc URLs
* can define multiple endpoints.</p>
* <p>
* <strong>URL creation example:</strong></p>
* <p>
* <pre>
* ORB orb = ORB.init( new String[0], null );
* String path = "corbaloc::mybusiness.com:2056/myService";
* URL url = new URL( null, path, new Handler( orb ) );
* Object object = url.getContent();
* </pre>
* </p>
* @see org.apache.orb.corbaloc.CorbalocURLConnection
* @author <a href="mailto:mcconnell@osm.net">Stephen McConnell</a>
*/
public class Handler extends URLStreamHandler
{
/**
* the current ORB.
*/
private ORB m_orb;
/**
* The connection object.
*/
private URLConnection m_connection;
/**
* <p>Creation of a new handler.</p>
* <p><strong>URL creation example using the handler:</strong></p>
* <p>
* <pre>
* ORB orb = ORB.init( new String[0], null );
* String path = "corbaloc::mybusiness.com:2056/myService";
* URL url = new URL( null, path, new Handler( orb ) );
* Object object = url.getContent();
* </pre>
* </p>
* @param orb the current ORB that will be supplied to the
* connection handler to support object reference establishment.
* If null, the URL will be able to perform parsing operations
* (see toExternalForm), however any attempt to connect will
* raise an exception.
*/
public Handler( ORB orb )
{
m_orb = orb;
}
/**
* Opens a connection to the specified URL.
*
* @param url A URL to open a connection to.
* @return The established connection.
* @throws IOException If a connection failure occurs.
*/
protected URLConnection openConnection( final URL url )
throws IOException
{
if( m_connection != null )
{
return m_connection;
}
if( m_orb == null )
{
throw new IOException(
"Handler has not been supplied with a ORB - cannot connect.");
}
m_connection = new CorbalocURLConnection( m_orb, url );
m_connection.connect();
return m_connection;
}
/**
* Parses the string representation of a <code>URL</code> into a
* <code>URL</code> object.
* e.g. corbaloc:iiop:1.2@mybusiness.com/myService
* or, corbaloc::mybusiness.com/myService
* <p>
* If there is any inherited context, then it has already been
* copied into the <code>URL</code> argument.
*
* @param url the <code>URL</code> to receive the result of parsing
* the spec.
* @param spec the <code>String</code> representing the URL that
* must be parsed.
* @param start the character index at which to begin parsing. This is
* just past the '<code>:</code>' (if there is one) that
* specifies the determination of the protocol name.
* @param limit the character position to stop parsing at. This is the
* end of the string or the position of the
* "<code>#</code>" character, if present. All information
* after the sharp sign indicates an anchor.
*/
protected void parseURL( URL url, String spec, int start, int limit )
{
//
// get the ref component
// (from # to the end of the spec)
//
String ref = url.getRef();
String remainder = spec.substring( start, limit );
int refLoc = spec.indexOf("#", start );
if( refLoc > -1 )
{
ref = spec.substring( refLoc + 1 );
remainder = spec.substring( start, refLoc );
}
//
// get the query component
// (from ? to the end of the remainder)
//
String query = url.getQuery();
int queryLoc = remainder.indexOf("?");
if( queryLoc > -1 )
{
query = remainder.substring( queryLoc + 1, remainder.length() );
remainder = remainder.substring( 0, queryLoc );
}
//
// get the path component
// (from / to the end of the remainder)
//
String path = url.getPath();
int pathLoc = remainder.indexOf("/");
if( pathLoc > -1 )
{
path = remainder.substring( pathLoc, remainder.length() );
remainder = remainder.substring( 0, pathLoc );
}
//
// get the host
// if a iiop version is included, then the host is between the "@"
// character and the end of the reamining string, otherwise we are
// using a default IIOP protocol flag in which case the first ":"
// signals the beginning of the host declaration
//
String user = url.getUserInfo();
String hostAndPort = null;
int hostLoc = remainder.indexOf("@");
if( hostLoc < 0 )
{
if( remainder.startsWith(":") )
{
user = "iiop:1.2";
hostAndPort = remainder.substring(1,remainder.length());
}
else
{
if( url.getHost() == null )
{
throw new IllegalArgumentException(
"Missing @ delimiter - corbaloc:iiop:<major>.<minor>@<host>/<path>" );
}
}
}
else
{
// handle user info and host
user = remainder.substring(0,hostLoc);
hostAndPort = remainder.substring( hostLoc + 1, remainder.length() );
}
int port = url.getPort();
String host = url.getHost();
if( hostAndPort != null )
{
int portLoc = hostAndPort.indexOf(":");
if( portLoc > -1 )
{
host = hostAndPort.substring(0,portLoc);
try
{
port = Integer.parseInt(
hostAndPort.substring( portLoc + 1, hostAndPort.length() ) );
}
catch( Throwable e )
{
throw new IllegalArgumentException(
"Invalid port value: " + spec );
}
}
}
//
// create authority string dependending of non-default port reference
//
String authority = null;
if( port == getDefaultPort() )
{
authority = host;
}
else
{
authority = host + ":" + port;
}
//
// set the URL parameters
//
setURL( url, "corbaloc", host, port, authority, user, path, query, ref );
}
/**
* Retuns the default port for a CORBA application.
* @return int the default port value
*/
protected int getDefaultPort()
{
return 2809;
}
/**
* Returns the URL in a string form.
* @param url to the URL to externalize
* @return String the external form of the URL
*/
protected String toExternalForm( URL url )
{
StringBuffer result = new StringBuffer( url.getProtocol());
result.append(":");
if( url.getUserInfo() == null )
{
result.append(":");
result.append( url.getAuthority() );
}
else
{
result.append( url.getUserInfo() );
result.append( "@" );
result.append( url.getAuthority() );
}
if (url.getFile() != null)
{
result.append(url.getFile());
}
if (url.getRef() != null)
{
result.append("#");
result.append(url.getRef());
}
return result.toString();
}
}
1.1 jakarta-avalon-apps/enterprise/corbaloc/src/java/org/apache/orb/corbaloc/package.html
Index: package.html
===================================================================
<body>
<p>Resources supporting the creation and management URLs using the corbaloc protocol.</p>
</body>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>