Validate SOAP message against WSDL - java

Just like validating an XML file against an XML Schema Definition in Java is there a way to validate an XML file that contains a SOAP Envelope against a WSDL file?

Some web service containers provide this functionality. JBoss 3.0.1+ does this with the #SchemaValidation annotation:
http://community.jboss.org/wiki/JBossWS-NativeUserGuide#SchemaValidation

If you are using Spring-WS, this can be done by using an interceptor along these lines:
<sws:interceptors>
<sws:payloadRoot namespaceUri="...">
<bean id="validatingInterceptor"
class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
<property name="schema" value="classpath:/wsdl/schema.xsd" />
<property name="validateRequest" value="true" />
<property name="validateResponse" value="true" />
</bean>
</sws:payloadRoot>
</sws:interceptors>
With CXF, here is an approach:
http://cxf.apache.org/faq.html#FAQ-HowcanIturnonschemavalidationforjaxwsendpoint%3F

There is a tool developed by Ivan Krivyakov which validates the req or resp XMLs based on the WSDL and / or XSD provided. The tool is available at http://www.codeproject.com/Articles/182406/Validating-SOAP-Message-against-WSDL (requires you to create a login though.)

I don't know simple way. In our project we just copy and paste element from WSDL to XSD file. You can write an util class which will make this work instead of you.

Related

SOAP UI doesnt generate wsdl-interface

I am trying to test my soap web service by SOAP-UI, Also I use Spring-ws and Java.
I point to my wsdl file in spring configuration like this:
<bean id="myservice" class="org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition">
<constructor-arg value="/WEB-INF/wsdl/myservice.wsdl"/>
</bean>
Then in the SOAP UI I locate this wsdl file, but it does not create and WSDL-interface that I can work with to create requests.
But If I use the exactly same xsd but dynamically create the wsdl file than SOAP UI creates the wsdl interface fine:
<sws:dynamic-wsdl id="myservice"
portTypeName="MyService"
locationUri="/myService"
targetNamespace="http://mypath">
<sws:xsd location="/mypath.xsd"/>
</sws:dynamic-wsdl>
What am I missing? I need modify my wsdl file and not work directly with spring auto generated wsdl.

is there any helper class spring uses to parse setter's data from xml that I can use?

Using Spring you can put setter/constructor data in bean definition xml like
<property name="myList">
<list>
<value>value1</value>
</list>
</property>
Now my project has similar requirement I wonder if spring already has well wrapped tool for this so I don't have to reinvent wheel?
thanks
Update:
I use Spring's namespace extension to create my own stuff. so I am responsible for parsing properties.
<application:mystuff>
<property>
..............
</property>
</application:mystuff>
Take a look at java.beans.XMLDecoder http://docs.oracle.com/javase/tutorial/javabeans/advanced/longpersistence.html

What is the recommended way to store user credentials in spring MVC?

I am creating a Spring MVC application which is a SOAP client. To communicate with SOAP web-service I am suppose to pass the login credentials. My application doesn't need to store any details dynamically and hence I am not using any db for this application. So kindly suggest a recommended practice to store the sensitive credential for my application. This credential will we managed by the system admin and must be easy for him to change according to the requirement.
Thanks in advance.
Store the username and password in a properties file external to your webapp spring context. That way the sysadmin can easily lock down read access on the properties file to the relevant parties (e.g. your application and himself). That should stop prying eyes seeing the password.
In your spring context have something like:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<list>
<value>/path/to/config.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>
<bean id="myBean" class="...">
<property name="username" value="{usernameFromExternalPropFile}" />
<property name="password" value="{passwordFromExternalPropFile}" />
</bean>
The sysadmin will then also be able to change the username/password independently from a build.
See http://www.javaworld.com/community/node/8309/
The simplest option would be to store them in your application context XML configuration file as properties to the bean which is communicating with the SOAP webservice.

Migration to Spring WS 2.0 failed due to lack of bean endpoint mapping?

We used the PayloadRootQNameEndpointMapping to map endpoint scripts (based on a scripting language like groovy or something else) to a given root QName. We recently tried to migrate spring ws to version 2.0. The javadoc of the PayloadRootQNameEndpointMapping shows that the class is marked as deprecated.
PayloadRootQNameEndpointMapping Deprecated as of Spring Web Services 2.0, in favor of PayloadRootAnnotationMethodEndpointMapping
Since annotations are static we can't provide a dynamic concept for scripting endpoints. Until now we could generically map the Bean which is handling a script endpoint (provided with a script file and some contexts) to the root QName.
Short: How can we achieve the good old bean endpoint to Root QName mapping without using the deprecated API? Any ideas?
Thank you in advance.
Can you use something like the SimpleMethodEndpointMapping to write your own dispatcher? Check the link for the source
You can use more general XPathPayloadEndpointMapping where xpath will point to root element.
<bean id="endpointMapping" class="org.springframework.ws.server.endpoint.mapping.XPathPayloadEndpointMapping">
<property name="expression" value="local-name(//*[1])" />
<property name="endpointMap">
<map>
<entry key="rootElement" value="endpointRef" />
</map>
</property>
</bean>

Is there a solution for generating a JSON SMD for a Spring 3 REST Controller?

A colleague and I are setting up an architecture for rapid development of rich client-side apps using REST and JSON. Our server is using Spring 3's MVC and REST features to expose REST services as Spring controllers. For non-standard REST calls, we'd like to use Service Mapping Descriptors (SMD) to expose the contract of certain controllers:
http://groups.google.com/group/json-schema/web/service-mapping-description-proposal
SMD looks fairly new on the scene; is there any solution out there right now for generating an SMD JSON file from a Spring 3 REST controller?
You can define your own HttpMessageConverter:
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<bean class="my.package.CustomJsonHttpConverter" />
</list>
</property>
</bean>
where CustomJsonHttpConverter extends AbstractHttpMessageConverter, just like the MappingJacksonHttpMessageConverter.

Categories