I have created a cloundfoundry app using Spring. However, my jsp files are being rendered as pure text (as if Tomcat is not executing the source code). The browser shows the source when requesting a particular URL.
File structure
webapps
-jsp
-javascripts
-css
-WEB-INF
web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>
</context-param>
<welcome-file-list>
<welcome-file>/jsp/index.jsp</welcome-file>
</welcome-file-list>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Handles Spring requests -->
<servlet>
<servlet-name>Honesty</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/spring/webmvc-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Honesty</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
spring config:
<!-- Turns on support for mapping requests to Spring MVC #Controller methods
Also registers default Formatters and Validators for use across all #Controllers -->
<mvc:annotation-driven/>
<context:annotation-config />
<mvc:default-servlet-handler/>
Thanks for any insight you can provide. Its as if Tomcat is not serving the request as the JSP source is showing, not a JSP rendered page.
The response headers show nginx as the server:
Connection:keep-alive
Date:Mon, 30 Jul 2012 03:58:16 GMT
ETag:W/"611-1343620259000"
Keep-Alive:timeout=20
Server:nginx
Are you using Spring MVC? I suppose you are putting the JSP in some resource directory which can be accessed. Would like to see your spring configuration file and your project structure.
The problem was my servlet mapping of "/*". switched to just "/" and now everything works as expected.
Related
I am trying to create a Webservice implementation deployed on a WebSphere 8.5 application server.
I already created the skeleton and all the stubs but I don't know how to package my application.
I noticed that using axis2-wsdl2code-maven-plugin a services.xml file is created and this should replace the old WSDD file from axis1. However I don't know where should I place the services.xml and how to set web.xml (if it is needed).
Everything should be packaged in a simple war file.
I cannot find any simple documentation for this.
UPDATE:
I was able to deploy my application but I cannot reach neither the service nor its wsdl (the WSDL is not present inside the archive).
When I'm trying to reach my webservice i get:
org.apache.axis2.AxisFault: The service cannot be found for the
endpoint reference
I have the following services.xml file, located under WEB-INF/services fodler of my WAR archive.
<?xml version="1.0" encoding="UTF-8"?><!-- This file was auto-generated from WSDL --><!-- by the Apache Axis2 version: 1.6.2 Built on : Apr 17, 2012 (05:33:49 IST) --><serviceGroup>
<service name="PagamentoBollettinoPostaleInf">
<messageReceivers>
<messageReceiver mep="http://www.w3.org/ns/wsdl/in-out" class="myservice.PagamentoBollettinoPostaleInfMessageReceiverInOut"/>
</messageReceivers>
<parameter name="ServiceClass">myservice.PagamentoBollettinoPostaleInfSkeleton</parameter>
<parameter name="useOriginalwsdl">true</parameter>
<parameter name="modifyUserWSDLPortAddress">true</parameter>
<operation name="getPagamentoBollettinoPostaleInf" mep="http://www.w3.org/ns/wsdl/in-out" namespace="******">
<actionMapping>urn:getPagamentoBollettinoPostaleInf</actionMapping>
<outputActionMapping>urn:getPagamentoBollettinoPostaleInfResponse</outputActionMapping>
</operation>
</service>
</serviceGroup>
This is my WEB.XML file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>inviaAnomalia</display-name>
<servlet>
<display-name>Apache-Axis Servlet</display-name>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>*.jws</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>
This is the endpoint i am trying to connect to:
http://localhost:9080/war_context_root/services/PagamentoBollettinoPostaleInf
This happens when I try to get the WSDL file of my webservice by connecting to: http://localhost:9080/war_context_root/services/PagamentoBollettinoPostaleInf?wsdl
SOLVED
The solution was to follow the steps shown here: http://maksim.sorokin.dk/it/2011/01/13/axis2-maven-servlets-tomcat/
Then, in order to deploy correctly, WSDL and services.xml descriptor file must be placed inside:
WEB-INF/services/<ServiceName>/META-INF
Furthermore, disabling IBM JAX-WS Engine as suggested by Bruce T. and setting the classloader as shown in the following image solved the issue.
I have a non-embedded Jetty. I would like to dynamically configure a servlet's settings. Specifically, I want to change the default servlet's resourceBase setting.
In the web.xml file it's simply
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
<init-param>
<param-name>resourceBase</param-name>
<param-value>something</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
But how can I change this dynamically using code? And where do I have to put that code?
If you have a webapp, and are using WEB-INF/web.xml, then the resourceBase is the webapp itself.
You cannot change that.
You can, however, make a NEW DefaultServlet entry, to serve other content from a different url-pattern (note: You cannot use / or /* for this new servlet's url-pattern), just define it as a new Servlet, with it's own name.
I have an Axis2 based web service which I deployed in Tomcat.First I downloaded axis2.war & placed it in Tomcat's webapps folder.It created axis2 folder & its sub-folders.In the WEB-INF sub-folder of Axis2, in the services sub-folder I place my .aar file.Then in my browser I go to http://localhost:8080/axis2. It has a link services, which lists out all the services.Suppose my service is HelloWorldService. So the path where it is accessible is
http://localhost:8080/axis2/services/HelloWorldService
But I do not want to reveal to world that my web service is driven by Axis2. Suppose I want the path to be
http://localhost:8080/abc/services/HelloWorldService
How to do that? Do I have to rename axis2 folder to abc. I also have an web application abc deployed in the same Tomcat. Do I copy content of axis2 sub-folder to abc. I tried that, did not work.
I also have an web application abc deployed in the same Tomcat. Do I copy content of axis2 sub-folder to abc.
You're thinking in right direction and yes, you have to copy all content(100% is not required, but its better you do it to start with) of the Axis2.war to abc except web.xml.
You have to merge, axis2.war/WEB-INF/web.xml content with abc/WEB-INF/web.xml, by copying following to respectively inside <web-app> XML tag.
<servlet>
<display-name>Apache-Axis Servlet</display-name>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
<!--<init-param>-->
<!--<param-name>axis2.xml.path</param-name>-->
<!--<param-value>/WEB-INF/conf/axis2.xml</param-value>-->
<!--<param-name>axis2.xml.url</param-name>-->
<!--<param-value>http://localhost/myrepo/axis2.xml</param-value>-->
<!--<param-name>axis2.repository.path</param-name>-->
<!--<param-value>/WEB-INF</param-value>-->
<!--<param-name>axis2.repository.url</param-name>-->
<!--<param-value>http://localhost/myrepo</param-value>-->
<!--</init-param>-->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<display-name>Apache-Axis AxisAdmin Servlet (Web Admin)</display-name>
<servlet-name>AxisAdminServlet</servlet-name>
<servlet-class>org.apache.axis2.webapp.AxisAdminServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>*.jws</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisAdminServlet</servlet-name>
<url-pattern>/axis2-admin/*</url-pattern>
</servlet-mapping>
Hope it works for you! If it doen't work update your question and I could refocus the answer.
I am starting to try to figure out how to work with Apache Camel within a Spring framework. The first thing that I want to try to get a grasp on would be running simple web service calls over this but I have no idea where to start.
Right now all I have is a basic HelloWorld Spring project set up and am trying to figure out what needs to be configured Apache Camel wise and where to get started on creating a simple web service.
I have taken a look at the examples on the Apache site but I was hoping maybe someone here knew of a tutorial that was a basic start to finish of something like I am trying to do.
Thanks for any tips or help that you all have!
I really found this one useful once: http://camel.apache.org/spring-ws-example.html (and complete source code in the camel distribution).
There are multiple ways you can deal with web services with Camel. Either use the spring web services as in the example I mention, or use Apache CXF.
Spring Web services are really easy to get started with, compared to CXF. Although CXF is a more complete web service stack.
There are multiple Camel and CXF examples here:
http://camel.apache.org/examples.html
If you go with CXF, you may well benefit from actually learning a few "CXF only" examples before mixing with Camel.
There are essentially two ways to do web services, contract first start with a WSDL, then auto generate classes/interfaces. The other approach is code first - where the you start with java classes and then get an auto generated WSDL.
There are some rather good articles over here: http://cxf.apache.org/resources-and-articles.html
But to answer your question, I don't know of any good step-by-step tutorial on this matter. The examples in the links are really good though.
I had the same question, and I have found this article
Step by step introduction to Web services creation using CXF and Spring:
http://www.ibm.com/developerworks/webservices/library/ws-pojo-springcxf/index.html?ca=drs-
In short, there is four steps to create a web service
1 - Create a service endpoint interface (SEI) and define a method to
be exposed as a Web service.
package demo.order;
import javax.jws.WebService;
#WebService
public interface OrderProcess {
String processOrder(Order order);
}
2 - Create the implementation class and annotate it as a Web service.
package demo.order;
import javax.jws.WebService;
#WebService(endpointInterface = "demo.order.OrderProcess")
public class OrderProcessImpl implements OrderProcess {
public String processOrder(Order order) {
return order.validate();
}
}
3 - Create beans.xml and define the service class as a Spring bean
using a JAX-WS front end.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint
id="orderProcess"
implementor="demo.order.OrderProcessImpl"
address="/OrderProcess" />
</beans>
4 - Create web.xml to integrate Spring and CXF.
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/beans.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
I am struggling with a webapp deployment in Jetty 6. Previously the the webapp was deployed in /mywebapp and everytime I accessed http://localhost/mywebapp/ Jetty directed me to http://localhost/mywebapp/index.jsp.
When I change the contextPath to /, suddenly the redirect behaviour is broken. Instead, Jetty makes an internal forward request.
Does anyone have any input why this is happening? The DefaultServlet has the following settings:
<init-param>
<param-name>dirAllowed</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>welcomeServlets</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>redirectWelcome</param-name>
<param-value>true</param-value>
</init-param>
Turns out it was not exactly the change of contextPath that made the redirects fail. Instead, I realized that simply the action of adding mywebapp.xml into $JETTY_HOME/contexts/ made Jetty not execute the redirects.
I overcame this issue by deleting my context XML file, instead renaming $JETTY_HOME/webapps/mywebapp.war to $JETTY_HOME/webapps/root.war solved the issue.
Unclear why this happened in the first place, but I'm happy things are back on track.