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());
}
}
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));
}
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;
}
Aggregations