I'm stuck with this problem and I can't find a solution for it anywhere, so any ideas are welcome.
I want to execute some code on a #WebServlet (javax.servlet.annotation.WebServlet) before it loads my index.jsp. For that I added "/" to the urlPatterns. This does what it's expected in the index.jsp, but it doesn't load my css or image paths any more. The problem is the "/" makes it include all other files in these urlPatterns, but if I try to use "index" instead, it doesn't work.
Can someone please help?
Cheers,
M.
Just use an url-pattern which exactly matches /index.jsp.
#WebServlet(urlPatterns = { "/index.jsp" })
Unrelated to the concrete question, I wonder if you can't better use a ServletContextListener (which is annotable using #WebListener). This is certainly true when your sole functional requirement is to preload/preinitialize some application-wide data on server's startup, regardless of the first-opened webpage.
Related
I get this error message when trying to connect to our webservices.
Error 404: javax.servlet.UnavailableException: SRVE0201E: Servlet [...] not a servlet class.
However, the class mentioned inside the brackets is a servlet class:
#WebService(serviceName = "xxx", endpointInterface = "xxx")
What I read was that in Websphere the class loader should be configured to Parent last; this is what I did and then to get rid of all jar - files that use Servlet.jar - I think I did this, too, since the only files that I am using are these ones:
antisamy-1.4.3.jar
api-7.9.0.0.jar
avalon-framework-4.1.3.jar
batik-css-1.7.jar
batik-ext-1.7.jar
batik-util-1.7.jar
bsh-core-2.0b4.jar
commons-beanutils-1.7.0.jar
commons-beanutils-core-1.7.0.jar
commons-codec-1.2.jar
commons-collections-3.2.jar
commons-configuration-1.5.jar
commons-digester-1.8.jar
commons-fileupload-1.2.jar
commons-httpclient-3.1.jar
commons-lang-2.3.jar
commons-logging-1.1.jar
core-7.9.0.0.jar
dom4j-1.6.1.jar
esapi-2.0_rc11.jar
istack-commons-runtime-2.16.jar
jaxb-api-2.2.9.jar
jaxb-core-2.2.8-b01.jar
jaxb-impl-2.2-promoted-b65.jar
jaxen-1.1-beta-8.jar
jdom-1.0.jar
log4j-1.2.16.jar
log4j-api-2.7.jar
log4j-core-2.7.jar
logkit-1.0.1.jar
nekohtml-1.9.12.jar
serializer-2.7.2.jar
xalan-2.7.2.jar
xercesImpl-2.11.0.jar
xml-apis-1.4.01.jar
xml-apis-ext-1.3.04.jar
xom-1.1.jar
Maybe someone could give me a hint or knows that the problem can be?
Thank you very much!
If you're relying on the annotation you mentioned, that's going to create a web service, not a servlet. Unless of course the class the #WebService is defined in extends javax.servlet.Servlet. Did you mean #WebServlet instead? Posting the pertinent portion of your source would be helpful.
This is one possibility:
https://developer.ibm.com/answers/questions/171243/srve0201e-servlet-my-webservice-not-a-servlet-clas.html
This text in particular:
The issue was showing up at deploy time and had to do with the fact
that my web services was referencing classes in a shared library. The
deploy code doesn't have access to the shared library so it wasn't
able to resolve things and gave up.
After some mad refactoring it started working.
If I define a Sling Servlet as follows:
#SlingServlet(
label="TestResourceTypeServlet",
name = "com.company.project.servlets.TestResourceType",
extensions = {"bob"},
resourceTypes= {"cq:Page"},
methods= {"GET"},
metatype=true)
#Properties({
#Property(name = "service.description", value = "A test servlet"),
#Property(name = "service.vendor", value = "Company")
})
The servlet picks up any get request to every page with an extension of '.bob', which is fine but what I really want is to handle a request to a specific page type,
SO
I modify resourceTypes to read
resourceTypes= {"site-administration/components/page/page-distribution"},
the supplied value is the specific sling:resourceType (copied and pasted out of CRXDE Lite) of a page I am trying to access with the .bob extension, but I get a 404!!!
All the documentation I've read says the above should work, but it does not.
Out of desperation I've even tried "site-administration/components/page" which is the super type of the page I want.
I'm running a clean 5.6.1 instance with this servlet as part of an OSGi bundle.
Am I missing something obvious here, or if not is anyone aware of any hot fixes that could resolve this issue ?
Any help would be appreciated as I'm starting to go slightly mad in the head.
EDIT
Ok, so I've gotten a little further: If I access the page with:
[path-to-page]/page.bob.html
The servlet fires. But in this URL is bob not a selector? and if so why when the resource type is cq:Page does the configuration work with bob as an extension?
Very confused :-S
I'm obviously missing something very simple here.
The problem with pages is that the resourceType is stored on the jcr:content node below the cq:Page node. If you would call [path-to-page]/_jcr_content.bob it should work. Note: _jcr_content is an url save version of jcr:content.
Why your last example is actually working, I cannot tell.
Is there a simple way to check if a content-type, or a specific object, has Versioning enabled/disabled in Plone (4.3.2)?
For context, I am making some unique conditionals around portal_actions. So instead of checking path('object/##iterate_control').checkout_allowed(), I need to first see if versioning is even enabled. Otherwise, the action in question does not display for items that have versioning disabled, because obviously it isn't checkout_allowed.
I didn't have any luck with good ole Google, and couldn't find this question anywhere here, so I hope it's not a dupe. Thanks!
I was able to get this working by creating a new script, importing getToolByName, and checking current content type against portal_repository.getVersionableContentTypes(). Then just included that script in the conditional.
I was looking for something like this that already existed, so if anyone knows of one let me know. Otherwise, I've got my own now. Thanks again!
The first thing that checkout_allowed does is check if the object in question supports versioning at all:
if not interfaces.IIterateAware.providedBy(context):
return False
(the interface being plone.app.iterate.interfaces.IIterateAware:
class IIterateAware( Interface ):
"""An object that can be used for check-in/check-out operations.
"""
The semantics Interface.providedBy(instance) are a bit unfortunate for usage in conditions or TAL scripts, because you'd need to import the interface, but there's a reversal helper:
context.portal_interface.objectImplements(context,
'plone.app.iterate.interfaces.IIterateAware')
For the life of me I can't make durandaljs work with Areas. I'm developing an application with multiple mini SPAs, but I'm not sure how to set up durandaljs to work with it. I wasn't able to find anything online that can drive me in the right direction. The only similar question I found was this one, which is very vague.
My goal is to separate each SPA within it's own folder like so:
App
--areas
----area1
------viewmodels
------views
----area2
------viewmodels
------views
The router doesn't seem to have the concept of areas and no matter how I map the routes I get 404s when I call router.activate('page1'); after mapping with router.mapRoute('page1'); durandal is trying to get /App/viewmodels/page1.js.
Changing it to:
router.mapRoute('areas/area1/viewmodels/page1');
router.activate('areas/area1/viewmodels/page1');
results in another 404 fetching App/viewmodels/areas/area1/viewmodels/page1.js
I've also tried many other combinations which I no longer remember and can't seem to get it to work.
Can someone please post a working example of how to setup durandaljs with the router plugin and multiple mini SPAs (areas)? A link to an article document would also suffice.
You can use viewLocator.useConvention - maybe something like this:
viewLocator.useConvention(
"areas/area1/viewmodels",
"areas/area1/views",
"areas/area1/templates"
);
One good thing to realize is that useConvention() works in conjunction with any existing require.config paths setting. In other words, if you set the require.config so that "viewModels" and "views" are mapped to the right folders, then all is well.
For example, the code snippet above is functionally equivalent to:
window.require.config({
paths: {
"viewModels": "areas/area1/viewmodels",
"views": "areas/area1/views",
"templates": "areas/area1/templates"
}
viewLocator.useConvention("viewmodels", "views", "templates");
I a similar structure implemented in my application. I think that you have to put this piece of code, to do the viewLocator works properly.
viewLocator.useConvention(); //You can do that in you main.js
You can see more information here: http://durandaljs.com/documentation/View-Locator/
Also I recommed you to look the code of viewLocator.js, especially, the code of useConventionMethod.
Other possibility is to override the method convertModuleIdToViewId, to make it works as you want. But I think that using useConvention methos is enought.
I just cant get this to work...
I have the following routes:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("*.html|js|css|gif|jpg|jpeg|png|swf");
routes.IgnoreRoute("{*favicon}", new { favicon = #"(.*/)?favicon.ico(/.*)?" });
routes.MapRoute(
"Default", // Route name
"{lama}/{controller}/{action}", // URL with parameters
new { controller = "Home", action = "Index", lama = "en-gb" } // Parameter defaults
);
And once I load the page.. I have a img element that tries to retrive the following url:
css/img/backgrounds/slide1_2048x1280.jpg
But the image wont show up and if I check my console I get the following error:
GET {my localhost}/cn/Home/css/img/backgrounds/slide1_2048x1280.jpg 404 (Not Found)
I have such a hard time understanding the route-system.. is there anywhere I can read ALOT more about this?.. And could somebody please help me with this single problem then that whould be very appreciated!
I think have fallen foul of relative urls in your html.
Since you haven't said whether this is Razor or Aspx; I'm just going to go with Aspx.
When you write the img tag it seems that you might be doing:
<img src="[relative_path_to_file]" />, using the path of the img relative to the page.
If that doesn't start with / then it's almost certainly the case that you will end up with issues, especially since MVC URLs don't map to the path of the actual page.
What you want to do is to use Url.Content("~/[full_path_to_file]") which will ensure that an absolute path will always be used.
On another note - you really do not need to write all these ignore routes for files that exist on disk. By default, the routing engine will not route existing files - you have to set routes.RouteExistingFiles = true in the RegisterRoutes method in your global in order to route files that already exist; so I think you should get rid of them.
i usually hit up 1) stackoverflow (obviously!), and 2) the msdn docs are pretty good:
http://msdn.microsoft.com/en-us/library/dd410120.aspx. But i usually end up googling for specifically what i need =)
However, looks like you're trying to setup a route to ignore certain filetypes?
i found this article that gives some good ideas on how to handle this.
I've only blocked one or two filetypes before, and i made one line per filetype. Not sure if you can make one line that has extensions delimited by pipe (|) like you're doing (i could be wrong!)
routes.IgnoreRoute("{*allaspx}", new {allaspx=#".*\.aspx(/.*)?"});
routes.IgnoreRoute("{*allswf}", new {allswf=#".*\.swf(/.*)?"});