in my wicket application settings I wish to mount a username parameter on the root like
mountPage (Profile.class, "/${username}") similar to how twitter maps the usernames to its accounts. In wicket this seems to crash the resource location algorithm. In the sense that all css, js files now load with 404.
Is there a work around this?
The code should look like: mountPage (Profile.class, "/${username}"). Note the $ that I've added. This means the named path parameter is mandatory.
Please give more details about the problem if this doesn't solve the issue.
Thanks to martin-g. Override the MountMapper with set the url segments to 1 so it doesn't map to other resources.
public class UsernameMountUrlMapper extends MountedMapper {
public UsernameMountUrlMapper(String mountPath,
Class<? extends IRequestablePage> pageClass) {
super(mountPath, pageClass);
}
#Override
protected boolean urlStartsWithMountedSegments(Url url) {
return url.getSegments().size() == 1 && !url.getPath().equals("favicon.ico") && !url.getPath().equals("oops") && !url.getPath().equals("Index");
}
}
Related
I am trying to test a controller with this Test class,
<?php
use SilverStripe\Dev\FunctionalTest;
class SitePageControllerTest extends FunctionalTest
{
protected static $fixture_file = 'site/tests/fixturesSitePage.yml';
public function testViewSitePage()
{
$obj = $this->objFromFixture('SitePage', 'page1');
$page = $this->get('page-one/');
$this->assertEquals(200, $page->getStatusCode());
}
}
and Fixture.
SitePage:
page1:
Title: Page One
CanViewType: true
But "$this->get('page-one/');" returns a 404 page.
Pages are versioned, and this one isn't published at the point where you ask for it, so the functional test emulates a frontend web request which is served from the live (published) stage by default.
You can use the draft site by appending ?stage=Stage to your request URL, or by using protected static $use_draft_site = true in your functional test (this is deprecated in 4.2).
Note that FunctionalTest doesn't log a user in, so you may also need to log in with some level of permission i.e. $this->logInWithPermission('ADMIN')
Another option is to publish it using something like: $obj->publishRecursive(); before the get()
I have a Spring Boot application using Thymeleaf as template resolver, which works fine when debugging from NetBeans, but gives me this error running its .jar:
Error resolving template "/theme/property", template might not exist or might not be accessible by any of the configured Template Resolvers
The app is set to auto-configurer with the annotation #SpringBootApplication, at an extension of SpringBootServletInitializer. I haven't set any contextPath into the properties file. I'm using Thymeleaf 2.1.6 and Spring 4 version. The jar is generated with Maven.
Doing some research I've come out that in some controllers I was passing a double slash, which I've solved but most pages still not working.
This controller works:
#GetMapping("/{idweb}")
String frontEndHome(#PathVariable("idweb")Integer idweb, Model model){
...
return "theme/home";
With the return statement set as return "/theme/home"; doesn't work. I guess, because the template resolver is recieving a double slash (//).
This other controller raises the error:
#GetMapping("/{idweb}/property")
String frontEndProperty(#PathVariable("idweb") Integer idweb, #RequestParam(value = "idproperty", required = false) Integer idproperty, Model model) throws Exception {
...
return "theme/property";
The index controller works fine as well:
#GetMapping("/")
public String index(Model model){
...
return "index";
}
That's my application starter class:
#SpringBootApplication
public class RentalWebsApplication extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(RentalWebsApplication.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(RentalWebsApplication.class, args);
}
}
For Thymeleaf I haven't set any configuration, although I've tested the app setting this into the application.properties file, with the same result:
spring.thymeleaf.prefix=classpath:/templates/
All html files are set into:
src/main/resources/templates
The html files from the examples are in:
src/main/resources/templates/index.html
src/main/resources/templates/theme/home.html
src/main/resources/templates/theme/property.html
There are some other questions dealing with the same issue, but none has a solution that works for me. Any help, would be much appreciated.
Update
Deploying the jar into Pivotal Web Services, the whole website works fine, but not deploying it with Boxfuse, Heroku or running the jar locally. Therefore, I guess the origin of the problem is some wrong configuration, that Pivotal system detects and corrects.*
*
PWS isn't correcting a configuration problem. It unpacks your jar file before running the application which stops the double slash from causing a problem. – Andy Wilkinson
At the end the solution was related to the double slashes, that the classpath:/templates/ gets if we set a return statement with a slash at the beginning like:
return "/theme/property"
Instead of:
return "theme/property"
In my case, the problem was not at the controller, but in the html with the Thymeleaf references of fragments, like in this example:
<footer th:replace="/index::footer"></footer>
Instead of:
<footer th:replace="index::footer"></footer>
What I don't understand is why the IDE's (NetBeans and STS), where not raising the error.
use
return new ModelAndView("member2",map);
instead of
return new ModelAndView("/member2",map);
Remove spring.thymeleaf.prefix=classpath:/templates/ from your application.properties.
experts.
I need to reload a file when it updated automatically in Liberty. To make it more clear, I want to make a path like "dropins" in liberty, it can automatically detect the change of files or we can scan this folder manually. I need to load the files in this folder when they changed.
I've no idea how to achieve this....
Could anyone here know about it?
Thx!
If you are not averse to writing a Liberty feature (not hard, but requires a little background reading), then you can register a listener for changes to specific files by implementing the com.ibm.wsspi.kernel.filemonitor.FileMonitor interface as a Declarative Service. Once registered as a DS, the Liberty file monitor will invoke your implementation's methods. It invokes onBaseline(Collection<File> baseline) on startup, and onChange(Collection<File> createdFiles, Collection<File> modifiedFiles, Collection<File> deletedFiles) when a change of some sort has occurred.
One implementation might look like this:
#Component(immediate="true", property={"monitor.directories=/path/to/myMonitoredDir"})
public class MyFileMonitor implements FileMonitor {
#Override
public void onBaseline(Collection<File> baseline) {
System.out.println("Initial file state:");
for (File f : baseline) {
System.out.println(f.getName());
}
}
#Override
public void onChange(Collection<File> createdFiles, Collection<File> modifiedFiles, Collection<File> deletedFiles) {
System.out.println("Newly added files:");
for (File f : createdFiles) {
System.out.println(f.getName());
}
System.out.println("Newly deleted files:");
for (File f : deletedFiles) {
System.out.println(f.getName());
}
System.out.println("Modified files:");
for (File f : modifiedFiles) {
System.out.println(f.getName());
}
}
}
Hope this helps,
Andy
I am using WebApi like I've learnt from http://t.co/mt9wIL8gLA
It all works well if I know exactly the perfect origin URI of my client's requests.
Too bad I am writing an enterprise-wide API, so my request to, say
http://apps.contoso.com/myApp/api/foobar
may come from apps all over my domain, say:
http://apps.contoso.com/CRMApp
http://apps.contoso.com/XYZ
http://www.contoso.com/LegacyApp
http://test.contoso.com/newApps/WowApp
...
and all the new apps my enterprise builds.
What is the best way to approach this? using Origins="*" is cheesy, adding origins to my WS source and redeploy is cheesier.
My current solution is writing a custom CorsPolicyAttribute like in http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api#cors-policy-providers
and read the allowed origins from appsettings in web.config.
A LITTLE better could be, inside the custom attribute, checking if the request Origin: header is from contoso.com, maybe with a regexp, and add it to allowed origins.
I am wondering if there is a better, more standard, way.
Use a DynamicPolicyProviderFactory. That's what I use...I even posted a question about it the other day that kind of shows how to add the allowed domains to the web.config file.
I ended up just writing an AuthorizationFilterAttribute, although I might have just done a regular FilterAttribute.
public class FilterReferals : AuthorizationFilterAttribute
{
public override void OnAuthorization(HttpActionContext actionContext)
{
var request = actionContext.Request;
if (!AllowedReferers.GetAllowedReferersList().Contains(request.Headers.Referrer?.Host.ToLower()))
{
Challenge(actionContext);
return;
}
base.OnAuthorization(actionContext);
}
void Challenge(HttpActionContext actionContext)
{
var host = actionContext.Request.RequestUri.DnsSafeHost;
actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized);
actionContext.Response.Headers.Add("WWW-Authenticate", string.Format("Basic realm=\"{0}\"", host));
}
}
is it possible to use the default resource provider that uses .resx files in the application but uses an SqlResourceProvider in a sub folder?
seems like the only one used is the one configured in web.config of the root?
any idea ?
I needed something similar, returning a custom ResourceProvider for specific classkeys, but then fallback to default resource providers otherwise.
I created a custom ResourceProviderFactory that returns my custom resource provider when requested, but otherwise returns null, which appears to cause the default provider to be used instead.
[DesignTimeResourceProviderFactory(typeof(CustomizedResourceProviderDesignTimeFactory))]
public class CustomizedResourceProviderFactory : ResourceProviderFactory
{
public override IResourceProvider CreateGlobalResourceProvider(string classKey)
{
if (classKey == "MyCustomResourceClass")
{
return new CustomizedResourceProvider(classKey);
}
else
{
return null;
}
}
// etc.
}