Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JBIDE-14994 - Page differences between page displayed via LiveReload and original page sent from server #49

Merged
merged 1 commit into from
Jun 27, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/org.jboss.tools.livereload.core/lib/.gitkeeper
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Please do not remove.
2 changes: 1 addition & 1 deletion plugins/org.jboss.tools.livereload.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<fileset>
<directory>lib</directory>
<includes>
<include>**/*</include>
<include>**/*.jar</include>
</includes>
</fileset>
</filesets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class JBossLiveReloadCoreActivator extends AbstractUIPlugin {

// The plug-in ID
public static final String PLUGIN_ID = "org.jboss.tools.livereload"; //$NON-NLS-1$
public static final String PLUGIN_ID = "org.jboss.tools.livereload.core"; //$NON-NLS-1$

// The shared instance
private static JBossLiveReloadCoreActivator plugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ApplicationsProxyServlet(final String targetHost, final int targetPort) {
@Override
protected HttpURI proxyHttpURI(HttpServletRequest request, String uri) throws MalformedURLException {
try {
final URI requestURI = new URI(request.getRequestURI());
final URI requestURI = new URI(uri);
final URI originalURI = new URI(request.getScheme(), requestURI.getUserInfo(), request.getServerName(), request.getLocalPort(), requestURI.getPath(), requestURI.getQuery(), requestURI.getFragment());
final String proxiedURI = URIUtils.convert(originalURI).toHost(targetHost).toPort(targetPort);
return new HttpURI(proxiedURI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.jboss.tools.livereload.core.internal.JBossLiveReloadCoreActivator;
import org.jboss.tools.livereload.core.internal.util.Logger;
import org.jboss.tools.livereload.core.internal.util.TimeoutUtils;
import org.jboss.tools.livereload.core.internal.util.TimeoutUtils.TaskMonitor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ public void startServer() throws CoreException {
// now, let's init and start the embedded jetty server from the
// server attributes
final IServer server = getServer();
websocketPort = server.getAttribute(LiveReloadLaunchConfiguration.WEBSOCKET_PORT, -1);
// retrieve the websocket port, use the default value if it was missing
websocketPort = server.getAttribute(LiveReloadLaunchConfiguration.WEBSOCKET_PORT, LiveReloadLaunchConfiguration.DEFAULT_WEBSOCKET_PORT);

// fix the new default behaviour: proxy is now always enabled
if(!isProxyEnabled()) {
setProxyEnabled(true);
Expand Down
3 changes: 2 additions & 1 deletion tests/org.jboss.tools.livereload.test/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.wst.web,
org.slf4j.api;bundle-version="1.6.4",
ch.qos.logback.classic;bundle-version="1.0.0",
ch.qos.logback.core;bundle-version="1.0.0"
ch.qos.logback.core;bundle-version="1.0.0",
org.eclipse.jetty.servlet
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ public void shouldForwardRequestOnProxiedServerWithoutScriptInjection() throws E
assertThat(responseBody).doesNotContain("livereload.js");
}

@Test
@Test(timeout=60*10000)
public void shouldForwardRequestOnProxiedServerWithScriptInjection() throws Exception {
// pre-condition
createHttpPreviewServer();
Expand All @@ -686,6 +686,22 @@ public void shouldForwardRequestOnProxiedServerWithScriptInjection() throws Exce
assertThat(responseBody).contains("livereload.js").contains(
Integer.toString(liveReloadServerBehaviour.getLiveReloadServer().getPort()));
}

@Test
public void shouldForwardRequestWithQueryParams() throws IOException, CoreException, InterruptedException, ExecutionException, TimeoutException {
createHttpPreviewServer();
httpPreviewServer.start(ILaunchManager.RUN_MODE, new NullProgressMonitor());
createAndLaunchLiveReloadServer(true);
assertThat(liveReloadServerBehaviour.getProxyServers().keySet()).contains(httpPreviewServer);
// operation: send a request with a query param. The Preview server has a special servlet that will return a 400 error if the
// proxy did not forward the query param
int proxyPort = liveReloadServerBehaviour.getProxyServers().get(httpPreviewServer).getConnectors()[0].getPort();
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod("http://localhost:" + proxyPort + "/foo/bar?w00t=true");
int status = client.executeMethod(method);
// verification
assertThat(status).isEqualTo(200);
}

@Test
public void shouldAllowWebSocketConnectionFromProxiedLocation() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.jboss.tools.livereload.core.internal.server.jetty.JettyServerRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -49,9 +51,13 @@ public void configure(final int port, final String baseLocation) throws Exceptio
addConnector(connector);
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setResourceBase(baseLocation);

ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/foo");
context.addServlet(new ServletHolder(new QueryParamVerifierServlet()), "/bar");
LOGGER.info("serving {} on port {}", resourceHandler.getBaseResource(), port );
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { resourceHandler, new DefaultHandler() });
handlers.setHandlers(new Handler[] { resourceHandler, context, new DefaultHandler() });
setHandler(handlers);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.jboss.tools.livereload.test.previewserver;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class QueryParamVerifierServlet extends HttpServlet {

private static final long serialVersionUID = 8502427396225099738L;

/* (non-Javadoc)
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if(request.getQueryString() != null && !request.getQueryString().isEmpty()) {
response.getOutputStream().write("OK :-)".getBytes());
response.setStatus(200);
} else {
response.getOutputStream().write("Expected query params :-(".getBytes());
response.setStatus(400);
}

}

}