Search in sources :

Example 1 with JNDIRequest

use of org.apache.openejb.client.JNDIRequest in project tomee by apache.

the class JndiRequestHandler method processResponse.

@Override
public void processResponse(final Response response, final ObjectOutputStream out, final ProtocolMetaData metaData) throws Exception {
    if (JNDIResponse.class.isInstance(response)) {
        final JNDIResponse res = (JNDIResponse) response;
        final JNDIRequest req = res.getRequest();
        try {
            // Only process if 'processRequest' was ok...
            final Object result = res.getResult();
            if (null == result || !ThrowableArtifact.class.isInstance(result)) {
                if (req.getRequestString().startsWith("/")) {
                    req.setRequestString(req.getRequestString().substring(1));
                }
                final String prefix = getPrefix(req);
                switch(req.getRequestMethod()) {
                    case JNDI_LOOKUP:
                        doLookup(req, res, prefix);
                        break;
                    case JNDI_LIST:
                        doList(req, res, prefix);
                        break;
                }
            }
        } catch (Throwable e) {
            res.setResponseCode(ResponseCodes.JNDI_NAMING_EXCEPTION);
            final NamingException namingException = new NamingException("Unknown error in container");
            namingException.setRootCause(e);
            res.setResult(new ThrowableArtifact(namingException));
        } finally {
            try {
                res.setMetaData(metaData);
                res.writeExternal(out);
            } catch (Throwable e) {
                logger.fatal("Could not write JndiResponse to output stream", e);
            }
            if (logger.isDebugEnabled()) {
                try {
                    // force it to as correct as possible response size
                    out.flush();
                    logRequestResponse(req, res);
                } catch (Exception ignore) {
                // no-op
                }
            }
        }
    } else {
        logger.error("JndiRequestHandler cannot process an instance of: " + response.getClass().getName());
    }
}
Also used : JNDIRequest(org.apache.openejb.client.JNDIRequest) JNDIResponse(org.apache.openejb.client.JNDIResponse) ThrowableArtifact(org.apache.openejb.client.ThrowableArtifact) NamingException(javax.naming.NamingException) NamingException(javax.naming.NamingException) NameNotFoundException(javax.naming.NameNotFoundException)

Example 2 with JNDIRequest

use of org.apache.openejb.client.JNDIRequest in project tomee by apache.

the class JndiRequestHandler method processRequest.

@Override
public Response processRequest(final ObjectInputStream in, final ProtocolMetaData metaData) {
    final JNDIRequest req = new JNDIRequest();
    final JNDIResponse res = new JNDIResponse();
    res.setRequest(req);
    try {
        req.setMetaData(metaData);
        req.readExternal(in);
    } catch (Throwable e) {
        res.setResponseCode(ResponseCodes.JNDI_NAMING_EXCEPTION);
        final NamingException namingException = new NamingException("Could not read jndi request");
        namingException.setRootCause(e);
        res.setResult(new ThrowableArtifact(namingException));
        if (logger.isDebugEnabled()) {
            try {
                logRequestResponse(req, res);
            } catch (Exception ignore) {
            // no-op
            }
        }
    }
    return res;
}
Also used : JNDIRequest(org.apache.openejb.client.JNDIRequest) JNDIResponse(org.apache.openejb.client.JNDIResponse) ThrowableArtifact(org.apache.openejb.client.ThrowableArtifact) NamingException(javax.naming.NamingException) NamingException(javax.naming.NamingException) NameNotFoundException(javax.naming.NameNotFoundException)

Aggregations

NameNotFoundException (javax.naming.NameNotFoundException)2 NamingException (javax.naming.NamingException)2 JNDIRequest (org.apache.openejb.client.JNDIRequest)2 JNDIResponse (org.apache.openejb.client.JNDIResponse)2 ThrowableArtifact (org.apache.openejb.client.ThrowableArtifact)2