JBoss Wildfly with Jersey Web Services Deployment Error JBAS011859: Naming context is read-only
Asked Answered
A

3

3

Im working on a Java Webservices Project Using the Jersey Servlet (1.18.1). When deploying my EAR file to Jboss WildFly (8.1.0) I'm Getting the following Error and im unsure why its breaking as this same EAR file deployed and worked 100% in JBoss7 (7.1.1).
The Error stacktrace:

java.lang.UnsupportedOperationException: JBAS011859: Naming context is read-only
at org.jboss.as.naming.WritableServiceBasedNamingStore.requireOwner(WritableServiceBasedNamingStore.java:126)
at org.jboss.as.naming.WritableServiceBasedNamingStore.createSubcontext(WritableServiceBasedNamingStore.java:116)
at org.jboss.as.naming.NamingContext.createSubcontext(NamingContext.java:338)
at org.jboss.as.naming.InitialContext.createSubcontext(InitialContext.java:229)
at org.jboss.as.naming.NamingContext.createSubcontext(NamingContext.java:346)
at javax.naming.InitialContext.createSubcontext(InitialContext.java:464)
at com.sun.jersey.server.impl.cdi.CDIExtension$1.stepInto(CDIExtension.java:280)
Angelangela answered 31/10, 2014 at 13:30 Comment(0)
A
8

After Doing some research in JBoss Dev Forums i came across the answer. This is caused by a bug with Jersey which doesn't allow add JNDI entries into the JVM.

To fix it add the following to the standalone.bat:

set "JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true"

or properties file:

com.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true
Angelangela answered 31/10, 2014 at 13:37 Comment(4)
Thanks to the Jboss Dev Thread: developer.jboss.org/message/817632#817632Angelangela
How did u fix this? I added the setting to my Wildfly standalone.conf.bat but it didn't fix the issue, unfortunately. Could you add some details about your solution? ThxSopher
Similar question: #16030473Sopher
You must add it to your standalone.bat not the standalone.conf.batAngelangela
S
0

I am able to manage this. Add a patch in naming jar. Just change org.jboss.as.naming.service.NamingStoreService -> readOnly = true

Full java class -

public class NamingStoreService implements Service {

private final boolean readOnly = false;
private volatile ServiceBasedNamingStore store;

public NamingStoreService() {
    this(false);
    System.out.println("Setting readOnly "+readOnly);
}

public NamingStoreService(boolean readOnly) {
    System.out.println("Setting readOnly "+readOnly);
}

/**
 * Creates the naming store if not provided by the constructor.
 *
 * @param context The start context
 * @throws StartException If any problems occur creating the context
 */
public void start(final StartContext context) throws StartException {
    if(store == null) {
        final ServiceRegistry serviceRegistry = context.getController().getServiceContainer();
        final ServiceName serviceNameBase = context.getController().getName();
        final ServiceTarget serviceTarget = context.getChildTarget();
        store = readOnly ? new ServiceBasedNamingStore(serviceRegistry, serviceNameBase) : new WritableServiceBasedNamingStore(serviceRegistry, serviceNameBase, serviceTarget);
    }
}

/**
 * Destroys the naming store.
 *
 * @param context The stop context
 */
public void stop(StopContext context) {
    if(store != null) {
        try {
            store.close();
            store = null;
        } catch (NamingException e) {
            throw MESSAGES.failedToDestroyRootContext(e);
        }
    }
}

/**
 * Get the context value.
 *
 * @return The naming store
 * @throws IllegalStateException
 */
public ServiceBasedNamingStore getValue() throws IllegalStateException {
    return store;
}
}
Smirk answered 30/4, 2015 at 15:24 Comment(0)
M
0

If you are using Mac, add the below line to your standalone.conf file in Jboss_home/bin directory

JAVA_OPTS="$JAVA_OPTS -Dcom.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true"
Merrile answered 23/4, 2019 at 12:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.