24 package org.lightjason.agentspeak.action.builtin.web;
26 import org.apache.http.client.methods.HttpGet;
27 import org.apache.http.client.methods.HttpPost;
28 import org.apache.http.client.methods.HttpRequestBase;
29 import org.apache.http.impl.client.HttpClientBuilder;
30 import org.apache.http.util.EntityUtils;
39 import javax.annotation.Nonnull;
40 import javax.annotation.Nullable;
41 import java.io.IOException;
42 import java.util.Collection;
44 import java.util.Objects;
45 import java.util.Stack;
46 import java.util.stream.Collectors;
47 import java.util.stream.Stream;
76 protected static HttpPost
httppost( @Nonnull
final String p_url )
78 return header(
new HttpPost( p_url ) );
87 protected static HttpGet
httpget( @Nonnull
final String p_url )
89 return header(
new HttpGet( p_url ) );
99 private static <T extends HttpRequestBase> T
header( @Nonnull
final T p_request )
103 ( Objects.isNull( System.getProperty(
"http.agent" ) ) ) || ( System.getProperty(
"http.agent" ).isEmpty() )
105 : System.getProperty(
"http.agent" )
121 protected static String
httpgetexecute( @Nonnull
final String p_url )
throws IOException
123 return EntityUtils.toString( HttpClientBuilder.create().build().execute(
httpget( p_url ) ).getEntity() );
133 protected static String
httpgetexecute( @Nonnull
final HttpGet p_get )
throws IOException
135 return EntityUtils.toString( HttpClientBuilder.create().build().execute( p_get ).getEntity() );
145 protected static String
httppostexecute( @Nonnull
final HttpPost p_post )
throws IOException
147 return EntityUtils.toString( HttpClientBuilder.create().build().execute( p_post ).getEntity() );
159 protected static ITerm baseliteral( @Nonnull
final Stream<String> p_functor, @Nonnull
final Stream<ITerm> p_values )
161 final Stack<String> l_tree = p_functor.collect( Collectors.toCollection( Stack::new ) );
164 while ( !l_tree.isEmpty() )
177 @SuppressWarnings(
"unchecked" )
180 if ( ( Objects.isNull( p_object ) ) || ( ( p_object instanceof Map ) && ( ( (Map<String, ?>) p_object ).isEmpty() ) ) )
181 return Stream.empty();
183 return p_object instanceof Map
184 ?
flatmap( (Map<String, ?>) p_object )
185 : p_object instanceof Collection
199 private static Stream<ITerm>
flatmap( @Nonnull
final Map<String, ?> p_map )
201 return p_map.entrySet()
205 i.getKey().toLowerCase().replaceAll(
"[^([a-z][0-9]\\-/_)]]",
"_" ),
218 private static Stream<ITerm>
flatcollection( @Nonnull
final Collection<?> p_collection )
static ResourceBundle configuration()
returns the property data of the package
static Stream< ITerm > flatcollection( @Nonnull final Collection<?> p_collection)
transforms a collection into a term stream
base class of build-in actions for setting name by package/classname (without prefix character) ...
static HttpGet httpget( @Nonnull final String p_url)
returns a http-get connection
IBaseWeb(final int p_length)
ctor
static Stream< ITerm > flatterm( @Nullable final Object p_object)
converts an object into a term stream
static String httppostexecute( @Nonnull final HttpPost p_post)
execute http-post request
static ITerm baseliteral( @Nonnull final Stream< String > p_functor, @Nonnull final Stream< ITerm > p_values)
creates a literal structure from a stream of string elements, the string stream will be build in a tr...
static String httpgetexecute( @Nonnull final HttpGet p_get)
execute http-get request
static String httpgetexecute( @Nonnull final String p_url)
execute http-get request
static HttpPost httppost( @Nonnull final String p_url)
returns a http-post connection
static final long serialVersionUID
serial id
static Stream< ITerm > flatmap( @Nonnull final Map< String, ?> p_map)
transformas a map into a literal
default generic literal class for agent beliefs a literal consists of a functor, an optional list of ...
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
class for any helper calls
static ILiteral from( @Nonnull final String p_functor, @Nullable final ITerm... p_values)
factory
static final String PACKAGEROOT
package name
base class to read data from the restful service
static< T extends HttpRequestBase > T header( @Nonnull final T p_request)
sets the default header definition
term structure for simple datatypes