public void deserialize(
     PropertyContext propertyContext,
     ConnectionResult connectionResult,
     XFormsModelSubmission.SubmissionParameters p,
     XFormsModelSubmission.SecondPassParameters p2)
     throws Exception {
   // Deserialize here so it can run in parallel
   if (XMLUtils.isXMLMediatype(connectionResult.getResponseMediaType())) {
     // XML media type
     final IndentedLogger detailsLogger = getDetailsLogger(p, p2);
     resultingDocument =
         deserializeInstance(
             propertyContext, detailsLogger, p2.isReadonly, p2.isHandleXInclude, connectionResult);
   } else {
     // Other media type is not allowed
     throw new XFormsSubmissionException(
         submission,
         "Body received with non-XML media type for replace=\"instance\": "
             + connectionResult.getResponseMediaType(),
         "processing instance replacement",
         new XFormsSubmitErrorEvent(
             containingDocument,
             propertyContext,
             submission,
             XFormsSubmitErrorEvent.ErrorType.RESOURCE_ERROR,
             connectionResult));
   }
 }
示例#2
0
  public void deserialize(
      ConnectionResult connectionResult,
      XFormsModelSubmission.SubmissionParameters p,
      XFormsModelSubmission.SecondPassParameters p2)
      throws IOException {
    responseBody = connectionResult.getTextResponseBody();
    if (responseBody == null) {
      // This is a binary result

      // Don't store anything for now as per the spec, but we could do something better by going
      // beyond the spec
      // NetUtils.inputStreamToAnyURI(pipelineContext, connectionResult.resultInputStream,
      // NetUtils.SESSION_SCOPE);

      // XForms 1.1: "For a success response including a body that is both a non-XML media type
      // (i.e. with a
      // content type not matching any of the specifiers in [RFC 3023]) and a non-text type (i.e.
      // with a content
      // type not matching text/*), when the value of the replace attribute on element submission is
      // "text",
      // nothing in the document is replaced and submission processing concludes after dispatching
      // xforms-submit-error with appropriate context information, including an error-type of
      // resource-error."
      throw new XFormsSubmissionException(
          submission,
          "Mediatype is neither text nor XML for replace=\"text\": "
              + connectionResult.getResponseMediaType(),
          "reading response body",
          new XFormsSubmitErrorEvent(
              containingDocument,
              submission,
              XFormsSubmitErrorEvent.ErrorType.RESOURCE_ERROR,
              connectionResult));
    }
  }
  private Object deserializeInstance(
      IndentedLogger indentedLogger,
      boolean isReadonly,
      boolean isHandleXInclude,
      ConnectionResult connectionResult)
      throws Exception {
    final Object resultingDocument;

    // Create resulting instance whether entire instance is replaced or not, because this:
    // 1. Wraps a Document within a DocumentInfo if needed
    // 2. Performs text nodes adjustments if needed
    try {
      if (!isReadonly) {
        // Resulting instance must not be read-only

        // TODO: What about configuring validation? And what default to choose?
        resultingDocument =
            TransformerUtils.readDom4j(
                connectionResult.getResponseInputStream(),
                connectionResult.resourceURI,
                isHandleXInclude,
                true);

        if (indentedLogger.isDebugEnabled())
          indentedLogger.logDebug("", "deserializing to mutable instance");
      } else {
        // Resulting instance must be read-only

        // TODO: What about configuring validation? And what default to choose?
        // NOTE: isApplicationSharedHint is always false when get get here.
        // isApplicationSharedHint="true" is handled above.
        resultingDocument =
            TransformerUtils.readTinyTree(
                XPathCache.getGlobalConfiguration(),
                connectionResult.getResponseInputStream(),
                connectionResult.resourceURI,
                isHandleXInclude,
                true);

        if (indentedLogger.isDebugEnabled())
          indentedLogger.logDebug("", "deserializing to read-only instance");
      }
    } catch (Exception e) {
      throw new XFormsSubmissionException(
          submission,
          e,
          "xforms:submission: exception while reading XML response.",
          "processing instance replacement",
          new XFormsSubmitErrorEvent(
              containingDocument,
              submission,
              XFormsSubmitErrorEvent.ErrorType.PARSE_ERROR,
              connectionResult));
    }

    return resultingDocument;
  }
 private ConnectionResult createPseudoConnectionResult(String resourceURI) {
   final ConnectionResult connectionResult =
       new ConnectionResult(resourceURI) {
         @Override
         public boolean hasContent() {
           return true;
         }
       };
   connectionResult.statusCode = 200;
   connectionResult.responseHeaders = ConnectionResult.EMPTY_HEADERS_MAP;
   connectionResult.setLastModified(null);
   connectionResult.setResponseContentType(XMLUtils.XML_CONTENT_TYPE);
   connectionResult.dontHandleResponse = false;
   try {
     connectionResult.setResponseInputStream(new ByteArrayInputStream(new byte[] {}));
   } catch (IOException e) {
     // Should not happen
     throw new OXFException(e);
   }
   return connectionResult;
 }