mcconnell 2002/06/03 21:22:48
Modified: enterprise/orb/src/java/org/apache/orb/corbaloc
CorbalocURLConnection.java Handler.java
Log:
updated error management
Revision Changes Path
1.2 +224 -3
jakarta-avalon-apps/enterprise/orb/src/java/org/apache/orb/corbaloc/CorbalocURLConnection.java
Index: CorbalocURLConnection.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-apps/enterprise/orb/src/java/org/apache/orb/corbaloc/CorbalocURLConnection.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CorbalocURLConnection.java 3 Jun 2002 14:41:26 -0000 1.1
+++ CorbalocURLConnection.java 4 Jun 2002 04:22:48 -0000 1.2
@@ -12,12 +12,14 @@
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
+import java.net.MalformedURLException;
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
@@ -95,6 +97,7 @@
try
{
+ System.out.println("connecting with path: " + path );
m_object = m_orb.string_to_object( path );
}
catch( Throwable e )
@@ -165,8 +168,226 @@
// is narrowable to a query handler, then narrow and invoke a query
and
// return the result
-
- return m_object();
+ URL redirect = null;
+ final String query = m_url.getQuery();
+ final String ref = m_url.getRef();
+ if( query != null )
+ {
+
+ //
+ // make sure that the target implements the finder interface
+ //
+
+ Finder finder = null;
+ try
+ {
+ finder = FinderHelper.narrow( m_object );
+ }
+ catch( Throwable bp )
+ {
+ final String error = "Target object does not support query
semantics: "
+ + bp.toString();
+ throw new IOException( error );
+ }
+
+ //
+ // invoke the query and unpack the results
+ //
+
+ Any any = null;
+ try
+ {
+ any = finder.resolve_query( query );
+ }
+ catch( ServiceRedirection redirection )
+ {
+ redirect = new URL( m_url, redirection.path, new Handler(
m_orb ) );
+ }
+ catch( InvalidQuery iq )
+ {
+ final String error = "Remote finder raised an invalid query:
" + iq.message ;
+ throw new IOException( error );
+ }
+ catch( Throwable e )
+ {
+ final String error = "Remote finder raised an unexpected
exception:"
+ + e.toString();
+ throw new IOException( error );
+ }
+
+ //
+ // unpack the results
+ //
+
+ if( any != null )
+ {
+ try
+ {
+ return getResult( any );
+ }
+ catch( Throwable e )
+ {
+ final String error = "Failed to extact query result:"
+ + e.toString();
+ throw new IOException( error );
+ }
+ }
+
+ }
+ else if( ref != null )
+ {
+ // if the ref portion of the URL is not null, and the object
reference
+ // is narrowable to a ref handler, then narrow and invoke a
selection and
+ // return the result
+
+ Chooser chooser = null;
+ try
+ {
+ chooser = ChooserHelper.narrow( m_object );
+ }
+ catch( Throwable bp )
+ {
+ final String error = "Target object does not support ref
semantics: "
+ + bp.toString();
+ throw new IOException( error );
+ }
+
+ Any any = null;
+ try
+ {
+ any = chooser.select( ref );
+ }
+ catch( ServiceRedirection redirection )
+ {
+ redirect = new URL( m_url, redirection.path, new Handler(
m_orb ) );
+ }
+ catch( UnknownReference ur )
+ {
+ final String error = "Remote chooser does not recognize the
ref value: " + ref;
+ throw new IOException( error );
+ }
+ catch( Throwable e )
+ {
+ final String error = "Remote chooser raised an unexpected
exception: "
+ + e.toString();
+ throw new IOException( error );
+ }
+
+ //
+ // unpack the results
+ //
+
+ if( any != null )
+ {
+ try
+ {
+ return getResult( any );
+ }
+ catch( Throwable e )
+ {
+ final String error = "Failed to extact query result:"
+ + e.toString();
+ throw new IOException( error );
+ }
+ }
+ }
+ else
+ {
+ return m_object;
+ }
+
+ if( m_url.equals( redirect ) )
+ {
+ final String error = "Service replied with a recursive
redirection address.";
+ throw new IOException( error );
+ }
+ else
+ {
+ return redirect.getContent( classes );
+ }
}
+ /**
+ * 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:
+ System.out.println("UNKNOWN CONTENT: " +
any.type().kind().value() );
+ throw new org.omg.CORBA.NO_IMPLEMENT();
+ }
+ }
}
1.2 +24 -20
jakarta-avalon-apps/enterprise/orb/src/java/org/apache/orb/corbaloc/Handler.java
Index: Handler.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-apps/enterprise/orb/src/java/org/apache/orb/corbaloc/Handler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Handler.java 3 Jun 2002 14:41:26 -0000 1.1
+++ Handler.java 4 Jun 2002 04:22:48 -0000 1.2
@@ -125,7 +125,7 @@
// (from # to the end of the spec)
//
- String ref = null;
+ String ref = url.getRef();
String remainder = spec.substring( start, limit );
int refLoc = spec.indexOf("#", start );
if( refLoc > -1 )
@@ -139,7 +139,7 @@
// (from ? to the end of the remainder)
//
- String query = null;
+ String query = url.getQuery();
int queryLoc = remainder.indexOf("?");
if( queryLoc > -1 )
{
@@ -152,7 +152,7 @@
// (from / to the end of the remainder)
//
- String path = null;
+ String path = url.getPath();
int pathLoc = remainder.indexOf("/");
if( pathLoc > -1 )
{
@@ -168,10 +168,9 @@
// signals the beginning of the host declaration
//
- String user = null;
+ String user = url.getUserInfo();
String hostAndPort = null;
int hostLoc = remainder.indexOf("@");
- //System.out.println("hostAndPort: " + remainder );
if( hostLoc < 0 )
{
@@ -182,32 +181,37 @@
}
else
{
- throw new IllegalArgumentException(
- "Missing @ delimiter -
corbaloc:iiop:<major>.<minor>@<host>/<path>" );
+ 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 = -1;
- String host = null;
- int portLoc = hostAndPort.indexOf(":");
- if( portLoc > -1 )
+ int port = url.getPort();
+ String host = url.getHost();
+ if( hostAndPort != null )
{
- host = hostAndPort.substring(0,portLoc);
- try
- {
- port = Integer.parseInt( hostAndPort.substring( portLoc + 1,
hostAndPort.length() ) );
- }
- catch( Throwable e )
+ int portLoc = hostAndPort.indexOf(":");
+ if( portLoc > -1 )
{
- throw new IllegalArgumentException(
- "Invalid port value: " + spec );
+ 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 );
+ }
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>