I want to implement a webservice client using Spring WS JAXB and CXF.
I use CXF to generate my Stubs from a WSDL file.
This WSDL contains the following schema :
For this schema the only thing that cxf generates is an ObjectFactory and no stub.
I want to use Spring Ws marshalSendAndReceive method to send a request to my service but I don't know how to construct my request object from what was generated with CXF.
Someone can help ?
thx
You don't really need CXF to generate the JAXB types from the WSDL file, JDK comes with a tool called xjc which can do this for you - http://docs.oracle.com/javase/6/docs/technotes/tools/share/xjc.html
Can you try using this and see if the artifacts created with this tool suffice.
Related
I am using "int-jdbc:stored-proc-outbound-gateway" in spring integration to get the details from the 11i stored procedure by directly hitting db using the datasource.
Now, I creating a Junit for the spring integration and need to mock the response as similar to the stored procedure result but hitting actual db.
Plz tell me achieve this scenario in the spring integration ?
Thanks in Adavance .
You can mock the StoredProcExcecutor which is constructor-injected into the gateway. The gateway invokes the executeStoredProcedure(Message<?> message) method.
If you are using Java configuration, you can simply inject the mock; if you are using XML, it's a bit more tricky, but you can use a DirectFieldAccessor to replace the SPE with a mock.
I would like to implement the following simple use case with Spring Integration v4.2+:
A REST endpoint is provided to clients, for example (/api/person).
The clients can POST data to this endpoint. The data can be submitted in JSON, XML or Google Protocol Buffers format.
The application accepts the data and saves it to a database table.
I have the following Spring Integration configuration that allows the endpoint to accept JSON data:
<int:channel id="receiveChannel"/>
<http:inbound-channel-adapter id="restInputAdapter"
channel="receiveChannel"
path="/api/person"
request-payload-type="java.util.Map"
supported-methods="POST"/>
<jdbc:outbound-channel-adapter id="jdbcOutputAdapter"
channel="receiveChannel"
data-source="dataSource"
query='INSERT INTO "person" ("first_name", "last_name", "email_address") VALUES (:payload[firstName], :payload[lastName], :payload[email])'/>
This is in a Maven project with Jackson2 on the classpath, which is why no special configuration is required for reading JSON from the request.
However, attempting to post XML data results in the following exception:
org.springframework.messaging.MessagingException: Could not convert request: no suitable HttpMessageConverter found for expected type [java.util.Map] and content type [application/xml]]
I have tried using the message-converters attribute with http:inbound-channel-adapter, specifying Jackson, JAXB and Protocol Buffers converters explicitly but that does not help either.
I know how to do this in a bespoke Spring MVC application with #RestControllers so I am not looking for solutions outside of Spring Integration.
How can the Spring Integration configuration above be tweaked so that the REST endpoint can be made to accept JSON, XML and Google Protocol Buffers at the same time?
It seems that although JSON converts to java.util.Map, XML does not. This is why the seen error.
I created a class:
#XmlRootElement class Person { ... }
and then modified the configuration as follows (only changes shown):
<http:inbound-channel-adapter ...
request-payload-type="Person"
.../>
<jdbc:outbound-channel-adapter ...
query='INSERT INTO "person" ("first_name", "last_name", "email_address") VALUES (:payload.firstName, :payload.lastName, :payload.email)'
.../>
I can now post both XML and JSON data to the endpoint.
Google Protocol Buffers support can now be added using the Protostuff library.
In Mule ESB I want to validate incoming SOAP/XML, using a standard Mule "schema-validation filter".
Something like:
<mulexml:schema-validation-filter schemaLocations="xxx.xsd" name="xxxValidationFilter"/>
However this kind of definition seem to assume that the schema is located in a separate xsd-file, whereas in a lot of cases the schema definition is embedded in the "wsdl:types" element of a wsdl-file.
Is there any way to use the Mule schema-validation-filter to validate against schema's which are embedded in the wsdl (except for copying the schema element definitions out of the
wsdl and into a separate xsd-file).
Mule service element tags which expose the service haave an attribute that can enable validation on the incoming request.
validationEnabled="true"
<cxf:simple-service validationEnabled="true"/>
<cxf:jaxws-service validationEnabled="true"/>
<cxf:proxy-service validationEnabled="true"/>
For more information refer to the following Mule documentation link.
http://www.mulesoft.org/documentation/display/current/Building+Web+Services+with+CXF
Hope this helps.
In my project, we consume webservices . What was confusing to me was there were some webservices(say A) that were called just using the HttpURLConnection and req/response was marshalled/unmarshalled using JAXB
There is another web service(say B) for which i see many classes with JAX WSRI and its not called using HttpURLConnection. I also see .wsdl files for these webservices.
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.1.1 in JDK 6
* Generated source version: 2.0
*
*/
#WebService(name = "ABPortType", targetNamespace "http://www.ups.com/WSDL/XOLTWS/DCR/v1.0")
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface ABCPortType {
#WebMethod(operationName = "ProcessAB", action = = "http://example.com/webservices/xxBinding/v1.0")
#WebResult(name = "xxResponse", targetNamespace = "http://xx.com/XMLSchema/XXWS/AB/v1.0", partName = "Body")
}
MY doubts are
Why are we calling the webservice B with all these extra bloat (end point, JAX WS RI instead of using HttpURLConnection?
can HttpULConnection be used to call this webservice B
For webservice A that is called using HttpURLConnection there is no WSDL (just jaxb classes created from xsd) but whreas the WS that is called using JAXWS RI generated classes has a WSDL. Are the web service A and B implemnted differentely and thats why we call them in different ways
Please help me understand
-Venkat
According to the order of your questions:
If you are using JAX-WS API, may be you want to generate client proxy classes from the WebService, e.g. using the wsimport tool for generate the client stubs from the WSDL document file. So that you work with Java objects and not with XML. Only in special cases, you need a XML handler for advanced features, such as WS-Security.
Yes. You need to work with the XML directly and use JAX-B for marshall/unmarshall the messages.
The WSDL document file describes the SOAP service and the signatures of all the operations available in the service. If A does not have a descriptor (the WSDL document file), may not use the JAX-WS API, e.g. Java WSDP, or the service provider is not exposing the WSDL.
I am trying to generate java classes that describe the web service offered here which belongs to this page. Please mind that I am not convinced that the XML is the one needed to run the following steps!
I save the XML of the API to a file: getcapabilities.xml
I run the following trang command to generate an XSD: java -jar trang.jar getcapabilities.xml getcapabilities.xsd
I get the following files: getcapabilities.xsd, ogc.xsd, wfs.xsd, xlink.xsd, xsi.xsd
I run the following command to generate java classes: xjc getcapabilities.xsd
The following error message is prompted
parsing a schema... [ERROR] no-xsi: The {target namespace} of an attribute declaration must not match 'http://www.w3.org/2001/XMLSchema-instance'.
line 7 of file:xsi.xsd
Failed to parse a schema.
Questions:
Do you get the same error message?
What can I do about it?
Is my approach meant to be successful at all?
You're dealing with an OGC Web Feature Service. There's a couple of peculiarities with that.
Don't generate you schemas with trang, you can get them from OGC: http://schemas.opengis.net/wfs/1.1.0/
You don't really have to compile these schemas on your own, you can get them precompiled from the OGC Schemas and Tools project (JARs are here).
WFS schemas only describe WFS operations - they are kind of container schemas. You'll also have an application profile which describes your features. You can obtain it via the DescribeFeatureType operation: http://data.wien.gv.at/daten/wfs?service=WFS&request=DescribeFeatureType&version=1.1.0
Consider using someting like GeoTools.