Search in sources :

Example 1 with CannotProceedException

use of javax.naming.CannotProceedException in project wildfly by wildfly.

the class ServiceBasedNamingStore method cannotProceedException.

private static CannotProceedException cannotProceedException(final Object resolvedObject, final Name remainingName) {
    final CannotProceedException cpe = new CannotProceedException();
    cpe.setResolvedObj(resolvedObject);
    cpe.setRemainingName(remainingName);
    return cpe;
}
Also used : CannotProceedException(javax.naming.CannotProceedException)

Example 2 with CannotProceedException

use of javax.naming.CannotProceedException in project wildfly by wildfly.

the class ExceptionMapper method mapException.

public static NamingException mapException(Exception e, CNCtx ctx, NameComponent[] inputName) throws NamingException {
    if (e instanceof NamingException) {
        return (NamingException) e;
    }
    if (e instanceof RuntimeException) {
        throw (RuntimeException) e;
    }
    NamingException ne;
    if (e instanceof NotFound) {
        if (ctx.federation) {
            return tryFed((NotFound) e, ctx, inputName);
        } else {
            ne = new NameNotFoundException();
        }
    } else if (e instanceof CannotProceed) {
        ne = new CannotProceedException();
        NamingContext nc = ((CannotProceed) e).cxt;
        NameComponent[] rest = ((CannotProceed) e).rest_of_name;
        // NotFound doesn't set rest as expected. -RL
        if (inputName != null && (inputName.length > rest.length)) {
            NameComponent[] resolvedName = new NameComponent[inputName.length - rest.length];
            System.arraycopy(inputName, 0, resolvedName, 0, resolvedName.length);
            // Wrap resolved NamingContext inside a CNCtx
            // Guess that its name (which is relative to ctx)
            // is the part of inputName minus rest_of_name
            ne.setResolvedObj(new CNCtx(ctx._orb, nc, ctx._env, ctx.makeFullName(resolvedName)));
        } else {
            ne.setResolvedObj(ctx);
        }
        ne.setRemainingName(org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToName(rest));
    } else if (e instanceof InvalidName) {
        ne = new InvalidNameException();
    } else if (e instanceof AlreadyBound) {
        ne = new NameAlreadyBoundException();
    } else if (e instanceof NotEmpty) {
        ne = new ContextNotEmptyException();
    } else {
        ne = new NamingException();
    }
    ne.setRootCause(e);
    return ne;
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) CannotProceed(org.omg.CosNaming.NamingContextPackage.CannotProceed) NamingContext(org.omg.CosNaming.NamingContext) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) InvalidName(org.omg.CosNaming.NamingContextPackage.InvalidName) InvalidNameException(javax.naming.InvalidNameException) CannotProceedException(javax.naming.CannotProceedException) ContextNotEmptyException(javax.naming.ContextNotEmptyException) NamingException(javax.naming.NamingException) AlreadyBound(org.omg.CosNaming.NamingContextPackage.AlreadyBound) NotEmpty(org.omg.CosNaming.NamingContextPackage.NotEmpty) NotFound(org.omg.CosNaming.NamingContextPackage.NotFound)

Example 3 with CannotProceedException

use of javax.naming.CannotProceedException in project wildfly by wildfly.

the class ExceptionMapper method tryFed.

private static NamingException tryFed(NotFound e, CNCtx ctx, NameComponent[] inputName) throws NamingException {
    NameComponent[] rest = ((NotFound) e).rest_of_name;
    if (debug) {
    }
    // If one of those is not found, you get "aa" as 'rest'.
    if (rest.length == 1 && inputName != null) {
        // Check that we're not talking to 1.2/1.3 Sun tnameserv
        NameComponent lastIn = inputName[inputName.length - 1];
        if (rest[0].id.equals(lastIn.id) && rest[0].kind != null && rest[0].kind.equals(lastIn.kind)) {
        // Might be legit
        } else {
            // Due to 1.2/1.3 bug that always returns single-item 'rest'
            NamingException ne = new NameNotFoundException();
            ne.setRemainingName(org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToName(rest));
            ne.setRootCause(e);
            throw ne;
        }
    }
    // Fixed in 1.4; perform calculations based on correct (1.4) behavior
    // Calculate the components of the name that has been resolved
    NameComponent[] resolvedName = null;
    int len = 0;
    if (inputName != null && (inputName.length >= rest.length)) {
        if (e.why == NotFoundReason.not_context) {
            // First component of rest is found but not a context; keep it
            // as part of resolved name
            len = inputName.length - (rest.length - 1);
            // Remove resolved component from rest
            if (rest.length == 1) {
                // No more remaining
                rest = null;
            } else {
                NameComponent[] tmp = new NameComponent[rest.length - 1];
                System.arraycopy(rest, 1, tmp, 0, tmp.length);
                rest = tmp;
            }
        } else {
            len = inputName.length - rest.length;
        }
        if (len > 0) {
            resolvedName = new NameComponent[len];
            System.arraycopy(inputName, 0, resolvedName, 0, len);
        }
    }
    // Create CPE and set common fields
    CannotProceedException cpe = new CannotProceedException();
    cpe.setRootCause(e);
    if (rest != null && rest.length > 0) {
        cpe.setRemainingName(org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToName(rest));
    }
    cpe.setEnvironment(ctx._env);
    // Lookup resolved name to get resolved object
    final java.lang.Object resolvedObj = (resolvedName != null) ? ctx.callResolve(resolvedName) : ctx;
    if (resolvedObj instanceof javax.naming.Context) {
        // obj is a context and child is not found
        // try getting its nns dynamically by constructing
        // a Reference containing obj.
        RefAddr addr = new RefAddr("nns") {

            public java.lang.Object getContent() {
                return resolvedObj;
            }

            private static final long serialVersionUID = 669984699392133792L;
        };
        Reference ref = new Reference("java.lang.Object", addr);
        // Resolved name has trailing slash to indicate nns
        CompositeName cname = new CompositeName();
        // add trailing slash
        cname.add("");
        cpe.setResolvedObj(ref);
        cpe.setAltName(cname);
        cpe.setAltNameCtx((javax.naming.Context) resolvedObj);
        return cpe;
    } else {
        // Not a context, use object factory to transform object.
        Name cname = org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToName(resolvedName);
        java.lang.Object resolvedObj2;
        try {
            resolvedObj2 = NamingManager.getObjectInstance(resolvedObj, cname, ctx, ctx._env);
        } catch (NamingException ge) {
            throw ge;
        } catch (Exception ge) {
            NamingException ne = IIOPLogger.ROOT_LOGGER.errorGeneratingObjectViaFactory();
            ne.setRootCause(ge);
            throw ne;
        }
        // If a context, continue operation with context
        if (resolvedObj2 instanceof javax.naming.Context) {
            cpe.setResolvedObj(resolvedObj2);
        } else {
            // Add trailing slash
            cname.add("");
            cpe.setAltName(cname);
            // Create nns reference
            final java.lang.Object rf2 = resolvedObj2;
            RefAddr addr = new RefAddr("nns") {

                public java.lang.Object getContent() {
                    return rf2;
                }

                private static final long serialVersionUID = -785132553978269772L;
            };
            Reference ref = new Reference("java.lang.Object", addr);
            cpe.setResolvedObj(ref);
            cpe.setAltNameCtx(ctx);
        }
        return cpe;
    }
}
Also used : NamingContext(org.omg.CosNaming.NamingContext) NameComponent(org.omg.CosNaming.NameComponent) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) CannotProceedException(javax.naming.CannotProceedException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) NamingException(javax.naming.NamingException) ContextNotEmptyException(javax.naming.ContextNotEmptyException) InvalidNameException(javax.naming.InvalidNameException) NameNotFoundException(javax.naming.NameNotFoundException) CompositeName(javax.naming.CompositeName) InvalidName(org.omg.CosNaming.NamingContextPackage.InvalidName) Name(javax.naming.Name) RefAddr(javax.naming.RefAddr) CannotProceedException(javax.naming.CannotProceedException) NamingException(javax.naming.NamingException) NotFound(org.omg.CosNaming.NamingContextPackage.NotFound)

Example 4 with CannotProceedException

use of javax.naming.CannotProceedException in project wildfly by wildfly.

the class CNCtx method destroySubcontext.

/**
 * Uses the callDestroy function to destroy the context. Destroys
 * the current context if name is empty.
 *
 * @param name JNDI Name
 * @throws javax.naming.OperationNotSupportedException when list is invoked
 *                                        with a non-null argument
 */
public void destroySubcontext(Name name) throws NamingException {
    if (_nc == null)
        throw IIOPLogger.ROOT_LOGGER.notANamingContext(name.toString());
    NamingContext the_nc = _nc;
    NameComponent[] path = org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.nameToCosName(name);
    if (name.size() > 0) {
        try {
            javax.naming.Context ctx = (javax.naming.Context) callResolve(path);
            CNCtx cnc = (CNCtx) ctx;
            the_nc = cnc._nc;
            // remove the reference to the context
            cnc.close();
        } catch (ClassCastException e) {
            throw new NotContextException(name.toString());
        } catch (CannotProceedException e) {
            javax.naming.Context cctx = getContinuationContext(e);
            cctx.destroySubcontext(e.getRemainingName());
            return;
        } catch (NameNotFoundException e) {
            if (e.getRootCause() instanceof NotFound && leafNotFound((NotFound) e.getRootCause(), path[path.length - 1])) {
                // leaf missing OK
                return;
            }
            throw e;
        } catch (NamingException e) {
            throw e;
        }
    }
    callDestroy(the_nc);
    callUnbind(path);
}
Also used : NamingContext(org.omg.CosNaming.NamingContext) NotContextException(javax.naming.NotContextException) NameComponent(org.omg.CosNaming.NameComponent) NameNotFoundException(javax.naming.NameNotFoundException) NamingContext(org.omg.CosNaming.NamingContext) CannotProceedException(javax.naming.CannotProceedException) NamingException(javax.naming.NamingException) NotFound(org.omg.CosNaming.NamingContextPackage.NotFound)

Example 5 with CannotProceedException

use of javax.naming.CannotProceedException in project wildfly by wildfly.

the class NamingContext method lookup.

public Object lookup(final Name name, boolean dereference) throws NamingException {
    check(name, JndiPermission.ACTION_LOOKUP);
    if (isEmpty(name)) {
        return new NamingContext(prefix, namingStore, environment);
    }
    final Name absoluteName = getAbsoluteName(name);
    Object result;
    try {
        result = namingStore.lookup(absoluteName, dereference);
    } catch (CannotProceedException cpe) {
        final Context continuationContext = NamingManager.getContinuationContext(cpe);
        if (continuationContext instanceof NamingContext) {
            result = ((NamingContext) continuationContext).lookup(cpe.getRemainingName(), dereference);
        } else {
            result = continuationContext.lookup(cpe.getRemainingName());
        }
    }
    if (result instanceof ResolveResult) {
        final ResolveResult resolveResult = (ResolveResult) result;
        final Object resolvedObject = resolveResult.getResolvedObj();
        Object context;
        if (resolvedObject instanceof Context) {
            context = resolvedObject;
        } else if (resolvedObject instanceof LinkRef) {
            context = resolveLink(resolvedObject, dereference);
        } else {
            context = getObjectInstance(resolvedObject, absoluteName, environment);
        }
        if (!(context instanceof Context)) {
            throw notAContextException(absoluteName.getPrefix(absoluteName.size() - resolveResult.getRemainingName().size()));
        }
        final Context namingContext = (Context) context;
        if (namingContext instanceof NamingContext) {
            return ((NamingContext) namingContext).lookup(resolveResult.getRemainingName(), dereference);
        } else {
            return namingContext.lookup(resolveResult.getRemainingName());
        }
    } else if (result instanceof LinkRef) {
        result = resolveLink(result, dereference);
    } else if (result instanceof Reference) {
        result = getObjectInstance(result, absoluteName, environment);
        if (result instanceof LinkRef) {
            result = resolveLink(result, dereference);
        }
    }
    return result;
}
Also used : Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) EventContext(javax.naming.event.EventContext) CannotProceedException(javax.naming.CannotProceedException) Reference(javax.naming.Reference) ResolveResult(javax.naming.spi.ResolveResult) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) LinkRef(javax.naming.LinkRef)

Aggregations

CannotProceedException (javax.naming.CannotProceedException)6 NameNotFoundException (javax.naming.NameNotFoundException)3 NamingException (javax.naming.NamingException)3 NamingContext (org.omg.CosNaming.NamingContext)3 NotFound (org.omg.CosNaming.NamingContextPackage.NotFound)3 CompositeName (javax.naming.CompositeName)2 ContextNotEmptyException (javax.naming.ContextNotEmptyException)2 InvalidNameException (javax.naming.InvalidNameException)2 Name (javax.naming.Name)2 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)2 Reference (javax.naming.Reference)2 NameComponent (org.omg.CosNaming.NameComponent)2 InvalidName (org.omg.CosNaming.NamingContextPackage.InvalidName)2 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 LinkRef (javax.naming.LinkRef)1 NotContextException (javax.naming.NotContextException)1 RefAddr (javax.naming.RefAddr)1 EventContext (javax.naming.event.EventContext)1 ResolveResult (javax.naming.spi.ResolveResult)1