Ejemplo n.º 1
0
  @Override
  public void objectToResponse(Object targetObject, WebResponse response, String mimeType)
      throws WicketRuntimeException {
    setCharsetResponse(response);

    String strOutput;

    if (RestMimeTypes.TEXT_PLAIN.equals(mimeType)) {
      strOutput = targetObject == null ? "" : targetObject.toString();
    } else {
      strOutput = objectSerialDeserial.serializeObject(targetObject, mimeType);
    }

    response.write(strOutput);
  }
  /**
   * Utility method to convert string values to the corresponding objects.
   *
   * @param clazz the type of the object we want to obtain.
   * @param value the string value we want to convert.
   * @return the object corresponding to the converted string value, or null if value parameter is
   *     null
   */
  public static Object toObject(Class clazz, String value) throws IllegalArgumentException {
    if (value == null) return null;
    // we use the standard Wicket conversion mechanism to obtain the
    // converted value.
    try {
      IConverter converter = Application.get().getConverterLocator().getConverter(clazz);

      return converter.convertToObject(value, Session.get().getLocale());
    } catch (Exception e) {
      WebResponse response = (WebResponse) RequestCycle.get().getResponse();

      response.setStatus(400);
      response.write(
          "Could not find a suitable constructor for value '"
              + value
              + "' of type '"
              + clazz
              + "'");

      return null;
    }
  }
Ejemplo n.º 3
0
  /**
   * @see
   *     org.apache.wicket.core.request.handler.IPageRequestHandler#respond(org.apache.wicket.request.IRequestCycle)
   */
  @Override
  public final void respond(final IRequestCycle requestCycle) {
    final RequestCycle rc = (RequestCycle) requestCycle;
    final WebResponse response = (WebResponse) requestCycle.getResponse();

    if (shouldRedirectToPage(requestCycle)) {
      // the page itself has been added to the request target, we simply issue a redirect
      // back to the page
      IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(page));
      final String url = rc.urlFor(handler).toString();
      response.sendRedirect(url);
      return;
    }

    respondersFrozen = true;

    for (ITargetRespondListener listener : respondListeners) {
      listener.onTargetRespond(this);
    }

    final Application app = page.getApplication();

    page.send(app, Broadcast.BREADTH, this);

    // Determine encoding
    final String encoding = app.getRequestCycleSettings().getResponseRequestEncoding();

    // Set content type based on markup type for page
    update.setContentType(response, encoding);

    // Make sure it is not cached by a client
    response.disableCaching();

    final StringResponse bodyResponse = new StringResponse();
    update.writeTo(bodyResponse, encoding);
    CharSequence filteredResponse = invokeResponseFilters(bodyResponse);
    response.write(filteredResponse);
  }