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

Context Path issue when running application in a servlet container #52

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
</contributors>
<properties>
<jettyVersion>9.4.9.v20180320</jettyVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -141,6 +142,12 @@
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.23.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand All @@ -159,6 +166,7 @@
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
<attachClasses>true</attachClasses>
<packagingExcludes>WEB-INF/lib/jetty*.jar</packagingExcludes>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,133 +9,132 @@
*
* @author <a href="http://olafhartig.de">Olaf Hartig</a>
*/
abstract public class FragmentRequestParserBase implements IFragmentRequestParser
{
@Override
final public ILinkedDataFragmentRequest parseIntoFragmentRequest(
final HttpServletRequest httpRequest,
final ConfigReader config )
throws IllegalArgumentException
{
return getWorker( httpRequest, config ).createFragmentRequest();
}

/**
abstract public class FragmentRequestParserBase implements
IFragmentRequestParser {
@Override
final public ILinkedDataFragmentRequest parseIntoFragmentRequest(
final HttpServletRequest httpRequest, final ConfigReader config)
throws IllegalArgumentException {
return getWorker(httpRequest, config).createFragmentRequest();
}

/**
*
* @param httpRequest
* @param config
* @return
* @throws IllegalArgumentException
*/
abstract protected Worker getWorker(final HttpServletRequest httpRequest,
final ConfigReader config) throws IllegalArgumentException;

/**
*
* @param httpRequest
* @param config
* @return
* @throws IllegalArgumentException
*/
abstract protected Worker getWorker( final HttpServletRequest httpRequest,
final ConfigReader config )
throws IllegalArgumentException;
abstract static protected class Worker {

/**
*
*/
abstract static protected class Worker
{

/**
*
*/
public final HttpServletRequest request;

/**
/**
*
*/
public final ConfigReader config;
public final HttpServletRequest request;

/**
/**
*
*/
public final boolean pageNumberWasRequested;
public final ConfigReader config;

/**
*
*/
public final long pageNumber;

/**
*
* @param request
* @param config
*/
public Worker( final HttpServletRequest request,
final ConfigReader config )
{
this.request = request;
this.config = config;

final String givenPageNumber = request.getParameter(
ILinkedDataFragmentRequest.PARAMETERNAME_PAGE );
if ( givenPageNumber != null ) {
long pageNumber;
try {
pageNumber = Long.parseLong( givenPageNumber );
} catch (NumberFormatException ex) {
pageNumber = 1L;
}
this.pageNumber = ( pageNumber > 0 ) ? pageNumber : 1L;
this.pageNumberWasRequested = true;
}
else {
this.pageNumber = 1L;
this.pageNumberWasRequested = false;
}
}

/**
/**
*
* @return
* @throws IllegalArgumentException
*/
abstract public ILinkedDataFragmentRequest createFragmentRequest()
throws IllegalArgumentException;
public final boolean pageNumberWasRequested;

/**
/**
*
* @return
*/
public String getFragmentURL() {
final String datasetURL = getDatasetURL();
final String query = request.getQueryString();
return query == null ? datasetURL : (datasetURL + "?" + query);
}

/**
*
* @return
*/
public String getDatasetURL() {
return extractBaseURL( request, config ) + request.getRequestURI();
}

} // end of class Worker


// ----- HELPERS ---------

/**
*
* @param request
* @param config
* @return
*/

public static String extractBaseURL( final HttpServletRequest request,
final ConfigReader config ) {
if (config.getBaseURL() != null) {
return config.getBaseURL();
} else if ((request.getServerPort() == 80)
|| (request.getServerPort() == 443)) {
return request.getScheme() + "://"
+ request.getServerName();
} else {
return request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort();
}
}
public final long pageNumber;

/**
*
* @param request
* @param config
*/
public Worker(final HttpServletRequest request,
final ConfigReader config) {
this.request = request;
this.config = config;

final String givenPageNumber = request
.getParameter(ILinkedDataFragmentRequest.PARAMETERNAME_PAGE);
if (givenPageNumber != null) {
long pageNumber;
try {
pageNumber = Long.parseLong(givenPageNumber);
} catch (final NumberFormatException ex) {
pageNumber = 1L;
}
this.pageNumber = (pageNumber > 0) ? pageNumber : 1L;
this.pageNumberWasRequested = true;
} else {
this.pageNumber = 1L;
this.pageNumberWasRequested = false;
}
}

/**
*
* @return
* @throws IllegalArgumentException
*/
abstract public ILinkedDataFragmentRequest createFragmentRequest()
throws IllegalArgumentException;

/**
*
* @return
*/
public String getFragmentURL() {
final String datasetURL = getDatasetURL();
final String query = this.request.getQueryString();
return query == null ? datasetURL : (datasetURL + "?" + query);
}

/**
* Returns the dataset URL
*
* @return the dataset URL. This consists of the base URL of the
* application, the servlet path and the pathinfo as supplied by
* request.getPathInfo()
*/
public String getDatasetURL() {
return extractBaseURL(this.request, this.config)
+ this.request.getServletPath()
+ this.request.getPathInfo();
}

} // end of class Worker

// ----- HELPERS ---------

/**
*
* @param request
* @param config
* @return
*/

public static String extractBaseURL(final HttpServletRequest request,
final ConfigReader config) {
final String contextPath = request.getServletContext().getContextPath();
if (config.getBaseURL() != null) {
return config.getBaseURL();
} else if ((request.getServerPort() == 80)
|| (request.getServerPort() == 443)) {
return request.getScheme() + "://" + request.getServerName()
+ contextPath;
} else {
return request.getScheme() + "://" + request.getServerName() + ":"
+ request.getServerPort() + contextPath;
}
}

}
Loading