Exception starting filter struts2 - struts2

Exception starting filter struts2
Unable to load configuration. - [unknown location]
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:431)
at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:190)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4072)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4726)
at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1284)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1382)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:306)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1389)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1653)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1662)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1642)
at java.lang.Thread.run(Thread.java:619)
Caused by: Unable to load configuration. - [unknown location]
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:374)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:418)
... 15 more
Caused by: Unable to locate parent package [showcase] - [unknown location]
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.getPackageConfig(PackageBasedActionConfigBuilder.java:887)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildConfiguration(PackageBasedActionConfigBuilder.java:536)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:318)
at org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:53)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:204)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
... 17 more

This problem occurs just because you missed some struts library files. Please make sure that all your library files are included in the build path.

From the error console it appears clearly that struts2 is unable to load configuration files as manager is unable to resolve the path.

I think you have missed to add the struts2 jar ...you may add struts2-core-2.1.8.jar and then use org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
in the configuration file.

I have similar problem in windows with Intellij IDE.I am using tomcat server. I copied all the jars of Struts2
asm.jar
asm-commons.jar
asm-tree.jar
commons-fileupload.jar
commons-io.jar
commons-lang.jar
freemarker.jar
javassist.jar
ognl.jar
struts2-core.jar
xwork-core.jar
to F:\xampp\tomcat\lib folder and it works.

The exception trace means your app is trying to find struts2-core.jar which it is not getting on the classpath. Add the library and other dependencies along with it. If you have already added, please make sure that it is available at the server (deployment assembly in case of eclipse/ lib folder in WEB-INF)
If you are trying to build a new webapp, it is advisable to avoid adding the jars manually and rather use a build tool like apache or gradle take care of it.
The process is a lot more simpler and conventional.
https://mvnrepository.com/artifact/org.apache.struts/
You could also try using readymade archetypes to avoid startup errors of all sorts. You can refer to the following link for later:
https://struts.apache.org/docs/struts-2-maven-archetypes.html

Missing JARs and duplicate JARs are the main reason. I would prefer to follow these steps for a Struts2 MVC Application:
Create Dynamic Web Application project in Eclipse (or equivalent in your IDE)
Add all the required JAR files into your build path and your WEB-INF/lib folder (or appropriate folders as needed by your server). I had used Eclipse Mars + Tomcat 8
Add filter tags to your web.xml to redirect all URLs to the StrutsPrepareAndExecuteFilter (that's the latest for struts2)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
Create necessary view pages
Create necessary Action class by either extending ActionSupport class or implementing Action interface (I would prefer the former!)
Create struts.xml and place it in your SRC folder of your context root *i.e project folder root level. Place all your action-to-result mappings inside this xml file.
Double check all files to make sure all spellings are spelled correctly.
Note: These are general steps for a normal study-level Struts2 assignment. Actual production code may vary.

Related

JBoss 6.x throwing java.lang.ClassNotFoundException: com.sun.xml.internal.ws.spi.ProviderImpl

In our application we make WSDL service call(let us say "SomeService"). We use JBoss 6.x and JDK1.8 in our environment(test). Our application also has dependency with CXF for some other services. "SomeService" should be called through standard JAXWS instead of "CXF". By default,c all is being routed through CXF and that's resulting into policy issues. Hence, I followed the solution mentioned below:
JAX-WS = When Apache CXF is installed it "steals" default JDK JAX-WS implementation, how to solve? .
I made the following change in my code:
if (previousDelegate.getClass().getName().contains("cxf")) {
ServiceDelegate serviceDelegate = ((Provider) Class.forName("com.sun.xml.internal.ws.spi.ProviderImpl").newInstance())
.createServiceDelegate(SomeService.WSDL_LOCATION, SomeService.SERVICE_NAME, service.getClass());
delegateField.set(service, serviceDelegate);
}
This change works fine for me in my local environment(I'm using Tomcat 8 +JDK 1.8). I went and deployed the code in test platform (it's JBoss 6.x + JDK 1.8). While testing the functionality, I'm getting the following error:
java.lang.ClassNotFoundException: com.sun.xml.internal.ws.spi.ProviderImpl from [Module "deployment.MyAPP.war:main" from Service Module Loader]
Not sure of the reason for this error. Anybody has clues about it? Do we need to make any additional changes in our JBoss server. Since "com.sun.xml.internal.ws.spi.ProviderImpl" is standard class and that's available in JDK1.8, I don't see any reason why am I getting the above error since our JBoss server is pointing to JDK1.8.
Your help is highly appreciated.
It looks like a classloading issue with your application, or the application server.
The ClassNotFoundException will occur the first time the class is referenced and the classloader tries to load it. The next time the class is referenced, the classloader has cached that is is not found and will throw a NoClassDefFoundError.
Confirm that the ClassNotFoundException is not being caused by the class not being packaged correctly or other classloader settings. Also, ensure the ClassNotFoundException is not occurring the first time the class is referenced.
Check to see if there are any symlinks in the JBoss path.
That will tell us the classes you have deployed to your application, and allow us check if com.sun.xml.internal.ws.spi.ProviderImpl or a related class is deployed to it. That class is shipped with the application server in this directory, and I think this should be the only location it is loaded from.
src/jboss-as/thirdparty/sun-jaxws/lib/jaxws-rt.jar
The only reference I can find to the message "classLoader is not connected to a domain (probably undeployed?) for class "
If you are using a custom JAX-WS implementation and don't want to use JBossWS CXF (the supported JAX-WS library that comes with EAP 6.x), you'll need to first remove JBossWS from your deployment
Once you've done that, you then need to expose the JDK classes that represent the JAX-WS and SAAJ implementation.
Make sure you add modules dependencies for sun.internal.saaj and sun.internal.ws to your deployment.
--
Anup

Not able to access web-app folder files in Grails 3

I am not able to access web-app folder files in Grails 3.
I have robots.txt in the web-app folder and in Grails 2 I was able to access it directly at http://localhost:8080/robots.txt. After migrating to Grails 3 I am not able to access it anymore at http://localhost:8080/robots.txt.
How can I make these files accessible again?
See https://github.com/grails/grails-core/releases/tag/v3.0.12 and part Location of static resources
In Grails 3 you can store your files under src/main/resources. You can access them by filename preceded with static for example http://localhost:8080/static/robots.txt.
This path can be changed using config option as defined in attached URL
I faced a similar problem in Grails 3.3.1. I had the necessity to access a file template to use it with a plugin (excel-export plugin). After reading the documentation, I put the file under src/main/resources. It worked with OK in development mode (grails run-app), but I received an error in production environment (grails war). After a lot of reading, I've found the way to make it work. I've let the file in the same directory (src/main/resources), and then, in my controller:
def template = this.class.classLoader.getResource('myExcelFile.xlsx')
def path = template.file //will give you the real path to your file
Having the path, you can then open a stream or do what you need to do. In my case, use it whith the plugin:
new WebXlsxExporter(path).with {
setResponseHeaders(response)
add(products, withProperties)
save(response.outputStream)
}

Where is the default login page for the spring security core plugin?

I have installed the spring security core plugin. I need to modify the login page to look like my existing website. I have searched the entire project and cannot find it. I am running grails 2.4 and spring-security-core:2.0-RC5. Where can this pesky little file be? Can someone who is not a complete greenhorn help a fellow out?
As #Abs points out, the file is at target/work/plugins/spring-security-core-2.0-RC5/grails-app/views/login/auth.gsp but you shouldn't edit plugin files. Other developers on your team won't have access to the modified files and if you delete the target directory you'll lose your changes since the target directory is only a temporary work location.
Instead, copy the file to the same relative location in your application and make changes there. Create grails-app/views/login and copy the file there and make whatever changes you want.
This technique works for most plugin files, not just GSPs. The compilation order and classpath are configured such that application files and classes override plugin files if they're in the same location/package.
You can find the default login page here
targt->work->plugins->spring-security-core-2.0-RC5->grails-app->views->login>auth.gsp

Spring Web Service Message Dispatcher overrriding

I am currently working on creating a web service using Spring -WS.
I want to make the request reach my own Message Dispatcher Class. So I made the necessary configuration changes to web.xml and also my sping-congfig.xml file.
I am seeing an error when spring loads beans for my Message Dispatcher,
it tries to look for a properties file in my package which has the Dispatcher Class. for Example if my class is AccountMessageDispatcher, it looks for AccountMessageDispatcher.properties file in the package where I have created the class, I can get it running by keeping the properties file there, but I want to keep the properties file under my resources directory which has other property files needed by my application.
Can any one help me or point me in the right direction as to what I am doing wrong?
If we take a look to the default MessageDispatcher infrastructure, we'll that it reads appropriate proerties file - org.springframework.ws.server.MessageDispatcher.properties.
As you see this file is located at the same package as the original MessageDispatcher class.
According to your concern, you are right: that file should be located at the resources dir for sources. But if you use normal build system like Maven or Gradle, all your resources are packaged to the target jar alongside with classes.
To achieve your requirements you just need to create the same dir tree in the resources as your original AccountMessageDispatcher.
Actually any Java package is a dir in the end jar.

Grails: Using the Resources plugin in a plugin

I'm trying to use the Resources plugin (http://grails.org/plugin/resources) in a plugin that I'm developing, however, I can't seem to get it to work. I keep getting error messages that the module (defined in the ApplicationResources.groovy file) doesn't exist when it tries to render the gsp file. Only if I add the module to the Grails application's (that my plugin is being used in) ApplicationResources.groovy file does this error message go away. Clearly the Resources plugin is only looking at the application files, and not the plugin files. Is this a known issue? Is there a solution or work around to be able to use the Resources plugin in a plugin?
I simply renamed the ApplicationResources.groovy file to MyPluginResources.groovy (where MyPlugin is the name of the plugin) and the problem went away.

Resources