Skip to content

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
monodot committed Sep 4, 2022
1 parent 458bff7 commit 95abc47
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 159 deletions.
6 changes: 6 additions & 0 deletions simple-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ Then to run a test against a specific Camel version:
Here's a (non-exhaustive!) list of the scenarios included in this part of the repo, primarily for the benefit of people searching the web. Scenarios are usually where I do little POCs to prove something, or not.

- **CxfCustomNamespacePrefixTest** - This shows how to customise CXF to use specific prefixes when referring to namespaces. This was born out of a requirement where a legacy web service client was not able to understand unqualified values in XML attributes. CXF will try to set a default namespace where it can. If legacy clients don't fully understand this, then CXF behaviour can be customised by creating a CXF endpoint manually and setting namespaces. This scenario shows how.

## Other things

To generate client classes from WSDL:

mvn org.apache.cxf:cxf-codegen-plugin:wsdl2java
316 changes: 160 additions & 156 deletions simple-tests/src/main/resources/wsdl/BookService.wsdl
Original file line number Diff line number Diff line change
@@ -1,171 +1,175 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.cleverbuilder.com/BookService/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="BookService"
xmlns:tns="http://www.cleverbuilder.com/BookService/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
name="BookService"
targetNamespace="http://www.cleverbuilder.com/BookService/">
<wsdl:documentation>Definition for a web service called BookService,
which can be used to add or retrieve books from a collection.
</wsdl:documentation>
<wsdl:documentation>Definition for a web service called BookService,
which can be used to add or retrieve books from a collection.
</wsdl:documentation>

<!--
The `types` element defines the data types (XML elements)
that are used by the web service.
-->
<wsdl:types>
<xsd:schema targetNamespace="http://www.cleverbuilder.com/BookService/">
<xsd:element name="Book">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ID" type="xsd:string" minOccurs="0"/>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Books">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="tns:Book" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!--
The `types` element defines the data types (XML elements)
that are used by the web service.
-->
<wsdl:types>
<xsd:schema targetNamespace="http://www.cleverbuilder.com/BookService/">
<xsd:element name="Book">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ID" type="xsd:string" minOccurs="0"/>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Author" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Books">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="tns:Book" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="GetBook">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ID" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetBookResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="tns:Book" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetBook">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ID" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetBookResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="tns:Book" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="AddBook">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="tns:Book" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="AddBookResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="tns:Book" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetAllBooks">
<xsd:complexType />
</xsd:element>
<xsd:element name="GetAllBooksResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="tns:Book" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<xsd:element name="AddBook">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="tns:Book" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="AddBookResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="tns:Book" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="GetAllBooks">
<xsd:complexType/>
</xsd:element>
<xsd:element name="GetAllBooksResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="tns:Book" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>


<!--
A wsdl `message` element is used to define a message
exchanged between a web service, consisting of zero
or more `part`s.
-->
<!--
A wsdl `message` element is used to define a message
exchanged between a web service, consisting of zero
or more `part`s.
-->

<wsdl:message name="GetBookRequest">
<wsdl:part element="tns:GetBook" name="parameters" />
</wsdl:message>
<wsdl:message name="GetBookResponse">
<wsdl:part element="tns:GetBookResponse" name="parameters" />
</wsdl:message>
<wsdl:message name="AddBookRequest">
<wsdl:part name="parameters" element="tns:AddBook"></wsdl:part>
</wsdl:message>
<wsdl:message name="AddBookResponse">
<wsdl:part name="parameters" element="tns:AddBookResponse"></wsdl:part>
</wsdl:message>
<wsdl:message name="GetAllBooksRequest">
<wsdl:part name="parameters" element="tns:GetAllBooks"></wsdl:part>
</wsdl:message>
<wsdl:message name="GetAllBooksResponse">
<wsdl:part name="parameters" element="tns:GetAllBooksResponse"></wsdl:part>
</wsdl:message>
<wsdl:message name="GetBookRequest">
<wsdl:part element="tns:GetBook" name="parameters"/>
</wsdl:message>
<wsdl:message name="GetBookResponse">
<wsdl:part element="tns:GetBookResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="AddBookRequest">
<wsdl:part name="parameters" element="tns:AddBook"></wsdl:part>
</wsdl:message>
<wsdl:message name="AddBookResponse">
<wsdl:part name="parameters" element="tns:AddBookResponse"></wsdl:part>
</wsdl:message>
<wsdl:message name="GetAllBooksRequest">
<wsdl:part name="parameters" element="tns:GetAllBooks"></wsdl:part>
</wsdl:message>
<wsdl:message name="GetAllBooksResponse">
<wsdl:part name="parameters" element="tns:GetAllBooksResponse"></wsdl:part>
</wsdl:message>

<!--
A WSDL `portType` is used to combine multiple `message`s
(e.g. input, output) into a single operation.
<!--
A WSDL `portType` is used to combine multiple `message`s
(e.g. input, output) into a single operation.
Here we define three synchronous (input/output) operations
and the `message`s that must be used for each.
-->
<wsdl:portType name="BookService">
<wsdl:operation name="GetBook">
<wsdl:input message="tns:GetBookRequest" />
<wsdl:output message="tns:GetBookResponse" />
</wsdl:operation>
<wsdl:operation name="AddBook">
<wsdl:input message="tns:AddBookRequest"></wsdl:input>
<wsdl:output message="tns:AddBookResponse"></wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetAllBooks">
<wsdl:input message="tns:GetAllBooksRequest"></wsdl:input>
<wsdl:output message="tns:GetAllBooksResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
Here we define three synchronous (input/output) operations
and the `message`s that must be used for each.
-->
<wsdl:portType name="BookService">
<wsdl:operation name="GetBook">
<wsdl:input message="tns:GetBookRequest"/>
<wsdl:output message="tns:GetBookResponse"/>
</wsdl:operation>
<wsdl:operation name="AddBook">
<wsdl:input message="tns:AddBookRequest"></wsdl:input>
<wsdl:output message="tns:AddBookResponse"></wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetAllBooks">
<wsdl:input message="tns:GetAllBooksRequest"></wsdl:input>
<wsdl:output message="tns:GetAllBooksResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>

<!--
The `binding` element defines exactly how each
`operation` will take place over the network.
In this case, we are using SOAP.
-->
<wsdl:binding name="BookServiceSOAP" type="tns:BookService">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="GetBook">
<soap:operation soapAction="http://www.cleverbuilder.com/BookService/GetBook" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="AddBook">
<soap:operation soapAction="http://www.cleverbuilder.com/BookService/AddBook" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetAllBooks">
<soap:operation
soapAction="http://www.cleverbuilder.com/BookService/GetAllBooks" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<!--
The `binding` element defines exactly how each
`operation` will take place over the network.
In this case, we are using SOAP.
-->
<wsdl:binding name="BookServiceSOAP" type="tns:BookService">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetBook">
<soap:operation
soapAction="http://www.cleverbuilder.com/BookService/GetBook"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="AddBook">
<soap:operation
soapAction="http://www.cleverbuilder.com/BookService/AddBook"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetAllBooks">
<soap:operation
soapAction="http://www.cleverbuilder.com/BookService/GetAllBooks"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>

<!--
The `service` element finally says where the service
can be accessed from - in other words, its endpoint.
-->
<wsdl:service name="BookService">
<wsdl:port binding="tns:BookServiceSOAP" name="BookServiceSOAP">
<soap:address location="http://www.example.org/BookService" />
</wsdl:port>
</wsdl:service>
<!--
The `service` element finally says where the service
can be accessed from - in other words, its endpoint.
-->
<wsdl:service name="BookService">
<wsdl:port binding="tns:BookServiceSOAP" name="BookServiceSOAP">
<soap:address location="http://www.example.org/BookService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
package com.cleverbuilder.cameldemos.core;

public class PredicatesTest {
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

public class PredicatesTest extends CamelTestSupport {

@Test
public void testBodyIsNull() throws Exception {
MockEndpoint isNull = getMockEndpoint("mock:bodyisnull-isnull");
isNull.expectedMessageCount(1);

template.sendBodyAndHeader("direct:bodyisnulltest", null,
"MyCustomHeader", "foo");

assertMockEndpointsSatisfied();

}


@Override
protected RoutesBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:bodyisnulltest")
.choice().when(body().isNull())
.to("mock:bodyisnull-isnull")
.otherwise()
.to("mock:bodyisnull-otherwise");
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public void stopTestService() throws Exception {
endpoint.stop();
}

@EndpointInject(uri = "mock:output")
MockEndpoint mockOutput;
// @EndpointInject(uri = "mock:output")
// MockEndpoint mockOutput;

@Test
public void testInvokeSoapService() throws Exception {
MockEndpoint mockOutput = getMockEndpoint("mock:output");
mockOutput.expectedMessageCount(1);

template.sendBody("direct:start", null);
Expand Down

0 comments on commit 95abc47

Please sign in to comment.