}
catch ( Exception e )
{
// Unable to connect to server
// We create a new ErrorResponse and return the XML response.
ErrorResponse errorResponse = new ErrorResponse( 0, ErrorResponseType.COULD_NOT_CONNECT, e.getMessage() );
batchResponse.addResponse( errorResponse );
return batchResponse.toDsml();
}
// Processing BatchRequest:
// - Parsing and Getting BatchRequest
// - Getting and registering options from BatchRequest
try
{
processBatchRequest();
}
catch ( XmlPullParserException e )
{
// We create a new ErrorResponse and return the XML response.
ErrorResponse errorResponse = new ErrorResponse( 0, ErrorResponseType.MALFORMED_REQUEST, e.getMessage()
+ " - Line " + e.getLineNumber() + " - Column " + e.getColumnNumber() );
batchResponse.addResponse( errorResponse );
return batchResponse.toDsml();
}
// Processing each request:
// - Getting a new request
// - Checking if the request is well formed
// - Sending the request to the server
// - Getting and converting reponse(s) as XML
// - Looping until last request
LdapMessage request = null;
try
{
request = parser.getNextRequest();
}
catch ( XmlPullParserException e )
{
// We create a new ErrorResponse and return the XML response.
ErrorResponse errorResponse = new ErrorResponse( 0, ErrorResponseType.MALFORMED_REQUEST, e.getMessage()
+ " - Line " + e.getLineNumber() + " - Column " + e.getColumnNumber() );
batchResponse.addResponse( errorResponse );
return batchResponse.toDsml();
}
while ( request != null ) // (Request == null when there's no more request to process)
{
// Checking the request has a requestID attribute if Processing = Parallel and ResponseOrder = Unordered
if ( ( batchRequest.getProcessing().equals( Processing.PARALLEL ) )
&& ( batchRequest.getResponseOrder().equals( ResponseOrder.UNORDERED ) )
&& ( request.getMessageId() == 0 ) )
{
// Then we have to send an errorResponse
ErrorResponse errorResponse = new ErrorResponse( 0, ErrorResponseType.MALFORMED_REQUEST,
"A requestID must be specified to each request when Processing is Parallel and ReponseOrder is Unordered." );
batchResponse.addResponse( errorResponse );
return batchResponse.toDsml();
}
try
{
processRequest( request );
}
catch ( Exception e )
{
// We create a new ErrorResponse and return the XML response.
ErrorResponse errorResponse = new ErrorResponse( 0, ErrorResponseType.GATEWAY_INTERNAL_ERROR,
"Internal Error: " + e.getMessage() );
batchResponse.addResponse( errorResponse );
return batchResponse.toDsml();
}
// Checking if we need to exit processing (if an error has ocurred if onError == Exit)
if ( exit )
{
break;
}
// Getting next request
try
{
request = parser.getNextRequest();
}
catch ( XmlPullParserException e )
{
// We create a new ErrorResponse and return the XML response.
ErrorResponse errorResponse = new ErrorResponse( 0, ErrorResponseType.MALFORMED_REQUEST, e.getMessage()
+ " - Line " + e.getLineNumber() + " - Column " + e.getColumnNumber() );
batchResponse.addResponse( errorResponse );
return batchResponse.toDsml();
}
}