cmailleux    2005/03/31 17:44:51 CEST

  Modified files:
    war/src/java/com/codeva/webapps/webclipping/servlet 
                                                        WebClippingServlet.java 
  Log:
  Correctly rewrite url for redirection
  
  Revision  Changes    Path
  1.7       +20 -7     
webclipping/war/src/java/com/codeva/webapps/webclipping/servlet/WebClippingServlet.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/webclipping/war/src/java/com/codeva/webapps/webclipping/servlet/WebClippingServlet.java.diff?r1=1.6&r2=1.7&f=h
  
  
  
  Index: WebClippingServlet.java
  ===================================================================
  RCS file: 
/home/cvs/repository/webclipping/war/src/java/com/codeva/webapps/webclipping/servlet/WebClippingServlet.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- WebClippingServlet.java   30 Mar 2005 14:07:20 -0000      1.6
  +++ WebClippingServlet.java   31 Mar 2005 15:44:51 -0000      1.7
  @@ -12,6 +12,7 @@
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
   import java.io.IOException;
  +import java.net.URL;
   import java.net.URLEncoder;
   import java.util.Iterator;
   import java.util.List;
  @@ -123,14 +124,12 @@
                           String string = strings[i];
                           buffer.append((i != 0) ? "," : "").append(string);
                       }
  -                    params.append(
  -                            (index == 0 ? "?" : "&") + 
entry.getKey().toString() + "=" +
  -                            URLEncoder.encode(buffer.toString(), 
characterEncoding));
  +                    params.append((index == 0 ? "?" : "&") + 
entry.getKey().toString() + "=" +
  +                                  URLEncoder.encode(buffer.toString(), 
characterEncoding));
                       index++;
                   } else {
  -                    params.append(
  -                            (index == 0 ? "?" : "&") + 
entry.getKey().toString() + "=" +
  -                            URLEncoder.encode(value.toString(), 
characterEncoding));
  +                    params.append((index == 0 ? "?" : "&") + 
entry.getKey().toString() + "=" +
  +                                  URLEncoder.encode(value.toString(), 
characterEncoding));
                       index++;
                   }
               }
  @@ -246,7 +245,21 @@
               Header locationHeader = httpMethod.getResponseHeader("location");
               if (locationHeader != null) {
                   redirectLocation = locationHeader.getValue();
  -                httpMethod.setPath(redirectLocation);
  +                if (!redirectLocation.startsWith("http")) {
  +                    URL redirectURL = new URL(url);
  +                    String tmpURL = redirectURL.getProtocol() + "://" + 
redirectURL.getHost() +
  +                                    ((redirectURL.getPort() > 0) ? ":" + 
redirectURL.getPort() : "") +
  +                                    "/" +
  +                                    redirectLocation;
  +                    httpMethod = new GetMethod(tmpURL);
  +                    // Set a default retry handler (see httpclient doc).
  +                    
httpMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
  +                                                        new 
DefaultHttpMethodRetryHandler(3, false));
  +                }
  +                int i = redirectLocation.indexOf("?");
  +                
httpMethod.setPath((redirectLocation.startsWith("/")?"":"/")+redirectLocation.substring(0,i>0?i:redirectLocation.length()));
  +                
httpMethod.setQueryString(i>0?redirectLocation.substring(i+1,redirectLocation.length()):"");
  +                httpMethod.setFollowRedirects(true);
                   getResponse(httpClient, httpMethod, httpServletResponse, 
httpServletRequest);
                   return;
               }
  

Reply via email to