Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • delight delight
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Merge requests 0
    • Merge requests 0
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Commits
Collapse sidebar
  • delight
  • delightdelight
  • Wiki
  • Xmlrpc
  • ExampleUsingThirdPartyTypes

ExampleUsingThirdPartyTypes · Changes

Page history
started documentation of json-over-http delight authored Mar 05, 2019 by Andreas Lauer's avatar Andreas Lauer
Hide whitespace changes
Inline Side-by-side
xmlrpc/ExampleUsingThirdPartyTypes.md 0 → 100644
View page @ 91ec85b6
## [Home](https://git.opendfki.de/delight/delight/wikis/Home) | [Documentation](https://git.opendfki.de/delight/delight/wikis/Documentation) | [People / Contact](https://git.opendfki.de/delight/delight/wikis/people)
---
### Using Third Party Types in your API
Eventually, you want to use third party types in your remote calls. Unfortunately the nice annotation features we saw in [Using own concrete types in your API](ExampleUsingOwnConceteTypes) and [Using interface or abstract types in your API](ExampleUsingOwnInterfaceTypes) are not applicable here because you are neither allowed to modify the classes nor makes it sense to add an additional dependency to that type.
The Delight XML-RPC framework offers a solution to this problem by offering conversion mappings to be declared with the API (of course you can add as many mappings as you want):
```java
@ConverterMappings(
@Mapping(type=URL.class,converter=URLConverter.class)
)
public interface Api
{
URL getHomepageLocation();
void addSite( URL url );
}
```
We have to define a standalone converter to transfer instances of type URL to a XML-RPC representation and vice versa.
Therefor, the converter has to implemente the interface ''ParameterConverter'' to define three methods:
- getXmlRpcRepresentationType(): states what XML-RPC type will be used as transport representation
- createFrom(): takes a XML-RPC representation and creates a corresponding instance of type ''URL''.
- toXmlRpc(): takes an instance of type ''URL'' and converts it into it's XML-RPC representation.
See the complete class here:
```java
public class URLConverter implements ParameterConverter<URL, String>
{
public Type getXmlRpcRepresentationType() { return( XmlRpc.Type.STRING ); }
public URL createFrom( String xmlRepresentation )
throws TypeConversionException
{ ...
}
public String toXmlRpc( URL param )
throws TypeConversionException
{
return( param.toExternalForm() );
}
}
```
Now, without having to modify it, the type ''URL'' can be used in XML-RPC calls.
```java
Api remote_api = XmlRpc.createClient( Api.class, "handlerId", host, port );
URL homepageUrl = remote_api.getHomepageLocation();
InputStream is = homepageUrl.openStream();
...
remote_api.addSite( new URL( "http://middle.of.nowhere" ) );
...
```
See also: [Using own concrete types in your API](ExampleUsingOwnConceteTypes) how to use own types contained in Collections an Maps].
Examples in source code: [here](https://git.opendfki.de/delight/delight/tree/master/example-delight-webapp)
\ No newline at end of file
Clone repository
  • DocuFeature
  • ExampleServer
  • ExampleWebApp
  • Home
  • ServerSentEventsFeature
  • StatsFeature
  • people
  • xmlrpc
    • Documentation
    • ExampleUsingConverterRegistry
    • ExampleUsingOwnConceteTypes
    • ExampleUsingOwnInterfaceTypes
    • ExampleUsingThirdPartyTypes
    • ExampleUsingXmlRpcBeans
    • ExampleUsingXmlRpcCompliantTypes

Legal Notice, Imprint, Privacy Policy