Search in sources :

Example 26 with NameNotFoundException

use of javax.naming.NameNotFoundException in project hibernate-orm by hibernate.

the class JndiServiceImpl method bind.

private void bind(Name name, Object value, Context context) {
    try {
        LOG.tracef("Binding : %s", name);
        context.rebind(name, value);
    } catch (Exception initialException) {
        // We had problems doing a simple bind operation.
        if (name.size() == 1) {
            // if the jndi name had only 1 component there is nothing more we can do...
            throw new JndiException("Error performing bind [" + name + "]", initialException);
        }
        // Otherwise, there is a good chance this may have been caused by missing intermediate contexts.  So we
        // attempt to create those missing intermediate contexts and bind again
        Context intermediateContextBase = context;
        while (name.size() > 1) {
            final String intermediateContextName = name.get(0);
            Context intermediateContext = null;
            try {
                LOG.tracev("Intermediate lookup: {0}", intermediateContextName);
                intermediateContext = (Context) intermediateContextBase.lookup(intermediateContextName);
            } catch (NameNotFoundException handledBelow) {
            // ok as we will create it below if not found
            } catch (NamingException e) {
                throw new JndiException("Unanticipated error doing intermediate lookup", e);
            }
            if (intermediateContext != null) {
                LOG.tracev("Found intermediate context: {0}", intermediateContextName);
            } else {
                LOG.tracev("Creating sub-context: {0}", intermediateContextName);
                try {
                    intermediateContext = intermediateContextBase.createSubcontext(intermediateContextName);
                } catch (NamingException e) {
                    throw new JndiException("Error creating intermediate context [" + intermediateContextName + "]", e);
                }
            }
            intermediateContextBase = intermediateContext;
            name = name.getSuffix(1);
        }
        LOG.tracev("Binding : {0}", name);
        try {
            intermediateContextBase.rebind(name, value);
        } catch (NamingException e) {
            throw new JndiException("Error performing intermediate bind [" + name + "]", e);
        }
    }
    LOG.debugf("Bound name: %s", name);
}
Also used : InitialContext(javax.naming.InitialContext) EventContext(javax.naming.event.EventContext) Context(javax.naming.Context) NameNotFoundException(javax.naming.NameNotFoundException) JndiException(org.hibernate.engine.jndi.JndiException) NamingException(javax.naming.NamingException) NamingException(javax.naming.NamingException) JndiException(org.hibernate.engine.jndi.JndiException) JndiNameException(org.hibernate.engine.jndi.JndiNameException) InvalidNameException(javax.naming.InvalidNameException) NameNotFoundException(javax.naming.NameNotFoundException)

Example 27 with NameNotFoundException

use of javax.naming.NameNotFoundException in project jdk8u_jdk by JetBrains.

the class HelloClient method executeRmiClientCall.

public static void executeRmiClientCall() throws Exception {
    Context ic;
    Object objref;
    HelloInterface helloSvc;
    String response;
    int retryCount = 0;
    Test test = new Test();
    System.out.println("HelloClient.main: enter ...");
    while (retryCount < MAX_RETRY) {
        try {
            ic = new InitialContext();
            System.out.println("HelloClient.main: HelloService lookup ...");
            // STEP 1: Get the Object reference from the Name Service
            // using JNDI call.
            objref = ic.lookup("HelloService");
            System.out.println("HelloClient: Obtained a ref. to Hello server.");
            // STEP 2: Narrow the object reference to the concrete type and
            // invoke the method.
            helloSvc = (HelloInterface) PortableRemoteObject.narrow(objref, HelloInterface.class);
            System.out.println("HelloClient: Invoking on remote server with ConcurrentHashMap parameter");
            ConcurrentHashMap<String, String> testConcurrentHashMap = new ConcurrentHashMap<String, String>();
            response = helloSvc.sayHelloWithHashMap(testConcurrentHashMap);
            System.out.println("HelloClient: Server says:  " + response);
            if (!response.contains("Hello with hashMapSize ==")) {
                System.out.println("HelloClient: expected response not received");
                throw new RuntimeException("Expected Response Hello with hashMapSize == 0 not received");
            }
            responseReceived = true;
            break;
        } catch (NameNotFoundException nnfEx) {
            System.err.println("NameNotFoundException Caught  .... try again");
            retryCount++;
            try {
                Thread.sleep(ONE_SECOND);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            continue;
        } catch (Exception e) {
            System.err.println("Exception " + e + "Caught");
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
    System.err.println("HelloClient terminating ");
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) NameNotFoundException(javax.naming.NameNotFoundException) InitialContext(javax.naming.InitialContext) MalformedURLException(java.net.MalformedURLException) NamingException(javax.naming.NamingException) RemoteException(java.rmi.RemoteException) NotBoundException(java.rmi.NotBoundException) NameNotFoundException(javax.naming.NameNotFoundException) PortableRemoteObject(javax.rmi.PortableRemoteObject) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 28 with NameNotFoundException

use of javax.naming.NameNotFoundException in project ACS by ACS-Community.

the class ManagerImpl method bind.

/**
	 * Bind object to remote directory.
	 *
	 * Use INS syntax specified in the INS specification.
	 * In short, the syntax is that components are left-to-right slash ('/') separated and case-sensitive.
	 * The id and kind of each component are separated by the period character ('.').
	 *
	 * @param	remoteDirectory	remote directory context to be used.
	 * @param	name	name of the object, code non-<code>null</code>
	 * @param	object	object to be binded
	 */
private void bind(Context remoteDirectory, String name, String type, Object object) {
    assert (name != null);
    // do not bind interdomain names
    if (name.startsWith(CURL_URI_SCHEMA))
        return;
    if (remoteDirectory != null) {
        try {
            // hierarchical name check
            int pos = name.indexOf('/');
            if (pos != -1) {
                if (pos == 0 || pos == name.length())
                    throw new IllegalArgumentException("Invalid hierarchical name '" + name + "'.");
                String parent = name.substring(0, pos);
                String child = name.substring(pos + 1);
                // lookup for subcontext, if not found create one
                Context parentContext = null;
                try {
                    parentContext = (Context) remoteDirectory.lookup(parent);
                } catch (NameNotFoundException nnfe) {
                // noop
                }
                if (parentContext == null) {
                    parentContext = remoteDirectory.createSubcontext(parent);
                /// @todo temp. commented out
                //generateHiearchyContexts(remoteDirectory, parent, parentContext);
                }
                // delegate
                bind(parentContext, child, type, object);
                return;
            }
            NameParser parser = remoteDirectory.getNameParser("");
            Name n;
            if (type != null)
                n = parser.parse(name + "." + type);
            else
                n = parser.parse(name);
            // special case
            if (name.endsWith(".D")) {
                remoteDirectory.rebind(n, object);
            /// @todo temp. commented out
            //generateHiearchyContexts(remoteDirectory, name, (Context)remoteDirectory.lookup(name));
            } else
                remoteDirectory.bind(n, object);
        } catch (NameAlreadyBoundException nabe) {
            rebind(remoteDirectory, name, type, object);
        } catch (NamingException ne) {
            CoreException ce = new CoreException("Failed to bind name '" + name + "' to the remote directory.", ne);
            logger.log(Level.FINE, ce.getMessage(), ce);
        }
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) CoreException(com.cosylab.acs.maci.CoreException) NameNotFoundException(javax.naming.NameNotFoundException) NamingException(javax.naming.NamingException) NameParser(javax.naming.NameParser) Name(javax.naming.Name)

Example 29 with NameNotFoundException

use of javax.naming.NameNotFoundException in project geode by apache.

the class ContextImpl method destroySubcontext.

/**
   * Destroys subcontext with name name. The subcontext must be empty otherwise
   * ContextNotEmptyException is thrown. Once a context is destroyed, the instance should not be
   * used.
   * 
   * @param name subcontext to destroy
   * @throws NoPermissionException if this context has been destroyed.
   * @throws InvalidNameException if name is empty or is CompositeName that spans more than one
   *         naming system.
   * @throws ContextNotEmptyException if Context name is not empty.
   * @throws NameNotFoundException if subcontext with name name can not be found.
   * @throws NotContextException if name is not bound to instance of ContextImpl.
   * 
   */
public void destroySubcontext(Name name) throws NamingException {
    checkIsDestroyed();
    Name parsedName = getParsedName(name);
    if (parsedName.size() == 0 || parsedName.get(0).length() == 0) {
        throw new InvalidNameException(LocalizedStrings.ContextImpl_NAME_CAN_NOT_BE_EMPTY.toLocalizedString());
    }
    String subContextName = parsedName.get(0);
    Object boundObject = ctxMaps.get(subContextName);
    if (boundObject == null) {
        throw new NameNotFoundException(LocalizedStrings.ContextImpl_NAME_0_NOT_FOUND_IN_THE_CONTEXT.toLocalizedString(subContextName));
    }
    if (!(boundObject instanceof ContextImpl)) {
        throw new NotContextException();
    }
    ContextImpl contextToDestroy = (ContextImpl) boundObject;
    if (parsedName.size() == 1) {
        // non-empty Context.
        if (contextToDestroy.ctxMaps.size() == 0) {
            ctxMaps.remove(subContextName);
            contextToDestroy.destroyInternal();
        } else {
            throw new ContextNotEmptyException(LocalizedStrings.ContextImpl_CAN_NOT_DESTROY_NONEMPTY_CONTEXT.toLocalizedString());
        }
    } else {
        // Let the subcontext destroy the context
        ((ContextImpl) boundObject).destroySubcontext(parsedName.getSuffix(1));
    }
}
Also used : NotContextException(javax.naming.NotContextException) InvalidNameException(javax.naming.InvalidNameException) NameNotFoundException(javax.naming.NameNotFoundException) ContextNotEmptyException(javax.naming.ContextNotEmptyException) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 30 with NameNotFoundException

use of javax.naming.NameNotFoundException in project geode by apache.

the class ContextImpl method unbind.

/**
   * Removes name and its associated object from the context.
   * 
   * @param name name to remove
   * @throws NoPermissionException if this context has been destroyed.
   * @throws InvalidNameException if name is empty or is CompositeName that spans more than one
   *         naming system
   * @throws NameNotFoundException if intermediate context can not be found
   * @throws NotContextException if name has more than one atomic name and intermediate context is
   *         not found.
   * @throws NamingException if any other naming exception occurs
   * 
   */
public void unbind(Name name) throws NamingException {
    checkIsDestroyed();
    Name parsedName = getParsedName(name);
    if (parsedName.size() == 0 || parsedName.get(0).length() == 0) {
        throw new InvalidNameException(LocalizedStrings.ContextImpl_NAME_CAN_NOT_BE_EMPTY.toLocalizedString());
    }
    String nameToRemove = parsedName.get(0);
    // remove a and its associated object
    if (parsedName.size() == 1) {
        ctxMaps.remove(nameToRemove);
    } else {
        // scenerio unbind a/b or a/b/c
        // remove b and its associated object
        Object boundObject = ctxMaps.get(nameToRemove);
        if (boundObject instanceof Context) {
            // remove b and its associated object
            ((Context) boundObject).unbind(parsedName.getSuffix(1));
        } else {
            // if the name is not found then throw exception
            if (!ctxMaps.containsKey(nameToRemove)) {
                throw new NameNotFoundException(LocalizedStrings.ContextImpl_CAN_NOT_FIND_0.toLocalizedString(name));
            }
            throw new NotContextException(LocalizedStrings.ContextImpl_EXPECTED_CONTEXT_BUT_FOUND_0.toLocalizedString(boundObject));
        }
    }
}
Also used : Context(javax.naming.Context) NotContextException(javax.naming.NotContextException) InvalidNameException(javax.naming.InvalidNameException) NameNotFoundException(javax.naming.NameNotFoundException) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Aggregations

NameNotFoundException (javax.naming.NameNotFoundException)112 InitialContext (javax.naming.InitialContext)56 Context (javax.naming.Context)51 NamingException (javax.naming.NamingException)51 Test (org.junit.Test)36 Name (javax.naming.Name)33 Reference (javax.naming.Reference)27 NotContextException (javax.naming.NotContextException)24 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)23 CompositeName (javax.naming.CompositeName)22 Binding (javax.naming.Binding)21 OperationNotSupportedException (javax.naming.OperationNotSupportedException)21 CompoundName (javax.naming.CompoundName)16 NamingContext (org.eclipse.jetty.jndi.NamingContext)12 IOException (java.io.IOException)11 InvalidNameException (javax.naming.InvalidNameException)7 ContainerSystem (org.apache.openejb.spi.ContainerSystem)7 ArrayList (java.util.ArrayList)6 LinkRef (javax.naming.LinkRef)6 Properties (java.util.Properties)5