Apache Server File Permission - ajax

I am using Apache Server 6.0 and I am trying to update a file using ajax put request but the server is giving me error 405 Method Not Allowed. I am working this out on windows.
Can anybody help me out if that.
Thanks in Advance.
Vinay

I'm assuming you are using apache tomcat (because you have mentioned version 6.0)
In that case add this to your webapp's web.xml:
<servlet>
<servlet-name>myDefault</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>readonly</param-name>
<param-value>false</param-value> <!-- this will enable PUT for your app -->
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>myDefault</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
Then you can test this like so, to upload the file (You need the curl program to test)
curl -T somefile.txt http://localhot:8080/<yourapp>/
If you want to enable this globally, you can make the same change in /conf/web.xml (for default servlet)

Related

LoggingFilter not invoked - gives HTTP 404 - Not Found error

I am using Jersey 2.3.1, Tomcat 7.0, maven.
I have a simple jersey servlet:
#Path("/myresource")
public class JerseyResource {
#GET
#Produces(MediaType.APPLICATION_JSON)
public List <SecurityControlDTO> getControls() throws HibernateException {
SecurityControlDTOManager manager = new SecurityControlDTOManager();
return manager.getControls();
}
}
And want to add a LoggingFilter.
This is my web.xml:
<!-- Jersey Mapping -->
<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.rbs.wisexec.controlservice.rest;</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>jersey-auth</filter-name>
<filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
<init-param>
<param-name>javax.ws.rs.container.ContainerRequestFilter</param-name>
<param-value>org.glassfish.jersey.filter.LoggingFilter</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>jersey-auth</filter-name>
<url-pattern>/rest/*</url-pattern>
<servlet-name>jersey-servlet</servlet-name>
</filter-mapping>
When I run the tomcat server, the server starts up but then when I try to access the URL I get a "HTTP Status 404 - not found" error. I have debug breakpoints in filter class so I can see that it never gets invoked.
I have tried various different ways of configuring the loggingFilter in the web.xml i.e. putting the:
<init-param>
<param-name>javax.ws.rs.container.ContainerRequestFilter</param-name>
<param-value>org.glassfish.jersey.filter.LoggingFilter</param-value>
</init-param>
Inside of the servlet tag - this runs the server and the resource is shown but again the filters are not invoked.
If you want to configure your application via web.xml and not by using subclass of javax.ws.rs.core.Application, you can modify your web descriptor in this way:
<!-- Jersey Mapping -->
<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.rbs.wisexec.controlservice.rest;</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.filter.LoggingFilter</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
The important thing is the second init-param which states that LoggingFilter should be added to the list of JAX-RS providers in your application. Parameter is taken from ServerProperties class where you can find description of this parameter (ServerProperties.PROVIDER_CLASSNAMES) as well as other possibilities to configure your Jersey application.

deploying and running embedded mule in webapp (Mule twitter integration)

Hi I am newbaby to Mule!!
I want to run this simple app (receives input from url and post to my twitter account using twitter connector).
I try first deploying it on CloudHub and it works http://twitterconnector.cloudhub.io/addtweet?mymessage=firsttweet
after that I wanted to try deploying on Tomcat so I created simple webapp using maven and put all required dependences for Mule in pom.xml, set web.xml and mule-config.xml files and when I go to localhost:8181/easymule-test/services/addtweet?mymessage=firsttweet it is not working!
Can someone pls help/explain what is the problem?
than you in advance!!
Here is the flow:
<flow name="twitterconnectorFlow1" doc:name="twitterconnectorFlow1">
<servlet:inbound-endpoint path="addtweet" responseTimeout="10000" doc:name="Servlet"/>
<twitter:update-status config-ref="test_ECAccount" status="#[header:INBOUND:mymessage]" doc:name="Twitter Connector"/>
<expression-transformer evaluator = "groovy" expression="payload.toString()" returnSourceIfNull="true" doc:name="Expression"/>
</flow>
Edit: web.xml configuration fragment
<web-app>
<display-name>easymule-test</display-name>
<context-param>
<param-name>org.mule.config</param-name>
<param-value>/WEB-INF/muleconfig.xml</param-value>
</context-param>
<listener>
<listener-class>org.mule.config.builders.MuleXmlBuilderContextListener</listener-class>
</listener>
<servlet>
<servlet-name>ajax</servlet-name>
<servlet-class>org.mule.transport.ajax.container.MuleAjaxServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>muleServlet</servlet-name>
<servlet-class>org.mule.transport.servlet.MuleReceiverServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>muleResources</servlet-name>
<servlet-class>org.mule.transport.ajax.MuleJarResourcesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>muleServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>muleResources</servlet-name>
<url-pattern>/mule-resource/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ajax</servlet-name>
<url-pattern>/ajax/*</url-pattern>
</servlet-mapping>
</web-app>
A servlet endpoint path is a path not an address, so use:
<servlet:inbound-endpoint path="sendtweet" ...
Assuming:
your web-app is deployed on the /easymule-test context,
and is running on port 8181
and the org.mule.transport.servlet.MuleReceiverServlet is bound to the services path
then you'll access the above endpoint at http://localhost:8181/easymule-test/services/sendtweet.

Freemarker template (FTL) not working in struts2

I am working with Struts2 and ftl. Instead of jsp I want to use ftl, but when I define welcome file in web.xml as login.ftl it is not working. It just shown as text. The entire code is shown in the browser, but if it is jsp everything works.
I just paste my web.xml below.
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>login.ftl</welcome-file>
</welcome-file-list>
How can I configure ftl in Struts2? If I use that same page as output page of an action it is working. How can I solve this? Is there any problem with my web.xml configuration?? Please help me. Thank you in advance.
Maybe this help you(extract of a web.xml):
<servlet>
<servlet-name>freemarker</servlet-name>
<servlet-class>com.thoughtequity.video.web.servlet.SiteFreemarkerServlet</servlet-class>
<!-- FreemarkerServlet settings: -->
<init-param>
<param-name>TemplatePath</param-name>
<param-value>/</param-value>
</init-param>
<init-param>
<param-name>NoCache</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>ContentType</param-name>
<param-value>text/html</param-value>
</init-param>
<!-- FreeMarker settings: -->
<init-param>
<param-name>template_update_delay</param-name>
<param-value>0</param-value> <!-- 0 is for development only! Use higher value otherwise. -->
</init-param>
<init-param>
<param-name>default_encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>number_format</param-name>
<param-value>0.##########</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>/te.js</url-pattern>
</servlet-mapping>
<!-- Map *.ftl files to Freemarker-->
<servlet-mapping>
<servlet-name>freemarker</servlet-name>
<url-pattern>*.ftl</url-pattern>
</servlet-mapping>
<!-- The Welcome File List -->
<welcome-file-list>
<welcome-file>index.vm</welcome-file>
</welcome-file-list>
FreeMarker template files need to be processed in order to generate textual pages that shows your data. You cannot just put them in welcome-file-list. For example in Struts2 you can redirect to your action and there use your template.
Also read this http://wiki.metawerx.net/wiki/HowToUseAServletAsYourMainWebPage.

primepush on Tomcat 7 not working

I am new to primepush and have a question.
The whole project is based on maven and the server is Tomcat 7.0.27, so I add the dependence into pom.xml file as following:
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-annotations</artifactId>
<version>1.0.1</version>
</dependency>
The web.xml is like following:
<servlet>
<servlet-name>Push Servlet</servlet-name>
<servlet-class>org.primefaces.push.PushServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>org.atmosphere.cpr.broadcasterCacheClass</param-name>
<param-value>org.atmosphere.cache.HeaderBroadcasterCache</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.cpr.broadcasterClass</param-name>
<param-value>org.atmosphere.cpr.DefaultBroadcaster</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.cpr.broadcastFilterClasses</param-name>
<param-value>org.atmosphere.client.TrackMessageSizeFilter</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.cpr.sessionSupport</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.useWebSocket</param-name>
<param-value>false</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Push Servlet</servlet-name>
<url-pattern>/primepush/*</url-pattern>
</servlet-mapping>
I grab the code of chat from primefaces showcase, but somehow the IllegalStateException of AtomsphereFramework is always thrown.
09:33:38.322 ERROR o.atmosphere.cpr.AtmosphereFramework - AtmosphereFramework exception
java.lang.IllegalStateException: Not supported.
at org.apache.catalina.connector.Request.startAsync(Request.java:1609) ~[catalina.jar:7.0.12]
at org.apache.catalina.connector.RequestFacade.startAsync(RequestFacade.java:1031) ~[catalina.jar:7.0.12]
at javax.servlet.ServletRequestWrapper.startAsync(ServletRequestWrapper.java:379) ~[servlet-api.jar:3.0.FR]
at javax.servlet.ServletRequestWrapper.startAsync(ServletRequestWrapper.java:379) ~[servlet-api.jar:3.0.FR]
at org.atmosphere.cpr.AtmosphereRequest.startAsync(AtmosphereRequest.java:556) ~[atmosphere-runtime-1.0.1.jar:1.0.1]
at org.atmosphere.container.Servlet30CometSupport.suspend(Servlet30CometSupport.java:137) ~[atmosphere-runtime-1.0.1.jar:1.0.1]
at org.atmosphere.container.Servlet30CometSupport.service(Servlet30CometSupport.java:103) ~[atmosphere-runtime-1.0.1.jar:1.0.1]
at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:1293) ~[atmosphere-runtime-1.0.1.jar:1.0.1]
at org.atmosphere.cpr.AtmosphereServlet.doPost(AtmosphereServlet.java:293) [atmosphere-runtime-1.0.1.jar:1.0.1]
at org.atmosphere.cpr.AtmosphereServlet.doGet(AtmosphereServlet.java:279) [atmosphere-runtime-1.0.1.jar:1.0.1]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) [servlet-api.jar:na]
I debug the source code of Atomsphere Framework and find out the problem is the following line in the Servlet30CometSupport.class:
AsyncContext asyncContext = req.startAsync(req, res);
It throws an IllegalStateException afterwards.
How can I solve that problem?
Thanks for any help
Tomcat version 7.0.27 supports WebSockets.
So param setting in your web.xml should be
<init-param>
<param-name>org.atmosphere.useWebSocket</param-name>
<param-value>true</param-value>
</init-param>
or omit entire param setting cause websockets are used by default.
Also you will need to add dependencies for atmosphere-compat-tomcat-1.0.1.jar and atmosphere-compat-tomcat7-1.0.1.jar

How can I configure the xml config filename used by the Spring DispatcherServlet?

The documentation states that by default, the (WebApplication?) config file of the DispatcherServlet is found by appending "-servlet.xml" to the servlet-name, but I need to configure the name of this file explicitly. The Spring documentation of course does not describe how not to use the default.
Any suggestions?
try :
<servlet>
<servlet-name>app</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/filename.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>

Resources