Java Code Examples for org.apache.wicket.request.Url#parse()

The following examples show how to use org.apache.wicket.request.Url#parse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoginPage.java    From webanno with Apache License 2.0 6 votes vote down vote up
private void setDefaultResponsePageIfNecessary()
{
    // This does not work because it was Spring Security that intercepted the access, not
    // Wicket continueToOriginalDestination();

    String redirectUrl = getRedirectUrl();
    
    if (redirectUrl == null || redirectUrl.contains(".IBehaviorListener.")
            || redirectUrl.contains("-logoutPanel-")) {
        log.debug("Redirecting to welcome page");
        setResponsePage(getApplication().getHomePage());
    }
    else {
        log.debug("Redirecting to saved URL: [{}]", redirectUrl);
        if (isNotBlank(form.urlfragment) && form.urlfragment.startsWith("!")) {
            Url url = Url.parse("http://dummy?" + form.urlfragment.substring(1));
            UrlRequestParametersAdapter adapter = new UrlRequestParametersAdapter(url);
            LinkedHashMap<String, StringValue> params = new LinkedHashMap<>();
            for (String name : adapter.getParameterNames()) {
                params.put(name, adapter.getParameterValue(name));
            }
            Session.get().setMetaData(SessionMetaData.LOGIN_URL_FRAGMENT_PARAMS, params);
        }
        throw new NonResettingRestartException(redirectUrl);
    }
}
 
Example 2
Source File: ServletWebResponse.java    From onedev with MIT License 5 votes vote down vote up
@Override
public String encodeURL(CharSequence url)
{
	Args.notNull(url, "url");

	UrlRenderer urlRenderer = getUrlRenderer();

	Url originalUrl = Url.parse(url);

	/*
	  WICKET-4645 - always pass absolute url to the web container for encoding
	  because when REDIRECT_TO_BUFFER is in use Wicket may render PageB when
	  PageA is actually the requested one and the web container cannot resolve
	  the base url properly
	 */
	String fullUrl = urlRenderer.renderFullUrl(originalUrl);
	String encodedFullUrl = httpServletResponse.encodeURL(fullUrl);

	final String encodedUrl;
	if (originalUrl.isFull())
	{
		encodedUrl = encodedFullUrl;
	}
	else
	{
		if (fullUrl.equals(encodedFullUrl))
		{
			// no encoding happened so just reuse the original url
			encodedUrl = url.toString();
		}
		else
		{
			// get the relative url with the jsessionid encoded in it
			Url _encoded = Url.parse(encodedFullUrl);
			encodedUrl = urlRenderer.renderRelativeUrl(_encoded);
		}
	}
	return encodedUrl;
}
 
Example 3
Source File: ServletWebResponse.java    From onedev with MIT License 5 votes vote down vote up
@Override
public String encodeRedirectURL(CharSequence url)
{
	Args.notNull(url, "url");

	UrlRenderer urlRenderer = getUrlRenderer();

	Url originalUrl = Url.parse(url);

	/*
	 * WICKET-4645 - always pass absolute url to the web container for encoding because when
	 * REDIRECT_TO_BUFFER is in use Wicket may render PageB when PageA is actually the requested
	 * one and the web container cannot resolve the base url properly
	 */
	String fullUrl = urlRenderer.renderFullUrl(originalUrl);
	String encodedFullUrl = httpServletResponse.encodeRedirectURL(fullUrl);

	final String encodedUrl;
	if (originalUrl.isFull())
	{
		encodedUrl = encodedFullUrl;
	}
	else
	{
		if (fullUrl.equals(encodedFullUrl))
		{
			// no encoding happened so just reuse the original url
			encodedUrl = url.toString();
		}
		else
		{
			// get the relative url with the jsessionid encoded in it
			Url _encoded = Url.parse(encodedFullUrl);
			encodedUrl = urlRenderer.renderRelativeUrl(_encoded);
		}
	}
	return encodedUrl;
}
 
Example 4
Source File: TestPatcher.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
	for (DbType dbType : DbType.values()) {
		ConnectionProperties props = ConnectionPropertiesPatcher.patch(dbType, HOST, PORT, DB, USER, PASS);
		assertEquals(dbType, props.getDbType(), "DB type should match");
		if (DbType.MYSQL == dbType) {
			Url url = Url.parse(props.getURL());
			PageParameters pp = new PageParametersEncoder().decodePageParameters(url);
			StringValue tz = pp.get("serverTimezone");
			assertEquals(TimeZone.getDefault().getID(), tz.toString(), "serverTimezone parameter is mandatory for MySql");
		}
	}
}
 
Example 5
Source File: MysqlPatcher.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
@Override
protected String getUrl(String inUrl, String host, String inPort, String inDb) {
	Url url = Url.parse(inUrl);
	url.setHost(host);
	url.setPort((inPort == null) ? 3306 : Integer.valueOf(inPort));
	url.getSegments().set(1, (inDb == null) ? DEFAULT_DB_NAME : inDb);
	PageParameters pp = new PageParametersEncoder().decodePageParameters(url);
	StringValue tz = pp.get(TZ_PARAM);
	if (tz.isEmpty()) {
		url.setQueryParameter(TZ_PARAM, TimeZone.getDefault().getID());
	}
	return url.toString(Url.StringMode.FULL);
}
 
Example 6
Source File: OLoggerEventDispatcher.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(IOLoggerConfiguration configuration) {
	super.configure(configuration);
	if(!Strings.isEmpty(collectorUrl)) {
		Url url = Url.parse(collectorUrl);
		if(Strings.isEmpty(url.getPath())) {
			collectorUrl = collectorUrl+(collectorUrl.endsWith("/")?"":"/")+"resource/ologger";
		}
	}
}
 
Example 7
Source File: AbstractWebSocketProcessor.java    From onedev with MIT License 4 votes vote down vote up
/**
 * Constructor.
 *
 * @param request
 *      the http request that was used to create the TomcatWebSocketProcessor
 * @param application
 *      the current Wicket Application
 */
public AbstractWebSocketProcessor(final HttpServletRequest request, final WebApplication application)
{
	final HttpSession httpSession = request.getSession(true);
	if (httpSession == null)
	{
		throw new IllegalStateException("There is no HTTP Session bound. Without a session Wicket won't be " +
				"able to find the stored page to update its components");
	}
	this.sessionId = httpSession.getId();

	String pageId = request.getParameter("pageId");
	resourceName = request.getParameter("resourceName");
	if (Strings.isEmpty(pageId) && Strings.isEmpty(resourceName))
	{
		throw new IllegalArgumentException("The request should have either 'pageId' or 'resourceName' parameter!");
	}
	if (Strings.isEmpty(pageId) == false)
	{
		this.pageId = Integer.parseInt(pageId, 10);
	}
	else
	{
		this.pageId = NO_PAGE_ID;
	}

	String baseUrl = request.getParameter(WebRequest.PARAM_AJAX_BASE_URL);
	Checks.notNull(baseUrl, String.format("Request parameter '%s' is required!", WebRequest.PARAM_AJAX_BASE_URL));
	this.baseUrl = Url.parse(baseUrl);

	WicketFilter wicketFilter = application.getWicketFilter();
	this.servletRequest = new ServletRequestCopy(request);

	this.application = Args.notNull(application, "application");

	this.webSocketSettings = WebSocketSettings.Holder.get(application);

	this.webRequest = webSocketSettings.newWebSocketRequest(request, wicketFilter.getFilterPath());

	this.connectionRegistry = webSocketSettings.getConnectionRegistry();

	this.connectionFilter = webSocketSettings.getConnectionFilter();
}
 
Example 8
Source File: WicketOrientDbTester.java    From wicket-orientdb with Apache License 2.0 4 votes vote down vote up
public String executeUrl(String _url, final String method, final String content, String username, String password) throws Exception
{
	MockHttpServletRequest request = new MockHttpServletRequest(getApplication(), getHttpSession(), getServletContext())
	{
		{
			setMethod(method);
		}

		@Override
		public ServletInputStream getInputStream() throws IOException {
			if(content==null) return super.getInputStream();
			else
			{
				final StringReader sr = new StringReader(content);
				return new ServletInputStream() {
					@Override
					public int read() throws IOException {
						return sr.read();
					}
				};
			}
		}
	};
	
	Url url = Url.parse(_url, Charset.forName(request.getCharacterEncoding()));
	request.setUrl(url);
	request.setMethod(method);
	if(username!=null && password!=null)
	{
		request.setHeader(LazyAuthorizationRequestCycleListener.AUTHORIZATION_HEADER, "Basic "+Base64.getEncoder().encodeToString((username+":"+password).getBytes()));
	}
	if(!processRequest(request))
	{
		throw new IOException("Request was not sucessfully sent");
	}
	MockHttpServletResponse response = getLastResponse();
	int status = response.getStatus();
	if(status>=HttpServletResponse.SC_OK+100)
	{
		throw new IOException("Code: "+response.getStatus()+" Message: "+response.getErrorMessage()+" Content: "+response.getDocument());
	}
	else
	{
		return response.getDocument();
	}
}
 
Example 9
Source File: ProjectImportModelResourceReference.java    From artifact-listener with Apache License 2.0 4 votes vote down vote up
private ProjectImportModelResourceReference() {
	super(Url.parse("../../../static/console/import/project/resource/project-import-model.xls"));
}