/*
 * #%L
 * wcm.io
 * %%
 * Copyright (C) 2016 wcm.io
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
package io.wcm.caravan.jaxws.publisher.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

/**
 * Request wrapper that maps all pathinfo to a virtual path, to whom the SOAP services are registered to.
 */
public final class RequestWrapper extends HttpServletRequestWrapper {

  /**
   * Virtual path
   */
  public static final String VIRTUAL_PATH = "/virtualpath";

  private final String virtualPath;

  /**
   * @param request Request
   */
  @SuppressWarnings("null")
  public RequestWrapper(HttpServletRequest request) {
    super(request);

    // build virtual path from fixes path prefix, and suffix from sling URL (especially for JAX-RS REST addressing)
    String suffix = null;
    /* TODO: integrate with Sling API?
    String suffix = ((SlingHttpServletRequest)pRequest).getRequestPathInfo().getSuffix();
     */
    String queryString = request.getQueryString();
    virtualPath = VIRTUAL_PATH
        + (suffix != null ? suffix : "")
        + (queryString != null ? "?" + queryString : "");
  }

  @Override
  public String getPathInfo() {
    return virtualPath;
  }

  @Override
  public String getRequestURI() {
    return virtualPath;
  }

  @Override
  public String getContextPath() {
    // simulate default root even if AEM is running at another path
    return "";
  }

}

@@ -1124,36 +1124,8 @@
  */%0A
-  @SuppressWarnings(%22null%22)%0A
   pu
@@ -1199,287 +1199,8 @@
 );%0A%0A
-    // build virtual path from fixes path prefix, and suffix from sling URL (especially for JAX-RS REST addressing)%0A    String suffix = null;%0A    /* TODO: integrate with Sling API?%0A    String suffix = ((SlingHttpServletRequest)pRequest).getRequestPathInfo().getSuffix();%0A     */%0A
     
@@ -1280,57 +1280,8 @@
 PATH
-%0A        + (suffix != null ? suffix : %22%22)%0A       
  + (
@@ -1568,11 +1568,17 @@
  if 
-AEM
+container
  is 

eliminate suffix handling