我有一个要求在Stream中提供SOAP响应,因为soap resoponse非常大并且可能导致Outofmemory异常。假设我有一个实体由20个字段组成,没有记录大约10万字节。任何人都知道该怎么做.. ???
public class ReportResponse{
private String name;
private String address;
private String number;
}
@WebService
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
@SchemaValidation(handler = SchemaValidationCustomErrorHandler.class)
public class MyServiceEndpoint {
@Resource
private final ReportDispatcher dispatcher;
@Resource
WebServiceContext wsContext;
@WebMethod(operationName = "GetReport")
public List<ReportResponse> getReport()
throws GenericSoapFault {
final MessageContext messageContext = this.wsContext.getMessageContext();
final SAXParseException errorException = (SAXParseException) messageContext.get(SchemaValidationCustomErrorHandler.ERROR);
final SAXParseException fatalErrorException = (SAXParseException) messageContext.get(SchemaValidationCustomErrorHandler.FATAL_ERROR);
String errorMessage = null;
if (errorException != null) {
errorMessage = errorException.getMessage();
} else if (fatalErrorException != null) {
errorMessage = fatalErrorException.getMessage();
}
if (errorMessage != null) {
if (checkIfDateRangeError(errorMessage)) {
responseBuilder.withException(new ExceptionBuilder().withInvalidDatesError().build());
return responseBuilder.build();
}
throw new GenericSoapFault(errorMessage);
}
return this.dispatcher.generateReport();
}
}
这里generateReport函数提供的结果大约有几十万。我需要使用Streeaming ...我找到了StreamingDataHandler类......但不知道如何使用它。