Exemplo n.º 1
0
  public void service(IEngineServiceView engine, IRequestCycle cycle, ResponseOutputStream output)
      throws IOException {
    System.out.println(
        "===============================================================================================");
    RequestContext context = cycle.getRequestContext();
    String[] contextParams = getServiceContext(context);
    if (contextParams.length != 3)
      throw new ApplicationRuntimeException(
          "Incorrect number of service parameters for service "
              + getName()
              + ". Expected 2, but got "
              + contextParams.length);

    String componentPageName = contextParams[1];
    String componentId = contextParams[2];

    IPage componentPage = cycle.getPage(componentPageName);
    IComponent component = componentPage.getNestedComponent(componentId);

    if (!(component instanceof IXMLService))
      throw new ApplicationRuntimeException(
          "Incorrect component type: was "
              + component.getClass()
              + " but must be "
              + IXMLService.class,
          component,
          null,
          null);

    IXMLService xservice = (IXMLService) component;

    // do not squeeze on input
    String[] params = context.getParameters(Tapestry.PARAMETERS_QUERY_PARAMETER_NAME);
    cycle.setServiceParameters(params);
    xservice.trigger(cycle);

    // do not squeeze on output either
    Object[] args = cycle.getServiceParameters();
    String strArgs = generateOutputString(args);

    output.setContentType("text/xml");
    output.write(strArgs.getBytes("utf-8"));
  }