Search in sources :

Example 1 with ExtendedRequest

use of javax.naming.ldap.ExtendedRequest in project ldapchai by ldapchai.

the class ApacheLdapProviderImpl method extendedOperation.

public ExtendedResponse extendedOperation(final ExtendedRequest request) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
    final org.apache.directory.api.ldap.model.message.ExtendedRequest apacheRequest = new org.apache.directory.api.ldap.model.message.ExtendedRequest() {

        public String getRequestName() {
            return request.getID();
        }

        public org.apache.directory.api.ldap.model.message.ExtendedRequest setRequestName(final String oid) {
            return this;
        }

        public org.apache.directory.api.ldap.model.message.ExtendedRequest setMessageId(final int messageId) {
            return this;
        }

        public org.apache.directory.api.ldap.model.message.ExtendedRequest addControl(final Control control) {
            return null;
        }

        public org.apache.directory.api.ldap.model.message.ExtendedRequest addAllControls(final Control[] controls) {
            return null;
        }

        public org.apache.directory.api.ldap.model.message.ExtendedRequest removeControl(final Control control) {
            return null;
        }

        public MessageTypeEnum getResponseType() {
            return null;
        }

        public ResultResponse getResultResponse() {
            return null;
        }

        public boolean hasResponse() {
            return false;
        }

        public MessageTypeEnum getType() {
            return null;
        }

        public Map<String, Control> getControls() {
            return null;
        }

        public Control getControl(final String oid) {
            return null;
        }

        public boolean hasControl(final String oid) {
            return false;
        }

        public int getMessageId() {
            return 0;
        }

        public Object get(final Object key) {
            return null;
        }

        public Object put(final Object key, final Object value) {
            return null;
        }
    };
    try {
        final org.apache.directory.api.ldap.model.message.ExtendedResponse apacheResponse = connection.extended(apacheRequest);
        final ExtendedResponse extendedResponse = new ExtendedResponse() {

            public String getID() {
                return apacheResponse.getResponseName();
            }

            public byte[] getEncodedValue() {
                return null;
            }
        };
        return extendedResponse;
    } catch (LdapException e) {
        throw ChaiOperationException.forErrorMessage(e.getMessage());
    }
}
Also used : Control(org.apache.directory.api.ldap.model.message.Control) ChaiRequestControl(com.novell.ldapchai.ChaiRequestControl) ExtendedResponse(javax.naming.ldap.ExtendedResponse) ExtendedRequest(javax.naming.ldap.ExtendedRequest) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 2 with ExtendedRequest

use of javax.naming.ldap.ExtendedRequest in project aries by apache.

the class InitialContextTest method testLookFromLdapICF.

@Test
public void testLookFromLdapICF() throws Exception {
    InitialContextFactoryBuilder icf = Skeleton.newMock(InitialContextFactoryBuilder.class);
    bc.registerService(new String[] { InitialContextFactoryBuilder.class.getName(), icf.getClass().getName() }, icf, (Dictionary) new Properties());
    LdapContext backCtx = Skeleton.newMock(LdapContext.class);
    InitialContextFactory fac = Skeleton.newMock(InitialContextFactory.class);
    Skeleton.getSkeleton(fac).setReturnValue(new MethodCall(InitialContextFactory.class, "getInitialContext", Hashtable.class), backCtx);
    Skeleton.getSkeleton(icf).setReturnValue(new MethodCall(InitialContextFactoryBuilder.class, "createInitialContextFactory", Hashtable.class), fac);
    Properties props = new Properties();
    props.put(JNDIConstants.BUNDLE_CONTEXT, bc);
    props.put(Context.INITIAL_CONTEXT_FACTORY, "dummy.factory");
    InitialLdapContext ilc = new InitialLdapContext(props, new Control[0]);
    ExtendedRequest req = Skeleton.newMock(ExtendedRequest.class);
    ilc.extendedOperation(req);
    Skeleton.getSkeleton(backCtx).assertCalled(new MethodCall(LdapContext.class, "extendedOperation", req));
}
Also used : InitialContextFactoryBuilder(javax.naming.spi.InitialContextFactoryBuilder) Hashtable(java.util.Hashtable) ExtendedRequest(javax.naming.ldap.ExtendedRequest) InitialLdapContext(javax.naming.ldap.InitialLdapContext) Properties(java.util.Properties) InitialContextFactory(javax.naming.spi.InitialContextFactory) MethodCall(org.apache.aries.unittest.mocks.MethodCall) InitialLdapContext(javax.naming.ldap.InitialLdapContext) LdapContext(javax.naming.ldap.LdapContext) Test(org.junit.Test)

Example 3 with ExtendedRequest

use of javax.naming.ldap.ExtendedRequest in project directory-ldap-api by apache.

the class JavaStoredProcUtils method callStoredProcedure.

/**
 * Invoke a Stored Procedure
 *
 * @param ctx The execution context
 * @param procedureName The procedure to execute
 * @param arguments The procedure's arguments
 * @return The execution resut
 * @throws NamingException If we have had an error whil executing the stored procedure
 */
public static Object callStoredProcedure(LdapContext ctx, String procedureName, Object[] arguments) throws NamingException {
    String language = "Java";
    Object responseObject;
    try {
        /**
         * Create a new stored procedure execution request.
         */
        StoredProcedureRequestImpl req = new StoredProcedureRequestImpl(0, procedureName, language);
        /**
         * For each argument UTF-8-encode the type name
         * and Java-serialize the value
         * and add them to the request as a parameter object.
         */
        for (int i = 0; i < arguments.length; i++) {
            byte[] type;
            byte[] value;
            type = arguments[i].getClass().getName().getBytes("UTF-8");
            value = SerializationUtils.serialize((Serializable) arguments[i]);
            req.addParameter(type, value);
        }
        /**
         * Call the stored procedure via the extended operation
         * and get back its return value.
         */
        ExtendedRequest jndiReq = LdapApiServiceFactory.getSingleton().toJndi(req);
        ExtendedResponse resp = ctx.extendedOperation(jndiReq);
        /**
         * Restore a Java object from the return value.
         */
        byte[] responseStream = resp.getEncodedValue();
        responseObject = SerializationUtils.deserialize(responseStream);
    } catch (Exception e) {
        NamingException ne = new NamingException();
        ne.setRootCause(e);
        throw ne;
    }
    return responseObject;
}
Also used : Serializable(java.io.Serializable) ExtendedResponse(javax.naming.ldap.ExtendedResponse) ExtendedRequest(javax.naming.ldap.ExtendedRequest) NamingException(javax.naming.NamingException) StoredProcedureRequestImpl(org.apache.directory.api.ldap.extras.extended.storedProcedure.StoredProcedureRequestImpl) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) NamingException(javax.naming.NamingException)

Aggregations

ExtendedRequest (javax.naming.ldap.ExtendedRequest)3 ExtendedResponse (javax.naming.ldap.ExtendedResponse)2 ChaiRequestControl (com.novell.ldapchai.ChaiRequestControl)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 URISyntaxException (java.net.URISyntaxException)1 Hashtable (java.util.Hashtable)1 Properties (java.util.Properties)1 NamingException (javax.naming.NamingException)1 InitialLdapContext (javax.naming.ldap.InitialLdapContext)1 LdapContext (javax.naming.ldap.LdapContext)1 InitialContextFactory (javax.naming.spi.InitialContextFactory)1 InitialContextFactoryBuilder (javax.naming.spi.InitialContextFactoryBuilder)1 MethodCall (org.apache.aries.unittest.mocks.MethodCall)1 StoredProcedureRequestImpl (org.apache.directory.api.ldap.extras.extended.storedProcedure.StoredProcedureRequestImpl)1 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)1 Control (org.apache.directory.api.ldap.model.message.Control)1 Test (org.junit.Test)1