use of org.apache.directory.api.ldap.extras.extended.storedProcedure.StoredProcedureRequestImpl in project directory-ldap-api by apache.
the class StandaloneLdapCodecServiceTest method testLoadingExtendedOperation.
/**
* Test an extended operation.
*/
@Test
public void testLoadingExtendedOperation() throws Exception {
LdapApiService codec = LdapApiServiceFactory.getSingleton();
StoredProcedureRequest req = new StoredProcedureRequestImpl();
req.setLanguage("Java");
req.setProcedure(Strings.getBytesUtf8("bogusProc"));
assertNotNull(req);
assertNotNull(codec);
StoredProcedureRequest decorator = (StoredProcedureRequest) codec.decorate(req);
assertNotNull(decorator);
}
use of org.apache.directory.api.ldap.extras.extended.storedProcedure.StoredProcedureRequestImpl 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;
}
Aggregations