LightJason - AgentSpeak(L++)
IBaseRest.java
Go to the documentation of this file.
1 /*
2  * @cond LICENSE
3  * ######################################################################################
4  * # LGPL License #
5  * # #
6  * # This file is part of the LightJason AgentSpeak(L++) #
7  * # Copyright (c) 2015-19, LightJason (info@lightjason.org) #
8  * # This program is free software: you can redistribute it and/or modify #
9  * # it under the terms of the GNU Lesser General Public License as #
10  * # published by the Free Software Foundation, either version 3 of the #
11  * # License, or (at your option) any later version. #
12  * # #
13  * # This program is distributed in the hope that it will be useful, #
14  * # but WITHOUT ANY WARRANTY; without even the implied warranty of #
15  * # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
16  * # GNU Lesser General Public License for more details. #
17  * # #
18  * # You should have received a copy of the GNU Lesser General Public License #
19  * # along with this program. If not, see http://www.gnu.org/licenses/ #
20  * ######################################################################################
21  * @endcond
22  */
23 
24 package org.lightjason.agentspeak.action.builtin.web.rest;
25 
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import com.fasterxml.jackson.dataformat.xml.XmlMapper;
29 
30 import javax.annotation.Nonnegative;
31 import javax.annotation.Nonnull;
32 import java.io.IOException;
33 import java.util.Map;
34 
35 
42 public abstract class IBaseRest extends IBaseWeb
43 {
47  private static final long serialVersionUID = -6606643839066144835L;
51  private static final ObjectMapper JSONMAPPER = new ObjectMapper();
55  private static final XmlMapper XMLMAPPER = new XmlMapper();
56 
61  protected IBaseRest( final int p_length )
62  {
63  super( p_length );
64  }
65 
66  @Nonnegative
67  @Override
68  public final int minimalArgumentNumber()
69  {
70  return 2;
71  }
72 
82  @Nonnull
83  protected static <T> T json( @Nonnull final String p_url, @Nonnull final Class<T> p_class ) throws IOException
84  {
85  return JSONMAPPER.readValue( IBaseRest.httpgetexecute( p_url ), p_class );
86  }
87 
96  @Nonnull
97  @SuppressWarnings( "unchecked" )
98  protected static Map<String, ?> xml( @Nonnull final String p_url ) throws IOException
99  {
100  return XMLMAPPER.readValue( IBaseRest.httpgetexecute( p_url ), Map.class );
101  }
102 
103 }
final int minimalArgumentNumber()
minimum number of arguments
Definition: IBaseRest.java:68
static Map< String, ?> xml( @Nonnull final String p_url)
reads a xml structure from an url
Definition: IBaseRest.java:98
static String httpgetexecute( @Nonnull final String p_url)
execute http-get request
Definition: IBaseWeb.java:121
base class to read data from the restful service
Definition: IBaseRest.java:42
static< T > T json( @Nonnull final String p_url, @Nonnull final Class< T > p_class)
reads a json structure from an url
Definition: IBaseRest.java:83
static final ObjectMapper JSONMAPPER
json mapper
Definition: IBaseRest.java:51