How to generate WSDL file for SOAP Based web Service? - soap

I have been recently working on a java project using spring to create few additional API's. The original web service already exist and so its wsdl file. Now i am suppose to add more features.
For this project, first .xsd request and response files are created and then from X2J xml files are auto generated to java files. Using these files as fields i also create the new API. Now i need to add these new API in exisiting wsdl. The existing wsdl is too long and so is there any way i can generate wsdl for new and old API .
web.xml file
<!-- Servlet to expose webservices -->
<servlet>
<servlet-name>messageDispatcher</servlet-name>
<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
<init-param>
<param-name>transformWsdlLocations</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>messageDispatcher</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>messageDispatcher</servlet-name>
<url-pattern>*.wsdl</url-pattern>
</servlet-mapping>
messageDispatcher-servlet.xml file
<!-- Add supported requests here to define them in the WSDL -->
<bean id="schemaCollection" class="org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection">
<property name="xsds">
<list>
<value>classpath:xmlbind/zzzzRQ.xsd</value>
<value>classpath:xmlbind/zzzzRS.xsd</value>
<value>classpath:xmlbind/yyyyRQ.xsd</value>
<value>classpath:xmlbind/yyyyRS.xsd</value>
<!-- CONFIGURE WSDL -->
<bean id="XXXX" class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
<property name="schemaCollection" ref="schemaCollection"/>
<property name="portTypeName" value="ACVWS_"/>
<property name="locationUri" value="/services"/>
<property name="requestSuffix" value="RQ"/>
<property name="responseSuffix" value="RS"/>
</bean>
</bean>
<bean id="xxxx_v1_0" class="org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition">
<property name="wsdl" value="classpath:/wsdl/xxxx_v1_0.wsdl"></property>
</bean>
<bean id="xxxx_v2_0" class="org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition">
<property name="wsdl" value="classpath:/wsdl/xxxx_v2_0.wsdl"></property>
</bean>

Related

Duplicate instance of Bayeux Server created

I'm having a problem with my CometD Application. It looks like its creating multiple instances of the Bayeux Server. My configuration Files look like the following and i'm using Web Sockets as Transport/GigaSpaces to deploy the Application (which uses its own embedded jetty Server). Just wondering if I've misconfigured something in the following setup?
WEB.XML:
<?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"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>CometDApplication</display-name>
<servlet>
<servlet-name>cometd</servlet-name>
<servlet-class>org.cometd.server.CometdServlet</servlet-class>
<init-param>
<param-name>jsonContext</param-name>
<param-value>org.cometd.server.JacksonJSONContextServer</param-value>
</init-param>
<init-param>
<param-name>transports</param-name>
<param-value>org.cometd.websocket.server.WebSocketTransport</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cometd</servlet-name>
<url-pattern>/cometd/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.openspaces.pu.container.jee.context.ProcessingUnitContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/META-INF/spring/pu.xml</param-value>
</context-param>
</web-app>
POM.XML:
<dependency>
<groupId>org.cometd.java</groupId>
<artifactId>bayeux-api</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>org.cometd.java</groupId>
<artifactId>cometd-java-server</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>org.cometd.java</groupId>
<artifactId>cometd-java-annotations</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>org.cometd.java</groupId>
<artifactId>cometd-websocket-jetty</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-websocket</artifactId>
<version>7.6.8.v20121106</version>
</dependency>
My Applcation Context File (pu.XML):
<bean id="Bayeux" class="org.cometd.server.BayeuxServerImpl" init-method="start" destroy-method="stop">
<property name="options">
<map>
<entry key="logLevel" value="0" />
<entry key="timeout" value="15000" />
</map>
</property>
<property name="transports">
<list>
<bean id="websocketTransport" class="org.cometd.websocket.server.WebSocketTransport">
<constructor-arg ref="Bayeux" />
</bean>
<bean id="jsonTransport" class="org.cometd.server.transport.JSONTransport">
<constructor-arg ref="Bayeux" />
</bean>
<bean id="jsonpTransport" class="org.cometd.server.transport.JSONPTransport">
<constructor-arg ref="Bayeux" />
</bean>
</list>
</property>
</bean>
<bean id="ContextExporter" class="org.springframework.web.context.support.ServletContextAttributeExporter">
<property name="attributes">
<map>
<entry key="org.cometd.bayeux">
<ref local="Bayeux" />
</entry>
</map>
</property>
</bean>
You are indeed creating two instances of BayeuxServer, one created by the CometdServlet you define in web.xml and one created by Spring.
Like stated in the CometD and Spring integration documentation, if you use Spring to initialize CometD, then your whole BayeuxServer configuration must be in Spring.
Don't duplicate it in web.xml.
Furthermore, since you define a <load-on-startup> element, the CometdServlet is initialized before Spring's ContextLoaderListener, creating a BayeuxServer instance before Spring gets the chance to create its own and export it.
Remove all <init-param> from web.xml, remove <load-on-startup> and you should be good: the servlet will be lazily initialized and will find the Spring-created BayeuxServer exported correctly, without creating an additional instance.

Sample for integrating BatooJPA in Jetty with Gradle

I'm trying to integrate Batoo JPA in one of my projects using gradle and Jetty as a server.
What libraries do I have to integrate? Is there a sample available?
Currently I have these:
'org.batoo.jpa:persistence-api:2.0',
'javax.validation:validation-api:1.0.0.GA',
'com.jolbox:bonecp:0.8.0-rc1'
But these appear not to be enough. Before going further with "trial and error" I'd wanted to ask here at stackoverflow first, what libraries I need to get started with Batoo Jpa (together with gradle and Jetty).
Thanks
In one basic project i made, i had to configure these libraries:
-batoo-annotations-2.0.1.0-RTM.jar
-batoo-annotations-2.0.1.0-RTM-sources.jar
-batoo-jdbc-2.0.1.0-RTM.jar
-batoo-jpa-2.0.1.0-RTM.jar
-batoo-jpa-spi-2.0.1.0-RTM.jar
-jpql-0.1.6.jar
-parser-2.0.1.0-RTM.jar
-persistence-api-2.0.jar
-guava-14.0.1.jar
-commons-lang-2.6.jar
-validation-api-1.0.0.GA.jar
-bonecp-0.7.1.RELEASE.jar
-commons-dbutils-1.5.jar
-commons-io-2.4.jar
-asm-3.3.1.jar
-h2-1.3.171.jar <-- I add this one as database driver it could be changed.
If you have problem with transactions (if i remember correctly Batoo raise exceptions if you don't have a transaction control, but you can test it) i configured these libraries in order to have a CDI transaction control, but you can omit these if you want to use spring or Batoo does works well without a transaction control :-)
-deltaspike-cdictrl-api-0.3-incubating.jar
-deltaspike-cdictrl-weld-0.3-incubating.jar
-deltaspike-core-api-0.3-incubating.jar
-deltaspike-core-impl-0.3-incubating.jar
-deltaspike-jpa-module-api-0.3-incubating.jar
-deltaspike-jpa-module-impl-0.3-incubating.jar
-weld-api-2.0.0.jar
-weld-spi-2.0.0.jar
-weld-se-2.0.0.jar
Now, remember that Batoo uses standard properties in the persistence.xml file, like this:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="your PU name" transaction-type="RESOURCE_LOCAL">
<provider>org.batoo.jpa.core.BatooPersistenceProvider</provider>
<class>here.you.add.your.Entities</class>
<properties>
<!-- here your driver-->
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
<!-- here the URL of your database-->
<property name="javax.persistence.jdbc.url" value="jdbc:h2:tcp://localhost/~/test" />
<!-- here your username-->
<property name="javax.persistence.jdbc.user" value="sa" />
<!-- here your password-->
<property name="javax.persistence.jdbc.password" value="" />
</properties>
</persistence-unit>
Hope this helps, cheers :-)

what's wrong with my #PersistenceContext?

I'm using Eclipse Juno, Glassfish 3.1.2, and MySQL 5.1.
I'm building a simple EJB & JSF application. I created the following eclipse projects:
appEAR <-- the EAR file
appEJB <-- contains UserService.java EJB
appJPA <-- contains UserDAO.java EJB, and User.java object
appWeb <-- contains index.jsp
It's just a skeleton right now, but I can deploy the app and see the index.jsp
Next, I tried to add the following to the UserDAO ...
#PersistenceContext
EntityManager em;
But then when the app tries to republish, it gives me the error:
'Publishing to GlassFish 3.1.2 at localhost...' has encountered a problem. cannot Deploy appEar
There are no other details.
When I remove the two lines of #PersistenceContent code, the app deploys again.
Also, the persistence.xml file n the appJPA project is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="appJPA">
<class>app.model.User</class>
</persistence-unit>
</persistence>
Please help ... what am I missing? I'm rather stuck.
Your persistence.xml is incomplete , you need to provide Connection properties to specify the provider ,which DB to connect etc
Heres an example using hibernate as the JPA provided
<persistence-unit name="educationPU"
transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.coe.jpa.StudentProfile</class>
<properties>
<property name="hibernate.connection.driver_class"
value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url"
value="jdbc:mysql://localhost:3306/COE" />
<property name="hibernate.connection.username" value="root" />
<property name="show_sql" value="true" />
<property name="dialect" value="org.hibernate.dialect.MySQLDialect" />
</properties>
</persistence-unit>
and heres a more Generic one
I am very new to glassfish, JPA and so on and I have really problems with setting that up. What I am planning to do is a simple RESTful service with a persistent backend. I am using glassfish3 as application server and already deployed a simple REST service with the jersey-library. Now I want to provide access to a database via JPA. Glassfish is shipped with JavaDB/derby and EclipseLink, is that right? So, I want to use that :-)
I created a persistence.xml in META-INF:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="myPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDataSource" /> <!-- org.apache.derby.jdbc.EmbeddedDriver -->
<property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/sample;create=true" />
<property name="javax.persistence.jdbc.user" value="APP" />
<property name="javax.persistence.jdbc.password" value="APP" />
<property name="eclipselink.ddl-generation" value="create-tables" />
</properties>
</persistence-unit>
</persistence>
I don't use glassfish. But I think the reason is that you didn't specify any datasource in the persistence.xml. you should do this in it, which you can use jndi or other way. and second, you should define the entityManagerFactory bean in spring context xml file.
Did you add the datasource in glasfish ? You will need to add the mysql jdbc drivers too. In Java EE, it's the persistence container (inside the server) which will create and manage the datasource for you.
See http://www.albeesonline.com/blog/2008/08/06/creating-and-configuring-a-mysql-datasource-in-glassfish-application-server/

Spring MVC 3.1 Serving Static Resources

I'm trying to solve what seems to be a common problem of trying to serve static resources such as images, style sheets and scripts from my Java Web App. I've tried a lot of the solutions offered in other threads but have gotten nowhere, all I get is 404 errors on the resource calls.
The only other thing I can think of is that I'm running on Tomcat 7, but if I try putting 6 on I get a "The server does not support version 3.0 of the J2EE Web module specification." error, so that looks like a no go. Does anyone have any ideas where I might be going wrong?
My project is structured as so:
WebContent
META-INF
Resources
CSS
Images
close.jpg
Scripts
WEB-INF
Lib
Views
index.jsp
Web.xml
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
spring-servlet
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="uk.ac.ncl.controllers" />
<mvc:resources mapping="/resources/**" location="/resources" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
My Controller
#RequestMapping(value="/", method = RequestMethod.GET)
public String index()
{
return "index";
}
My View
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>Spring 3.0 MVC Series: Index - ViralPatel.net</title>
</head>
<body>
<h1>Page with image</h1>
<!-- use c:url to get the correct absolute path -->
<img src="<c:url value="/resources/images/close.png" />" />
<img src="http://localhost:8080${pageContext.request.contextPath}/resources/images/close.png" />
View Map
</body>
Can it be a case-sensitivity issue? Your html says /resources/images but your tree looks like /Resources/Images

glassfish-resource.xml and persistence unit in eclipse ang glassfish v3.0

I created a Web project in eclipse and adding a glassfish-resource.xml init and configure it with my database url.
also I added a persistence.xml unit in my project and add a jta-datasource for my datasource defined in glassfish-resource.xml but when the application is being deployed on glassfish in ide I got error that :
Lookup failed for 'java:module/jdbc/sportal' in SerialContext
my glassfish-resource.xml:
<resources>
<jdbc-connection-pool name="java:module/jdbc/sportalPool"
res-type="javax.sql.DataSource" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
pool-resize-quantity="1" max-pool-size="5" steady-pool-size="0"
statement-timeout-in-seconds="30">
<property name="User" value="root"></property>
<property name="Password" value="1234"></property>
<property name="portNumber" value="3306"></property>
<property name="dataBaseName" value="sportal"></property>
<property name="serverName" value="192.168.2.7"></property>
</jdbc-connection-pool>
<jdbc-resource pool-name="java:module/jdbc/sportalPool"
jndi-name="java:module/jdbc/sportal"></jdbc-resource>
and my persistence.xml is:
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="PU" transaction-type="JTA">
<jta-data-source>java:module/jdbc/sportal</jta-data-source>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.logging.level" value="FINE" />
</properties>
</persistence-unit>
I get the same error with "java:app/..." instead of "java:module/..." too.
My glassfish version is Open edition 3.0.1, JPA2, eclipse Helios
RGDS
Most likely the jdbc-resource is not created when Glassfish starts. Go to Glassfish Admin console and look under JDBC Resources to check whether your sportal resource has been created or not.
I don't know if Eclipse Glassfish module can do this automatically using glassfish-resources.xml, all I know is that Netbeans 7 created the jdbc resources automatically when Glassfish starts (or does it create it when I reverse engineer my database table?)?
Either way you have to create the JDBC Resource first.
Try using just "jdbc/sportal" as the JNDI and DS name, the prefix may be confusing things.