<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WSDL &#8211; My Shitty Code</title>
	<atom:link href="https://myshittycode.com/tag/wsdl/feed/" rel="self" type="application/rss+xml" />
	<link>https://myshittycode.com</link>
	<description>Embracing the Messiness in Search of Epic Solutions</description>
	<lastBuildDate>Fri, 06 Jan 2023 17:20:02 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://myshittycode.com/wp-content/uploads/2022/04/cropped-icon-32x32.png</url>
	<title>WSDL &#8211; My Shitty Code</title>
	<link>https://myshittycode.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">205304208</site>	<item>
		<title>Spring Web Services: Client Integration Testing with MockWebServiceServer</title>
		<link>https://myshittycode.com/2014/04/02/spring-web-services-client-integration-testing-with-mockwebserviceserver/</link>
					<comments>https://myshittycode.com/2014/04/02/spring-web-services-client-integration-testing-with-mockwebserviceserver/#comments</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Thu, 03 Apr 2014 02:23:42 +0000</pubDate>
				<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Spring Web Services]]></category>
		<category><![CDATA[WSDL]]></category>
		<guid isPermaLink="false">http://myshittycode.com/?p=468</guid>

					<description><![CDATA[<p>Spring Web Services provides a great way to perform web service client integration tests. However, the example in the documentation requires the client class to extend org.springframework.ws.client.core.support.WebServiceGatewaySupport, which is rather ugly. Instead, I prefer to have WebServiceTemplate injected into my client class. So, I made a slight tweak to my integration test to work this [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2014/04/02/spring-web-services-client-integration-testing-with-mockwebserviceserver/">Spring Web Services: Client Integration Testing with MockWebServiceServer</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Spring Web Services provides a great way to perform <a href="http://docs.spring.io/spring-ws/site/reference/html/client.html" target="_blank" rel="noopener">web service client integration tests</a>. However, the example in the documentation requires the client class to extend <b>org.springframework.ws.client.core.support.WebServiceGatewaySupport</b>, which is rather ugly. Instead, I prefer to have <b>WebServiceTemplate</b> injected into my client class.</p>



<p>So, I made a slight tweak to my integration test to work this work&#8230;</p>



<h2 class="wp-block-heading">Production Code To Be Tested</h2>



<p>First, we need the following Spring Web Services dependency:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; title: ; notranslate">
&lt;dependency&gt;
    &lt;groupid&gt;org.springframework.ws&lt;/groupid&gt;
    &lt;artifactid&gt;spring-ws-core&lt;/artifactid&gt;
    &lt;version&gt;2.1.4.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
</pre></div>


<p>Let&#8217;s assume the client class looks like this:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: java; title: ; notranslate">
@Service
public class WSClientServiceImpl implements WSClientService {

    private WebServiceTemplate webServiceTemplate;

    @Autowired
    public WSClientServiceImpl(WebServiceTemplate webServiceTemplate) {
        this.webServiceTemplate = webServiceTemplate;
    }

    public String login(String username, String password) {
        Login login = new ObjectFactory().createLogin();
        login.setUsername(username);
        login.setPassword(password);

        SoapActionCallback callback = new SoapActionCallback(&quot;http://webservice/login&quot;);
        Object object = webServiceTemplate.marshalSendAndReceive(login, callback);

        JAXBElement&lt;string&gt; jaxbElement = (JAXBElement&lt;string&gt;) object;
        String sessionId = jaxbElement.getValue();

        return sessionId;
    }
}
</pre></div>


<p>The <b>WebServiceTemplate</b> bean is configured like this:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; title: ; notranslate">
&lt;beans ...=&quot;&quot;&gt;
    &lt;context:component-scan base-package=&quot;com.choonchernlim.epicapp&quot;&gt;


    &lt;bean id=&quot;marshaller&quot; class=&quot;org.springframework.oxm.jaxb.Jaxb2Marshaller&quot;&gt;
        &lt;property name=&quot;contextPaths&quot;&gt;
            &lt;list&gt;
                &lt;value&gt;...&lt;/value&gt;
            &lt;/list&gt;
        &lt;/property&gt;
    &lt;/bean&gt;

    &lt;bean id=&quot;webServiceTemplate&quot; class=&quot;org.springframework.ws.client.core.WebServiceTemplate&quot;&gt;
        &lt;property name=&quot;marshaller&quot; ref=&quot;marshaller&quot;&gt;
        &lt;property name=&quot;unmarshaller&quot; ref=&quot;marshaller&quot;&gt;
        &lt;property name=&quot;defaultUri&quot; value=&quot;http://webservice&quot;&gt;
    &lt;/property&gt;&lt;/property&gt;&lt;/property&gt;&lt;/bean&gt;
&lt;/context:component-scan&gt;&lt;/beans&gt;
</pre></div>


<h2 class="wp-block-heading">Constructing Integration Test</h2>



<p>Make sure we have the Spring Web Services Test framework dependency:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; title: ; notranslate">
&lt;dependency&gt;
    &lt;groupid&gt;org.springframework.ws&lt;/groupid&gt;
    &lt;artifactid&gt;spring-ws-test&lt;/artifactid&gt;
    &lt;version&gt;2.1.4.RELEASE&lt;/version&gt;
    &lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
</pre></div>


<p>The integration test looks similar to the example in the Spring documentation, however, I injected <b>WebServiceTemplate</b> instead:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: java; title: ; notranslate">
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({&quot;classpath*:applicationContext.xml&quot;})
public class WSClientServiceImplTest {

    @Autowired
    private WSClientService wsClientService;

    @Autowired
    private WebServiceTemplate webServiceTemplate;

    private MockWebServiceServer mockServer;

    @Before
    public void createServer() throws Exception {
        mockServer = MockWebServiceServer.createServer(webServiceTemplate);
    }

    @Test
    public void testLogin() {
        Source requestPayload = new StringSource(
                &quot;&lt;ns2:login xmlns:ns2=&quot;http://webservice/login&quot;&gt;&quot; +
                &quot;  &lt;ns2:username&gt;user&lt;/ns2:username&gt;&quot; +
                &quot;  &lt;ns2:password&gt;password&lt;/ns2:password&gt;&quot; +
                &quot;&lt;/ns2:login&gt;&quot;
        );

        Source responsePayload = new StringSource(
                &quot;&lt;sessionid xmlns=&quot;http://webservice/login&quot;&gt;12345&lt;/sessionid&gt;&quot;
        );

        mockServer.expect(payload(requestPayload)).andRespond(withPayload(responsePayload));

        String sessionId = wsClientService.login(&quot;user&quot;, &quot;password&quot;);

        assertThat(sessionId, is(&quot;12345&quot;));

        mockServer.verify();
    }
}
</pre></div><p>The post <a rel="nofollow" href="https://myshittycode.com/2014/04/02/spring-web-services-client-integration-testing-with-mockwebserviceserver/">Spring Web Services: Client Integration Testing with MockWebServiceServer</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2014/04/02/spring-web-services-client-integration-testing-with-mockwebserviceserver/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">468</post-id>	</item>
		<item>
		<title>The message with Action &#8221; cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher</title>
		<link>https://myshittycode.com/2013/10/01/the-message-with-action-cannot-be-processed-at-the-receiver-due-to-a-contractfilter-mismatch-at-the-endpointdispatcher/</link>
					<comments>https://myshittycode.com/2013/10/01/the-message-with-action-cannot-be-processed-at-the-receiver-due-to-a-contractfilter-mismatch-at-the-endpointdispatcher/#comments</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Tue, 01 Oct 2013 20:29:25 +0000</pubDate>
				<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring Web Services]]></category>
		<category><![CDATA[WSDL]]></category>
		<guid isPermaLink="false">http://myshittycode.com/?p=96</guid>

					<description><![CDATA[<p>PROBLEM You get this error message when invoking a web service:- org.springframework.ws.soap.client.SoapFaultClientException: The message with Action &#8221; cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2013/10/01/the-message-with-action-cannot-be-processed-at-the-receiver-due-to-a-contractfilter-mismatch-at-the-endpointdispatcher/">The message with Action &#8221; cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">PROBLEM</h2>



<p>You get this error message when invoking a web service:-</p>



<p><b>org.springframework.ws.soap.client.SoapFaultClientException: The message with Action &#8221; cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</b></p>



<h2 class="wp-block-heading">SOLUTION</h2>



<p>You forgot to specify the SOAP action before invoking the web service.</p>



<p>Open your WSDL file and search for the operation you are trying to invoke. You should see something like this:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; highlight: [7]; title: ; notranslate">
&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?--&gt;
&lt;wsdl:definitions ...=&quot;&quot;&gt;
	...
    &lt;wsdl:binding ...=&quot;&quot;&gt;
		...
        &lt;wsdl:operation name=&quot;OhMyGawd&quot;&gt;
            &lt;soap:operation soapaction=&quot;http://oh.my.gawd&quot;&gt;
			...
        &lt;/soap:operation&gt;&lt;/wsdl:operation&gt;
    &lt;/wsdl:binding&gt;
	...
&lt;/wsdl:definitions&gt;
</pre></div>


<p>Take note of the <b>soapAction</b> value, in this example, it is <b>http://oh.my.gawd</b>.</p>



<p>If you are using Spring Web Services, add the following lines:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: java; highlight: [13]; title: ; notranslate">
@Autowired
private WebServiceTemplate webServiceTemplate;

public void run() {
	ObjectFactory objectFactory = new ObjectFactory();

	// Create the request payload
	OhMyGawd ohMyGawd = objectFactory.createOhMyGawd();
	ohMyGawd.setValue(...);

    OhMyGawdResponse response = (OhMyGawdResponse) webServiceTemplate.marshalSendAndReceive(
            ohMyGawd,
			new SoapActionCallback(&quot;http://oh.my.gawd&quot;)
	);

	...
}
</pre></div><p>The post <a rel="nofollow" href="https://myshittycode.com/2013/10/01/the-message-with-action-cannot-be-processed-at-the-receiver-due-to-a-contractfilter-mismatch-at-the-endpointdispatcher/">The message with Action &#8221; cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2013/10/01/the-message-with-action-cannot-be-processed-at-the-receiver-due-to-a-contractfilter-mismatch-at-the-endpointdispatcher/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">96</post-id>	</item>
		<item>
		<title>Cannot process the message because the content type &#8216;application/soap+xml; charset=utf-8&#8217; was not the expected type &#8216;text/xml; charset=utf-8&#8217;</title>
		<link>https://myshittycode.com/2013/10/01/cannot-process-the-message-because-the-content-type-applicationsoapxml-charsetutf-8-was-not-the-expected-type-textxml-charsetutf-8/</link>
					<comments>https://myshittycode.com/2013/10/01/cannot-process-the-message-because-the-content-type-applicationsoapxml-charsetutf-8-was-not-the-expected-type-textxml-charsetutf-8/#comments</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Tue, 01 Oct 2013 19:54:08 +0000</pubDate>
				<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring Web Services]]></category>
		<category><![CDATA[WSDL]]></category>
		<guid isPermaLink="false">http://myshittycode.com/?p=88</guid>

					<description><![CDATA[<p>PROBLEM You are getting this exception when invoking a web service:- org.springframework.ws.client.WebServiceTransportException: Cannot process the message because the content type &#8216;application/soap+xml; charset=utf-8&#8217; was not the expected type &#8216;text/xml; charset=utf-8&#8217;. [415] SOLUTION You are using the wrong SOAP version. SOAP v1.1 uses text/xml while SOAP v1.2 uses application/soap+xml. If you are using Spring Web Services, add [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2013/10/01/cannot-process-the-message-because-the-content-type-applicationsoapxml-charsetutf-8-was-not-the-expected-type-textxml-charsetutf-8/">Cannot process the message because the content type &#8216;application/soap+xml; charset=utf-8&#8217; was not the expected type &#8216;text/xml; charset=utf-8&#8217;</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">PROBLEM</h2>



<p>You are getting this exception when invoking a web service:-</p>



<p><b>org.springframework.ws.client.WebServiceTransportException: Cannot process the message because the content type &#8216;application/soap+xml; charset=utf-8&#8217; was not the expected type &#8216;text/xml; charset=utf-8&#8217;. [415]</b></p>



<h2 class="wp-block-heading">SOLUTION</h2>



<p>You are using the wrong SOAP version. <a href="http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383526" target="_blank" rel="noopener">SOAP v1.1</a> uses <b>text/xml</b> while <a href="http://www.w3.org/TR/2002/CR-soap12-part2-20021219/#ietf-draft" target="_blank" rel="noopener">SOAP v1.2</a> uses <b>application/soap+xml</b>.</p>



<p>If you are using Spring Web Services, add the following lines:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; highlight: [7,8,9,10,11,12,17]; title: ; notranslate">
&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?--&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:util=&quot;http://www.springframework.org/schema/util&quot; xmlns:oxm=&quot;http://www.springframework.org/schema/oxm&quot; xsi:schemalocation=&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd&quot;&gt;

	&lt;!-- Configure the SOAP version to 1.1 --&gt;
    &lt;bean id=&quot;soapMessageFactory&quot; class=&quot;org.springframework.ws.soap.saaj.SaajSoapMessageFactory&quot;&gt;
        &lt;property name=&quot;soapVersion&quot;&gt;
            &lt;util:constant static-field=&quot;org.springframework.ws.soap.SoapVersion.SOAP_11&quot;&gt;
        &lt;/util:constant&gt;&lt;/property&gt;
    &lt;/bean&gt;

    &lt;oxm:jaxb2-marshaller id=&quot;marshaller&quot; contextpath=&quot;myproject.wsdl.ws&quot;&gt;

    &lt;bean id=&quot;webServiceTemplate&quot; class=&quot;org.springframework.ws.client.core.WebServiceTemplate&quot;&gt;
        &lt;constructor-arg ref=&quot;soapMessageFactory&quot;&gt;
        &lt;property name=&quot;marshaller&quot; ref=&quot;marshaller&quot;&gt;
        &lt;property name=&quot;unmarshaller&quot; ref=&quot;marshaller&quot;&gt;
        &lt;property name=&quot;defaultUri&quot; value=&quot;http://my.web.service?wsdl&quot;&gt;
    &lt;/property&gt;&lt;/property&gt;&lt;/property&gt;&lt;/constructor-arg&gt;&lt;/bean&gt;
&lt;/oxm:jaxb2-marshaller&gt;&lt;/beans&gt;
</pre></div><p>The post <a rel="nofollow" href="https://myshittycode.com/2013/10/01/cannot-process-the-message-because-the-content-type-applicationsoapxml-charsetutf-8-was-not-the-expected-type-textxml-charsetutf-8/">Cannot process the message because the content type &#8216;application/soap+xml; charset=utf-8&#8217; was not the expected type &#8216;text/xml; charset=utf-8&#8217;</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2013/10/01/cannot-process-the-message-because-the-content-type-applicationsoapxml-charsetutf-8-was-not-the-expected-type-textxml-charsetutf-8/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">88</post-id>	</item>
		<item>
		<title>Using Spring Web Services and JAXB to Invoke Web Service Based on WSDL</title>
		<link>https://myshittycode.com/2013/10/01/using-spring-web-services-and-jaxb-to-invoke-web-service-based-on-wsdl/</link>
					<comments>https://myshittycode.com/2013/10/01/using-spring-web-services-and-jaxb-to-invoke-web-service-based-on-wsdl/#comments</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Tue, 01 Oct 2013 13:17:11 +0000</pubDate>
				<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JAXB 2]]></category>
		<category><![CDATA[JAXB-2 Maven Plugin]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Spring Web Services]]></category>
		<category><![CDATA[Web Service]]></category>
		<category><![CDATA[WSDL]]></category>
		<guid isPermaLink="false">http://myshittycode.com/?p=80</guid>

					<description><![CDATA[<p>There are several ways to consume a web service based on a WSDL from Java. After trying a couple of approaches, I&#8217;m currently leaning towards Spring Web Services and JAXB. The biggest advantage of using both Spring Web Services and JAXB to consume a web service is the flexibility to change the web service URL [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2013/10/01/using-spring-web-services-and-jaxb-to-invoke-web-service-based-on-wsdl/">Using Spring Web Services and JAXB to Invoke Web Service Based on WSDL</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>There are several ways to consume a web service based on a WSDL from Java. After trying a couple of approaches, I&#8217;m currently leaning towards Spring Web Services and JAXB. The biggest advantage of using both Spring Web Services and JAXB to consume a web service is the flexibility to change the web service URL without the need to regenerate the needed Java files, especially if you have a different web service URL for each environment (DEV, TEST and PROD).</p>



<p>In this tutorial, I&#8217;m going to consume this freely available web service that allows me to convert the currency rate from one country to another: http://www.webservicex.net/CurrencyConvertor.asmx?WSDL</p>



<h2 class="wp-block-heading">currency.wsdl <b>( src/main/resources )</b></h2>



<p>The first step is to open the WSDL link on the browser and save a copy of it. In this example, I&#8217;m saving it as <b>currency.wsdl</b>.</p>



<p>Your project structure should look something like this:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
myproject
|- src
|  |- main
|     |- java
|     |  |- myproject
|     |- resources
|        |- currency.wsdl
|- pom.xml
</pre></div>


<h2 class="wp-block-heading">pom.xml</h2>



<p>Add Spring Web Services dependency and configure JAXB-2 Maven plugin to generate the Java files based on the WSDL.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; title: ; notranslate">
&lt;project&gt;
	...
	&lt;dependencies&gt;
	    &lt;dependency&gt;
	        &lt;groupid&gt;org.springframework.ws&lt;/groupid&gt;
	        &lt;artifactid&gt;spring-ws-core&lt;/artifactid&gt;
	        &lt;version&gt;2.1.2.RELEASE&lt;/version&gt;
	    &lt;/dependency&gt;
	&lt;/dependencies&gt;

    &lt;build&gt;
        &lt;plugins&gt;
			...

            &lt;plugin&gt;
                &lt;groupid&gt;org.codehaus.mojo&lt;/groupid&gt;
                &lt;artifactid&gt;jaxb2-maven-plugin&lt;/artifactid&gt;
                &lt;version&gt;1.5&lt;/version&gt;
                &lt;executions&gt;
                    &lt;execution&gt;
                        &lt;id&gt;xjc&lt;/id&gt;
                        &lt;goals&gt;
                            &lt;goal&gt;xjc&lt;/goal&gt;
                        &lt;/goals&gt;
                    &lt;/execution&gt;
                &lt;/executions&gt;
                &lt;configuration&gt;
					&lt;!-- Package to store the generated file --&gt;
                    &lt;packagename&gt;myproject.wsdl.currency&lt;/packagename&gt;
					&lt;!-- Treat the input as WSDL --&gt;
                    &lt;wsdl&gt;true&lt;/wsdl&gt;
                    &lt;!-- Input is not XML schema --&gt;
					&lt;xmlschema&gt;false&lt;/xmlschema&gt;
                    &lt;!-- The WSDL file that you saved earlier --&gt;
                    &lt;schemafiles&gt;currency.wsdl&lt;/schemafiles&gt;
                    &lt;!-- The location of the WSDL file --&gt;
					&lt;schemadirectory&gt;${project.basedir}/src/main/resources&lt;/schemadirectory&gt;
                    &lt;!-- The output directory to store the generated Java files --&gt;
					&lt;outputdirectory&gt;${project.basedir}/src/main/java&lt;/outputdirectory&gt;
                    &lt;!-- Don&#039;t clear output directory on each run --&gt;
                    &lt;clearoutputdir&gt;false&lt;/clearoutputdir&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;
        &lt;/plugins&gt;
    &lt;/build&gt;
&lt;/project&gt;
</pre></div>


<p>Setting <b>clearOutputDir</b> to <b>false</b> is very important. If this is set to <b>true</b> and there&#8217;s a silly error in the JAXB-2 Maven plugin configuration, your output directory will be wiped clean. Since the output directory points to <b>${project.basedir}/src/main/java</b>, we want to make sure we don&#8217;t lose all of our existing Java files.</p>



<h2 class="wp-block-heading">Generating Java Files Based on WSDL</h2>



<p>While you can run <b>mvn clean jaxb2:xjc</b> to generate the Java files, the easier way is to just run <b>mvn clean compile</b>. You should see a similar Maven output in your console:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; title: ; notranslate">
&#x5B;INFO] ------------------------------------------------------------------------
&#x5B;INFO] Building myproject 1.0
&#x5B;INFO] ------------------------------------------------------------------------
&#x5B;INFO]
&#x5B;INFO] --- jaxb2-maven-plugin:1.5:xjc (xjc) @ myproject ---
&#x5B;INFO] Generating source...
&#x5B;INFO] parsing a schema...
&#x5B;INFO] compiling a schema...
&#x5B;INFO] myproject/wsdl/currency/ConversionRate.java
&#x5B;INFO] myproject/wsdl/currency/ConversionRateResponse.java
&#x5B;INFO] myproject/wsdl/currency/Currency.java
&#x5B;INFO] myproject/wsdl/currency/ObjectFactory.java
&#x5B;INFO] myproject/wsdl/currency/package-info.java
&#x5B;INFO]
</pre></div>


<p>Your project structure should look something like this:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
myproject
|- src
|  |- main
|     |- java
|     |  |- myproject
|     |     |- wsdl
|     |        |- currency
|     |           |- ConversionRate.java
|     |           |- ConversionRateResponse.java
|     |           |- Currency.java
|     |           |- ObjectFactory.java
|     |           |- package-info.java
|     |- resources
|        |- currency.wsdl
|- pom.xml
</pre></div>


<h2 class="wp-block-heading">applicationContext.xml <b>( src/main/resources )</b></h2>



<p>Once we have the generated Java files, the next step is to configure Spring Web Services.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; title: ; notranslate">
&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?--&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:context=&quot;http://www.springframework.org/schema/context&quot; xmlns:oxm=&quot;http://www.springframework.org/schema/oxm&quot; xmlns:util=&quot;http://www.springframework.org/schema/util&quot; xsi:schemalocation=&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd&quot;&gt;

    &lt;context:component-scan base-package=&quot;myproject&quot;&gt;

	&lt;!-- Define the SOAP version used by the WSDL --&gt;
    &lt;bean id=&quot;soapMessageFactory&quot; class=&quot;org.springframework.ws.soap.saaj.SaajSoapMessageFactory&quot;&gt;
        &lt;property name=&quot;soapVersion&quot;&gt;
            &lt;util:constant static-field=&quot;org.springframework.ws.soap.SoapVersion.SOAP_12&quot;&gt;
        &lt;/util:constant&gt;&lt;/property&gt;
    &lt;/bean&gt;

	&lt;!-- The location of the generated Java files --&gt;
    &lt;oxm:jaxb2-marshaller id=&quot;marshaller&quot; contextpath=&quot;myproject.wsdl.currency&quot;&gt;

	&lt;!-- Configure Spring Web Services --&gt;
    &lt;bean id=&quot;webServiceTemplate&quot; class=&quot;org.springframework.ws.client.core.WebServiceTemplate&quot;&gt;
        &lt;constructor-arg ref=&quot;soapMessageFactory&quot;&gt;
        &lt;property name=&quot;marshaller&quot; ref=&quot;marshaller&quot;&gt;
        &lt;property name=&quot;unmarshaller&quot; ref=&quot;marshaller&quot;&gt;
        &lt;property name=&quot;defaultUri&quot; value=&quot;http://www.webservicex.net/CurrencyConvertor.asmx?WSDL&quot;&gt;
    &lt;/property&gt;&lt;/property&gt;&lt;/property&gt;&lt;/constructor-arg&gt;&lt;/bean&gt;
&lt;/oxm:jaxb2-marshaller&gt;&lt;/context:component-scan&gt;&lt;/beans&gt;
</pre></div>


<h2 class="wp-block-heading">CurrentService.java <b>( src/main/java/myproject/service )</b></h2>



<p>In the Service class, we will use Spring Web Services <b>WebServiceTemplate</b> to call the web service.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: java; title: ; notranslate">
@Service
public class CurrencyService {
    @Autowired
    private WebServiceTemplate webServiceTemplate;

    public Double getConversionRate(Currency fromCurrency, Currency toCurrency) {
        ConversionRate conversionRate = new ObjectFactory().createConversionRate();
        conversionRate.setFromCurrency(fromCurrency);
        conversionRate.setToCurrency(toCurrency);

        ConversionRateResponse response = (ConversionRateResponse) webServiceTemplate.marshalSendAndReceive(
                conversionRate);

        return response.getConversionRateResult();
    }
}
</pre></div>


<h2 class="wp-block-heading">Main.java <b>( src/main/java/myproject/main )</b></h2>



<p>This is the main runner class.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: java; title: ; notranslate">
public class Main {
    private static Logger log = Logger.getLogger(Main.class);

    public static void main(String&#x5B;] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext(&quot;applicationContext.xml&quot;);
        CurrencyService currencyService = context.getBean(CurrencyService.class);

        Currency fromCurrency = Currency.USD;
        Currency toCurrency = Currency.GBP;
        Double conversionRate = currencyService.getConversionRate(fromCurrency, toCurrency);

        log.info(String.format(&quot;The conversion rate from %s to %s is %s.&quot;, fromCurrency, toCurrency, conversionRate));
    }
}
</pre></div>


<h2 class="wp-block-heading">Project Structure</h2>



<p>Your project structure should look something like this:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
myproject
|- src
|  |- main
|     |- java
|     |  |- myproject
|     |     |- main
|     |        |- Main.java
|     |     |- service
|     |        |- CurrencyService.java
|     |     |- wsdl
|     |        |- currency
|     |           |- ConversionRate.java
|     |           |- ConversionRateResponse.java
|     |           |- Currency.java
|     |           |- ObjectFactory.java
|     |           |- package-info.java
|     |- resources
|        |- currency.wsdl
|- pom.xml
</pre></div>


<h2 class="wp-block-heading">Result</h2>



<p>When you run <b>Main.java</b>, you should see a result similar to this:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
The conversion rate from USD to GBP is 0.6178.
</pre></div><p>The post <a rel="nofollow" href="https://myshittycode.com/2013/10/01/using-spring-web-services-and-jaxb-to-invoke-web-service-based-on-wsdl/">Using Spring Web Services and JAXB to Invoke Web Service Based on WSDL</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2013/10/01/using-spring-web-services-and-jaxb-to-invoke-web-service-based-on-wsdl/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">80</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)
Database Caching using Disk

Served from: myshittycode.com @ 2026-02-19 10:00:46 by W3 Total Cache
-->