use of org.apache.directory.api.dsmlv2.response.SearchResponse in project directory-ldap-api by apache.
the class BatchResponseTest method testResponseWith1SearchResponse.
/**
* Test parsing of a Response with the 1 SearchResponse
*/
@Test
public void testResponseWith1SearchResponse() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(BatchResponseTest.class.getResource("response_with_1_SearchResponse.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
BatchResponseDsml batchResponse = parser.getBatchResponse();
assertEquals(1, batchResponse.getResponses().size());
DsmlDecorator<? extends Response> response = batchResponse.getCurrentResponse();
if (response.getDecorated() instanceof SearchResponse) {
assertTrue(true);
} else {
fail();
}
}
use of org.apache.directory.api.dsmlv2.response.SearchResponse in project directory-ldap-api by apache.
the class BatchResponseTest method testResponseWith2SearchResponse.
/**
* Test parsing of a Response with the 2 SearchResponse
*/
@Test
public void testResponseWith2SearchResponse() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(BatchResponseTest.class.getResource("response_with_2_SearchResponse.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
BatchResponseDsml batchResponse = parser.getBatchResponse();
assertEquals(2, batchResponse.getResponses().size());
DsmlDecorator<? extends Response> response = batchResponse.getCurrentResponse();
if (response.getDecorated() instanceof SearchResponse) {
assertTrue(true);
} else {
fail();
}
}
use of org.apache.directory.api.dsmlv2.response.SearchResponse in project directory-ldap-api by apache.
the class Dsmlv2Engine method processRequest.
/**
* Processes a single request
*
* @param request the request to process
* @param respWriter The writer used to store the DSML response
* @exception Exception If we had an error while processing the request
*/
protected void processRequest(DsmlDecorator<? extends Request> request, BufferedWriter respWriter) throws Exception {
ResultCodeEnum resultCode = null;
switch(request.getDecorated().getType()) {
case ABANDON_REQUEST:
connection.abandon((AbandonRequest) request);
return;
case ADD_REQUEST:
AddResponse response = connection.add((AddRequest) request);
resultCode = response.getLdapResult().getResultCode();
AddResponseDsml addResponseDsml = new AddResponseDsml(connection.getCodecService(), response);
writeResponse(respWriter, addResponseDsml);
break;
case BIND_REQUEST:
BindResponse bindResponse = connection.bind((BindRequest) request);
resultCode = bindResponse.getLdapResult().getResultCode();
BindResponseDsml authResponseDsml = new BindResponseDsml(connection.getCodecService(), bindResponse);
writeResponse(respWriter, authResponseDsml);
break;
case COMPARE_REQUEST:
CompareResponse compareResponse = connection.compare((CompareRequest) request);
resultCode = compareResponse.getLdapResult().getResultCode();
CompareResponseDsml compareResponseDsml = new CompareResponseDsml(connection.getCodecService(), compareResponse);
writeResponse(respWriter, compareResponseDsml);
break;
case DEL_REQUEST:
DeleteResponse delResponse = connection.delete((DeleteRequest) request);
resultCode = delResponse.getLdapResult().getResultCode();
DelResponseDsml delResponseDsml = new DelResponseDsml(connection.getCodecService(), delResponse);
writeResponse(respWriter, delResponseDsml);
break;
case EXTENDED_REQUEST:
ExtendedResponse extendedResponse = connection.extended((ExtendedRequest) request);
resultCode = extendedResponse.getLdapResult().getResultCode();
ExtendedResponseDsml extendedResponseDsml = new ExtendedResponseDsml(connection.getCodecService(), extendedResponse);
writeResponse(respWriter, extendedResponseDsml);
break;
case MODIFY_REQUEST:
ModifyResponse modifyResponse = connection.modify((ModifyRequest) request);
resultCode = modifyResponse.getLdapResult().getResultCode();
ModifyResponseDsml modifyResponseDsml = new ModifyResponseDsml(connection.getCodecService(), modifyResponse);
writeResponse(respWriter, modifyResponseDsml);
break;
case MODIFYDN_REQUEST:
ModifyDnResponse modifyDnResponse = connection.modifyDn((ModifyDnRequest) request);
resultCode = modifyDnResponse.getLdapResult().getResultCode();
ModDNResponseDsml modDNResponseDsml = new ModDNResponseDsml(connection.getCodecService(), modifyDnResponse);
writeResponse(respWriter, modDNResponseDsml);
break;
case SEARCH_REQUEST:
SearchCursor searchResponses = connection.search((SearchRequest) request);
SearchResponseDsml searchResponseDsml = new SearchResponseDsml(connection.getCodecService());
if (respWriter != null) {
StringBuilder sb = new StringBuilder();
sb.append("<searchResponse");
if (request.getDecorated().getMessageId() > 0) {
sb.append(" requestID=\"");
sb.append(request.getDecorated().getMessageId());
sb.append('"');
}
sb.append('>');
respWriter.write(sb.toString());
}
while (searchResponses.next()) {
Response searchResponse = searchResponses.get();
if (searchResponse.getType() == MessageTypeEnum.SEARCH_RESULT_ENTRY) {
SearchResultEntry searchResultEntry = (SearchResultEntry) searchResponse;
SearchResultEntryDsml searchResultEntryDsml = new SearchResultEntryDsml(connection.getCodecService(), searchResultEntry);
searchResponseDsml = new SearchResponseDsml(connection.getCodecService(), searchResultEntryDsml);
if (respWriter != null) {
writeResponse(respWriter, searchResultEntryDsml);
} else {
searchResponseDsml.addResponse(searchResultEntryDsml);
}
} else if (searchResponse.getType() == MessageTypeEnum.SEARCH_RESULT_REFERENCE) {
SearchResultReference searchResultReference = (SearchResultReference) searchResponse;
SearchResultReferenceDsml searchResultReferenceDsml = new SearchResultReferenceDsml(connection.getCodecService(), searchResultReference);
searchResponseDsml = new SearchResponseDsml(connection.getCodecService(), searchResultReferenceDsml);
if (respWriter != null) {
writeResponse(respWriter, searchResultReferenceDsml);
} else {
searchResponseDsml.addResponse(searchResultReferenceDsml);
}
}
}
SearchResultDone srDone = searchResponses.getSearchResultDone();
if (srDone != null) {
resultCode = srDone.getLdapResult().getResultCode();
SearchResultDoneDsml srdDsml = new SearchResultDoneDsml(connection.getCodecService(), srDone);
if (respWriter != null) {
writeResponse(respWriter, srdDsml);
respWriter.write("</searchResponse>");
} else {
searchResponseDsml.addResponse(srdDsml);
batchResponse.addResponse(searchResponseDsml);
}
}
break;
case UNBIND_REQUEST:
connection.unBind();
break;
default:
throw new IllegalStateException("Unexpected request tpye " + request.getDecorated().getType());
}
if ((!continueOnError) && (resultCode != null) && (resultCode != ResultCodeEnum.SUCCESS) && (resultCode != ResultCodeEnum.COMPARE_TRUE) && (resultCode != ResultCodeEnum.COMPARE_FALSE) && (resultCode != ResultCodeEnum.REFERRAL)) {
// Turning on Exit flag
exit = true;
}
}
use of org.apache.directory.api.dsmlv2.response.SearchResponse in project directory-ldap-api by apache.
the class SearchResponseTest method testResponseWithSRD.
/**
* Test parsing of a Response with a Search Result Done
*/
@Test
public void testResponseWithSRD() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(SearchResponseTest.class.getResource("response_with_1_SRD.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
SearchResponse searchResponse = (SearchResponse) parser.getBatchResponse().getCurrentResponse().getDecorated();
assertNotNull(searchResponse.getSearchResultDone());
}
use of org.apache.directory.api.dsmlv2.response.SearchResponse in project directory-ldap-api by apache.
the class SearchResponseTest method testResponseWith0SRE1SRD.
/**
* Test parsing of a Response with 1 Search Result Entry and a Search Result Done
*/
@Test
public void testResponseWith0SRE1SRD() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(SearchResponseTest.class.getResource("response_with_0_SRE_1_SRD.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
SearchResponse searchResponse = (SearchResponse) parser.getBatchResponse().getCurrentResponse().getDecorated();
assertEquals(0, searchResponse.getSearchResultEntryList().size());
assertNotNull(searchResponse.getSearchResultDone());
}
Aggregations