All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.webcohesion.enunciate.modules.java_json_client.library_description.fmt Maven / Gradle / Ivy

[#ftl]
[#--

    Copyright © 2006-2016 Web Cohesion ([email protected])

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

--]
[#-- @ftlvariable name="sample_resource" type="com.webcohesion.enunciate.api.resources.Method" --]

The Java client-side library is used to provide the set of Java objects that can be serialized to/from JSON using Jackson. This is useful for accessing the JSON REST endpoints that are published by this application.

[#if sample_resource??] [#if sample_resource.responseEntity??]
Resources Example (Raw JAXB)
java.net.URL url = new java.net.URL(baseURL + "${sample_resource.resource.path}");
ObjectMapper mapper = new ObjectMapper();
java.net.URLConnection connection = url.openConnection();
[#if sample_resource.requestEntity??]
connection.setDoOutput(true);
[/#if]
connection.connect();

[#if sample_resource.requestEntity??]
mapper.writeValue(connection.getOutputStream(), ${simpleNameFor(sample_resource.requestEntity, false)?uncap_first?html});
[/#if]
${simpleNameFor(sample_resource.responseEntity, false)?html} result = (${simpleNameFor(sample_resource.responseEntity, false)?html}) mapper.readValue( connection.getInputStream(), ${simpleNameFor(sample_resource.responseEntity, false)?html}.class );
//handle the result as needed...
    
Resources Example (Jersey client)
jakarta.ws.rs.client.Client client = jakarta.ws.rs.client.ClientBuilder.newClient();

${simpleNameFor(sample_resource.responseEntity, false)?html} result = client.target(baseUrl + "${sample_resource.resource.path}")
  .${sample_resource.httpMethod?lower_case}([#if sample_resource.requestEntity??]jakarta.ws.rs.client.Entity.entity(${simpleNameFor(sample_resource.requestEntity, false)?uncap_first?html}, "${mediaTypeFor(sample_resource.requestEntity)}"), [/#if]${simpleNameFor(sample_resource.responseEntity, false)?html}.class);

//handle the result as needed...
    
[/#if] [/#if]




© 2015 - 2024 Weber Informatics LLC | Privacy Policy