Class: SAPNW::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sapnwrfc/base.rb

Overview

Some doco in the SAPNW module

Constant Summary collapse

@@rfc_connections =

some doco in Base

{}

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject

Returns the value of attribute config.



74
75
76
# File 'lib/sapnwrfc/config.rb', line 74

def config
  @config
end

.config_locationObject

Returns the value of attribute config_location.



74
75
76
# File 'lib/sapnwrfc/config.rb', line 74

def config_location
  @config_location
end

Class Method Details

.finalize(id) ⇒ Object

def rfc_connection(*args) return SAPNW::RFC::Connection.connect(args) end

def rfc_register(*args)

return SAPNW::RFC::Server.connect(args) end

def installFunction(*args)

return SAPNW::RFC::Server.installFunction(args) end



35
36
37
# File 'lib/sapnwrfc/base.rb', line 35

def Base.finalize(id)
  SAP_LOGGER.debug("[#{self.class}] finalize called")
end

.load_configObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/sapnwrfc/config.rb', line 76

def load_config
        file = self.config_location || './sap.yml'
        SAP_LOGGER.fatal("[#{self.name}] Configuration file not found:  #{file}") unless FileTest.exists?(file)
  self.config = File.open(file) { |f| YAML::load(f) }
  SAP_LOGGER.debug("[#{self.name}] Configuration: " + self.config.inspect)

if self.config.key? 'logfile'
if /STDOUT/i.match(self.config['logfile'])
 SAP_LOGGER.set_logdev(STDOUT)
          else
 SAP_LOGGER.set_logdev(self.config['logfile'],
                       self.config['logfile_age'] || 0,
                      self.config['logfile_size'] || 1048576)
 SAP_LOGGER.datetime_format = "%Y-%m-%d %H:%M:%S"
          end
        end
if self.config.key? 'loglevel'
case self.config['loglevel'].upcase
 when 'FATAL'
    SAP_LOGGER.level = Logger::FATAL
 when 'ERROR'
    SAP_LOGGER.level = Logger::ERROR
 when 'WARN'
    SAP_LOGGER.level = Logger::WARN
 when 'INFO'
    SAP_LOGGER.level = Logger::INFO
 when 'DEBUG'
    SAP_LOGGER.level = Logger::DEBUG
          end
        else
# set default 
          SAP_LOGGER.level = Logger::WARN
        end
  return self.config
end

.rfc_connect(args = nil) ⇒ Object

Build a connection to an R/3 system (ABAP AS)

Connection parameters can be passed in a variety of ways (a) via a YAML based configuration file (b) a Hash of parameter arguments © a combination of both



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/sapnwrfc/connection.rb', line 21

def rfc_connect(args = nil)
    parms = {}
self.config = {} unless self.config
  parms[:ashost] = self.config['ashost']           if self.config.key? 'ashost'
  parms[:dest] = self.config['dest']               if self.config.key? 'dest'
  parms[:mshost] = self.config['mshost']           if self.config.key? 'mshost'
  parms[:group] = self.config['group']             if self.config.key? 'group'
  parms[:sysid] = self.config['sysid']             if self.config.key? 'sysid'
  parms[:msserv] = self.config['msserv']           if self.config.key? 'msserv'
  parms[:sysnr] = self.config['sysnr']             if self.config.key? 'sysnr'
  parms[:lang] = self.config['lang']               if self.config.key? 'lang'
  parms[:client] = self.config['client']           if self.config.key? 'client'
  parms[:user] = self.config['user']               if self.config.key? 'user'
  parms[:passwd] = self.config['passwd']           if self.config.key? 'passwd'
  parms[:trace] = self.config['trace'].to_i        if self.config.key? 'trace'
    parms[:codepage] = self.config['codepage'].to_i  if self.config.key? 'codepage'
  parms[:x509cert] = self.config['x509cert']       if self.config.key? 'x509cert'
  parms[:extiddata] = self.config['extiddata']     if self.config.key? 'extiddata'
  parms[:extidtype] = self.config['extidtype']     if self.config.key? 'extidtype'
  parms[:mysapsso2] = self.config['mysapsso2']     if self.config.key? 'mysapsso2'
  parms[:mysapsso] = self.config['mysapsso']       if self.config.key? 'mysapsso'
  parms[:getsso2] = self.config['getsso2'].to_i    if self.config.key? 'getsso2'
  parms[:snc_mode] = self.config['snc_mode']       if self.config.key? 'snc_mode'
  parms[:snc_qop] = self.config['snc_qop']         if self.config.key? 'snc_qop'
  parms[:snc_myname] = self.config['snc_myname']   if self.config.key? 'snc_myname'
  parms[:snc_partnername] = self.config['snc_partnername'] if self.config.key? 'snc_partnername'
  parms[:snc_lib] = self.config['snc_lib']         if self.config.key? 'snc_lib'
    SAP_LOGGER.debug("[" + self.name + "] base parameters to be passed are: " + parms.inspect)

    case args
  when nil
  when Hash
      parms[:ashost] = args[:ashost]           if args.key? :ashost
      parms[:dest] = args[:dest]               if args.key? :dest
      parms[:mshost] = args[:mshost]           if args.key? :mshost
      parms[:sysid] = args[:sysid]             if args.key? :sysid
      parms[:group] = args[:group]             if args.key? :group
      parms[:msserv] = args[:msserv]           if args.key? :msserv
       parms[:sysnr] = args[:sysnr]             if args.key? :sysnr
       parms[:lang] = args[:lang]               if args.key? :lang
        parms[:client] = args[:client]           if args.key? :client
        parms[:user] = args[:user]               if args.key? :user
        parms[:passwd] = args[:passwd]           if args.key? :passwd
        parms[:trace] = args[:trace].to_i        if args.key? :trace
        parms[:codepage] = args[:codepage].to_i  if args.key? :codepage
       parms[:x509cert] = args[:x509cert]       if args.key? :x509cert
       parms[:extiddata] = args[:extiddata]     if args.key? :extiddata
       parms[:extidtype] = args[:extidtype]     if args.key? :extidtype
        parms[:mysapsso2] = args[:mysapsso2]     if args.key? :mysapsso2
        parms[:mysapsso] = args[:mysapsso]       if args.key? :mysapsso
        parms[:getsso2] = args[:getsso2].to_i    if args.key? :getsso2
        parms[:snc_mode] = args[:snc_mode]       if args.key? :snc_mode
        parms[:snc_qop] = args[:snc_qop]         if args.key? :snc_qop
        parms[:snc_myname] = args[:snc_myname]   if args.key? :snc_myname
        parms[:snc_partnername] = args[:snc_partnername] if args.key? :snc_partnername
        parms[:snc_lib] = args[:snc_lib]         if args.key? :snc_lib
        SAP_LOGGER.debug("[" + self.name + "] with EXTRA parameters to be passed are: " + parms.inspect)
  else
    raise "Wrong parameters for Connection - must pass a Hash\n"
end


    connection = SAPNW::RFC::Connection.new(parms)
    SAP_LOGGER.debug("completed the connection (#{connection.handle.class}/#{connection.handle.object_id}) ...")
  return connection

end

.rfc_register(args = nil) ⇒ Object

registers with an R/3 systems gateway service. Uses parameters supplied in the YAML config file by default, but overrides these with any passed as a Hash. returns a SAPNW::RFC::Server object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sapnwrfc/server.rb', line 19

def rfc_register(args = nil)
  parms = {}
  parms[:trace] = self.config['trace'].to_i        if self.config.key? 'trace'
  parms[:tpname] = self.config['tpname']           if self.config.key? 'tpname'
  parms[:gwhost] = self.config['gwhost']           if self.config.key? 'gwhost'
  parms[:gwserv] = self.config['gwserv']           if self.config.key? 'gwserv'
  SAP_LOGGER.debug("[" + self.name + "] base parameters to be passed are: " + parms.inspect)

  case args
  when nil
  when Hash
    parms[:trace] = args[:trace].to_i        if args.key? :trace
    parms[:tpname] = args[:tpname]           if args.key? :tpname
    parms[:gwhost] = args[:gwhost]           if args.key? :gwhost
    parms[:gwserv] = args[:gwserv]           if args.key? :gwserv
    SAP_LOGGER.debug("[" + self.name + "] with EXTRA parameters to be passed are: " + parms.inspect)
  else
    raise "Wrong parameters for Connection - must pass a Hash\n"
  end

  server = SAPNW::RFC::Server.new(parms)
  SAP_LOGGER.debug("completed the server connection (#{server.handle.class}/#{server.handle.object_id}) ...")
  return server
end