0

我需要在 Stream 中提供 SOAP 响应,因为肥皂响应非常大,可能会导致 Outofmemory 异常。假设我有一个由 20 个字段组成的实体,并且记录的数量约为 100 万。任何人都知道如何做到这一点..???

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 类...但不知道如何使用它。

4

0 回答 0