예제 #1
0
 /** @deprecated Not used anywhere */
 public void init(InputStream inputStream, String charSetEncoding, String url, String contentType)
     throws OMException {
   try {
     this.parser = StAXUtils.createXMLStreamReader(inputStream);
   } catch (XMLStreamException e1) {
     throw new OMException(e1);
   }
   omfactory = OMAbstractFactory.getOMFactory();
 }
예제 #2
0
  public XMLStreamReader getReader() throws XMLStreamException {

    try {
      String encoding = "utf-8";
      InputStream is = new ByteArrayInputStream(getXMLBytes(encoding));
      return StAXUtils.createXMLStreamReader(is, encoding);
    } catch (UnsupportedEncodingException e) {
      throw new XMLStreamException(e);
    }
  }
 /** @see javax.xml.parsers.DocumentBuilder#parse(java.io.File) */
 public Document parse(File file) throws SAXException, IOException {
   try {
     OMDOMFactory factory = new OMDOMFactory();
     XMLStreamReader reader = StAXUtils.createXMLStreamReader(new FileInputStream(file));
     StAXOMBuilder builder = new StAXOMBuilder(factory, reader);
     return (DocumentImpl) builder.getDocument();
   } catch (XMLStreamException e) {
     throw new SAXException(e);
   }
 }
 public Document parse(InputSource inputSource) throws SAXException, IOException {
   try {
     OMDOMFactory factory = new OMDOMFactory();
     // Not really sure whether this will work :-?
     XMLStreamReader reader = StAXUtils.createXMLStreamReader(inputSource.getCharacterStream());
     StAXOMBuilder builder = new StAXOMBuilder(factory, reader);
     DocumentImpl doc = (DocumentImpl) builder.getDocument();
     ((ElementImpl) doc.getDocumentElement()).build();
     return (DocumentImpl) builder.getDocument();
   } catch (XMLStreamException e) {
     throw new SAXException(e);
   }
 }
 protected Object loadDocument(InputStream in) throws Exception {
   // Jaxen's unit tests assume that whitespace in the prolog/epilog is not
   // represented in the tree (as in DOM), so we need to filter these events.
   XMLStreamReader reader = new RootWhitespaceFilter(StAXUtils.createXMLStreamReader(in));
   return new StAXOMBuilder(omMetaFactory.getOMFactory(), reader).getDocument();
 }
예제 #6
0
  /**
   * @see org.ofbiz.webapp.event.EventHandler#invoke(ConfigXMLReader.Event,
   *     ConfigXMLReader.RequestMap, javax.servlet.http.HttpServletRequest,
   *     javax.servlet.http.HttpServletResponse)
   */
  public String invoke(
      Event event, RequestMap requestMap, HttpServletRequest request, HttpServletResponse response)
      throws EventHandlerException {
    LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
    GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");

    // first check for WSDL request
    String wsdlReq = request.getParameter("wsdl");
    if (wsdlReq == null) {
      wsdlReq = request.getParameter("WSDL");
    }
    if (wsdlReq != null) {
      String serviceName = RequestHandler.getOverrideViewUri(request.getPathInfo());
      DispatchContext dctx = dispatcher.getDispatchContext();
      String locationUri = this.getLocationURI(request);

      if (serviceName != null) {
        Document wsdl = null;
        try {
          wsdl = dctx.getWSDL(serviceName, locationUri);
        } catch (GenericServiceException e) {
          serviceName = null;
        } catch (WSDLException e) {
          sendError(response, "Unable to obtain WSDL", serviceName);
          throw new EventHandlerException("Unable to obtain WSDL", e);
        }

        if (wsdl != null) {
          try {
            OutputStream os = response.getOutputStream();
            response.setContentType("text/xml");
            UtilXml.writeXmlDocument(os, wsdl);
            response.flushBuffer();
          } catch (IOException e) {
            throw new EventHandlerException(e);
          }
          return null;
        } else {
          sendError(response, "Unable to obtain WSDL", serviceName);
          throw new EventHandlerException("Unable to obtain WSDL");
        }
      }

      if (serviceName == null) {
        try {
          Writer writer = response.getWriter();
          StringBuilder sb = new StringBuilder();
          sb.append("<html><head><title>OFBiz SOAP/1.1 Services</title></head>");
          sb.append("<body>No such service.").append("<p>Services:<ul>");

          for (String scvName : dctx.getAllServiceNames()) {
            ModelService model = dctx.getModelService(scvName);
            if (model.export) {
              sb.append("<li><a href=\"")
                  .append(locationUri)
                  .append("/")
                  .append(model.name)
                  .append("?wsdl\">");
              sb.append(model.name).append("</a></li>");
            }
          }
          sb.append("</ul></p></body></html>");

          writer.write(sb.toString());
          writer.flush();
          return null;
        } catch (Exception e) {
          sendError(response, "Unable to obtain WSDL", null);
          throw new EventHandlerException("Unable to obtain WSDL");
        }
      }
    }

    // not a wsdl request; invoke the service
    response.setContentType("text/xml");

    // request envelope
    SOAPEnvelope reqEnv = null;

    // get the service name and parameters
    try {
      XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(request.getInputStream());
      StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(xmlReader);
      reqEnv = (SOAPEnvelope) builder.getDocumentElement();

      // log the request message
      if (Debug.verboseOn()) {
        try {
          Debug.logInfo("Request Message:\n" + reqEnv + "\n", module);
        } catch (Throwable t) {
        }
      }
    } catch (Exception e) {
      sendError(response, "Problem processing the service", null);
      throw new EventHandlerException("Cannot get the envelope", e);
    }

    Debug.logVerbose("[Processing]: SOAP Event", module);

    String serviceName = null;
    try {
      SOAPBody reqBody = reqEnv.getBody();
      validateSOAPBody(reqBody);
      OMElement serviceElement = reqBody.getFirstElement();
      serviceName = serviceElement.getLocalName();
      Map<String, Object> parameters =
          UtilGenerics.cast(SoapSerializer.deserialize(serviceElement.toString(), delegator));
      try {
        // verify the service is exported for remote execution and invoke it
        ModelService model = dispatcher.getDispatchContext().getModelService(serviceName);

        if (model == null) {
          sendError(response, "Problem processing the service", serviceName);
          Debug.logError("Could not find Service [" + serviceName + "].", module);
          return null;
        }

        if (!model.export) {
          sendError(response, "Problem processing the service", serviceName);
          Debug.logError(
              "Trying to call Service [" + serviceName + "] that is not exported.", module);
          return null;
        }

        Map<String, Object> serviceResults = dispatcher.runSync(serviceName, parameters);
        Debug.logVerbose("[EventHandler] : Service invoked", module);

        createAndSendSOAPResponse(serviceResults, serviceName, response);

      } catch (GenericServiceException e) {
        if (UtilProperties.getPropertyAsBoolean("service", "secureSoapAnswer", true)) {
          sendError(
              response, "Problem processing the service, check your parameters.", serviceName);
        } else {
          if (e.getMessageList() == null) {
            sendError(response, e.getMessage(), serviceName);
          } else {
            sendError(response, e.getMessageList(), serviceName);
          }
          Debug.logError(e, module);
          return null;
        }
      }
    } catch (Exception e) {
      sendError(response, e.getMessage(), serviceName);
      Debug.logError(e, module);
      return null;
    }

    return null;
  }