jruby-cxf 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,94 @@
1
+ # Copyright 2013 Claude Mamo
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module CXF
16
+ module ComplexType
17
+ include CXF
18
+
19
+ attr_accessor :complex_type_definition
20
+
21
+ def self.included(base)
22
+ base.extend(self)
23
+ end
24
+
25
+ def namespace(namespace)
26
+ @complex_type_definition ||= {}
27
+ @complex_type_definition['namespace'] = namespace
28
+ end
29
+
30
+ def member(name, type, options = {})
31
+ name = name.to_s
32
+ java_name = options[:label].nil? ? name : options[:label]
33
+ @complex_type_definition ||= {}
34
+
35
+ add_accessors(name, java_name, "@#{name}", type)
36
+
37
+ member = {name => {type: type,
38
+ required: options[:required].nil? ? true : options[:required],
39
+ label: java_name}}
40
+
41
+ if @complex_type_definition.has_key? 'members'
42
+ @complex_type_definition['members'] = @complex_type_definition['members'].merge(member)
43
+ else
44
+ @complex_type_definition['members'] = member
45
+ end
46
+
47
+ end
48
+
49
+ private
50
+
51
+ def add_accessors(ruby_property_name, java_property_name, ivar_name, type)
52
+ java_property_name_capitalized = String.new java_property_name
53
+ java_property_name_capitalized[0] = java_property_name[0].capitalize
54
+
55
+ setter_name = ("set" + java_property_name_capitalized).to_sym
56
+ getter_name = ("get" + java_property_name_capitalized).to_sym
57
+
58
+ # for Aegis
59
+ send :define_method, setter_name do |value|
60
+ setter(ivar_name, value)
61
+ end
62
+
63
+ # for Ruby
64
+ send :define_method, ruby_property_name + '=' do |value|
65
+ setter(ivar_name, value)
66
+ end
67
+
68
+ # for Aegis
69
+ send :define_method, getter_name do
70
+ getter ivar_name
71
+ end
72
+
73
+ # for Ruby
74
+ send :define_method, ruby_property_name do
75
+ getter ivar_name
76
+ end
77
+
78
+ java_param_type = get_java_type(type)
79
+
80
+ add_method_signature(setter_name, [java.lang.Void, java_param_type])
81
+ add_method_signature(getter_name, [java_param_type])
82
+
83
+ end
84
+
85
+ def setter(ivar_name, value)
86
+ instance_variable_set(ivar_name, value)
87
+ return nil
88
+ end
89
+
90
+ def getter(ivar_name)
91
+ instance_variable_get(ivar_name)
92
+ end
93
+ end
94
+ end
Binary file
@@ -0,0 +1,56 @@
1
+ # Copyright 2013 Claude Mamo
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'jruby-cxf-1.0.jar'
16
+ require 'complex_type'
17
+ require 'web_service_servlet'
18
+
19
+ module CXF
20
+
21
+ private
22
+
23
+ def get_java_type(type)
24
+ case type
25
+ when :string
26
+ java.lang.String
27
+ when :int
28
+ java.lang.Integer
29
+ when :float
30
+ java.lang.Float
31
+ when :long
32
+ java.lang.Long
33
+ when :byte
34
+ java.lang.Byte
35
+ when :short
36
+ java.lang.Short
37
+ when :big_decimal
38
+ java.math.BigDecimal
39
+ when :time
40
+ java.sql.Time
41
+ when :double
42
+ java.lang.Double
43
+ when :boolean
44
+ java.lang.Boolean
45
+ when :datetime
46
+ java.util.Date
47
+ when :nil
48
+ java.lang.Void
49
+ else
50
+ Kernel.const_get(type.to_s).become_java!(false)
51
+
52
+ end
53
+ end
54
+
55
+ end
56
+
@@ -0,0 +1,30 @@
1
+ # Copyright 2013 Claude Mamo
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module CXF
16
+
17
+ module WebServiceServlet
18
+
19
+ class JRubyCXFNonSpringServlet < org.apache.cxf.transport.servlet.CXFNonSpringServlet
20
+ attr_accessor :server_factory
21
+
22
+ def loadBus(servletConfig)
23
+ super(servletConfig)
24
+
25
+ @server_factory.create
26
+ end
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,71 @@
1
+ # Copyright 2013 Claude Mamo
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module CXF
16
+
17
+ class JRubyServiceConfiguration < org.apache.cxf.service.factory.DefaultServiceConfiguration
18
+
19
+ attr_accessor :service_namespace, :service_name, :declared_methods
20
+
21
+ def getServiceNamespace
22
+ @service_namespace || super
23
+ end
24
+
25
+ def getServiceName
26
+ @service_name || super
27
+ end
28
+
29
+ def isOperation(method)
30
+ if @declared_methods.has_key? method.get_name
31
+ return true
32
+ end
33
+
34
+ return false
35
+ end
36
+
37
+ def getResponseWrapperName(op, method)
38
+ unless @declared_methods[method.get_name][:response_wrapper_name].nil?
39
+ QName.new(op.getName().getNamespaceURI(), @declared_methods[method.get_name][:response_wrapper_name].to_s)
40
+ else
41
+ super
42
+ end
43
+ end
44
+
45
+ def getOutParameterName(op, method, paramNumber)
46
+ unless @declared_methods[method.get_name][:out_parameter_name].nil?
47
+ QName.new(op.getName().getNamespaceURI(), @declared_methods[method.get_name][:out_parameter_name].to_s)
48
+ else
49
+ super
50
+ end
51
+ end
52
+
53
+ def getInParameterName(op, method, paramNumber)
54
+ QName.new(op.get_name.get_namespace_uri, @declared_methods[method.get_name][:in_parameter_names][paramNumber].to_s)
55
+ end
56
+
57
+ def getOperationName(intf, method)
58
+ unless @declared_methods[method.get_name][:label].nil?
59
+ QName.new(intf.get_name.get_namespace_uri, @declared_methods[method.get_name][:label].to_s)
60
+ else
61
+ super
62
+ end
63
+ end
64
+
65
+ def initialize
66
+ @declared_methods = {}
67
+ end
68
+
69
+ end
70
+
71
+ end
@@ -0,0 +1,72 @@
1
+ # Copyright 2013 Claude Mamo
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module CXF
16
+ module WebServiceDefinition
17
+ include CXF
18
+
19
+ attr_accessor :web_service_definition
20
+
21
+ def self.included(base)
22
+ base.extend(self)
23
+ end
24
+
25
+ def web_service_definition
26
+ @web_service_definition || {}
27
+ end
28
+
29
+ def service_namespace(service_namespace)
30
+ @web_service_definition ||= {}
31
+ @web_service_definition['service_namespace'] = service_namespace
32
+ end
33
+
34
+ def endpoint_name(endpoint_name)
35
+ @web_service_definition ||= {}
36
+ @web_service_definition['endpoint_name'] = endpoint_name
37
+ end
38
+
39
+ def service_name(service_name)
40
+ @web_service_definition ||= {}
41
+ @web_service_definition['service_name'] = service_name
42
+ end
43
+
44
+ def expose(name, signature, options = {})
45
+
46
+ java_return_type = get_java_type(signature[:returns])
47
+
48
+ java_param_types = []
49
+ signature[:expects].each {|expect|
50
+ java_param_types << get_java_type(expect.values.first)
51
+ }
52
+
53
+ java_signature = [java_return_type].concat(java_param_types)
54
+
55
+ add_method_signature(name.to_s, java_signature)
56
+
57
+ exposed_method = { name.to_sym => { label: options[:label],
58
+ response_wrapper_name: options[:response_wrapper_name],
59
+ out_parameter_name: options[:out_parameter_name],
60
+ expects: signature[:expects], returns: signature[:returns] } }
61
+
62
+ @web_service_definition ||= {}
63
+
64
+ if @web_service_definition.has_key? 'exposed_methods'
65
+ @web_service_definition['exposed_methods'] = @web_service_definition['exposed_methods'].merge(exposed_method)
66
+ else
67
+ @web_service_definition['exposed_methods'] = exposed_method
68
+ end
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,186 @@
1
+ # Copyright 2013 Claude Mamo
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'java'
16
+ require 'jruby/core_ext'
17
+ require 'web_service_definition'
18
+ require 'jruby_service_configuration'
19
+ require 'jruby_cxf_non_spring_servlet'
20
+
21
+ java_import javax.xml.namespace.QName
22
+
23
+ module CXF
24
+
25
+ module WebServiceServlet
26
+ include CXF::WebServiceDefinition
27
+
28
+ def self.included(base)
29
+ base.extend(self)
30
+ end
31
+
32
+ # required to avoid inheritance
33
+ def method_missing(m, *args, &block)
34
+ @proxy_servlet.send(m, *args, &block)
35
+ end
36
+
37
+ def initialize(path = '/')
38
+
39
+ web_service_definition = get_web_service_definition(self)
40
+
41
+ service_factory = create_service_factory({service_name: web_service_definition[:service_name],
42
+ service_namespace: web_service_definition[:service_namespace],
43
+ endpoint_name: web_service_definition[:endpoint_name],
44
+ declared_methods: web_service_definition[:methods]})
45
+
46
+ data_binder = create_data_binder(web_service_definition[:complex_types])
47
+
48
+ server_factory = create_server_factory({service_factory: service_factory,
49
+ data_binder: data_binder,
50
+ path: path,
51
+ service_bean: self.class.become_java!.newInstance})
52
+
53
+ @proxy_servlet = JRubyCXFNonSpringServlet.new
54
+ @proxy_servlet.server_factory = server_factory
55
+ end
56
+
57
+ private
58
+
59
+ def get_web_service_definition(web_service)
60
+
61
+ declared_methods = {}
62
+ found_complex_types = {}
63
+ web_service_definition = web_service.class.web_service_definition
64
+
65
+ web_service_definition['exposed_methods'] = {} if not web_service_definition.has_key? 'exposed_methods'
66
+
67
+ web_service.methods.each{ |method|
68
+
69
+ if web_service_definition['exposed_methods'].has_key? method
70
+
71
+ in_parameter_names = []
72
+ web_service_definition['exposed_methods'][method].each{|config_key, config_value|
73
+
74
+ if config_key == :expects
75
+ config_value.each { |expect|
76
+ found_complex_types = find_complex_types(expect.values.first, found_complex_types)
77
+ in_parameter_names << expect.keys.first.to_s
78
+ }
79
+ end
80
+
81
+ }
82
+
83
+ unless web_service_definition['exposed_methods'][method][:label].nil?
84
+ method_label = web_service_definition['exposed_methods'][method][:label].to_s
85
+ end
86
+
87
+ unless web_service_definition['exposed_methods'][method][:response_wrapper_name].nil?
88
+ response_wrapper_name = web_service_definition['exposed_methods'][method][:response_wrapper_name].to_s
89
+ end
90
+
91
+ unless web_service_definition['exposed_methods'][method][:out_parameter_name].nil?
92
+ out_parameter_name = web_service_definition['exposed_methods'][method][:out_parameter_name].to_s
93
+ end
94
+
95
+ declared_methods[method.to_s] = { in_parameter_names: in_parameter_names,
96
+ label: method_label,
97
+ response_wrapper_name: response_wrapper_name,
98
+ out_parameter_name: out_parameter_name }
99
+
100
+ end
101
+ }
102
+
103
+
104
+ return { methods: declared_methods,
105
+ complex_types: found_complex_types,
106
+ service_name: web_service_definition['service_name'],
107
+ service_namespace: web_service_definition['service_namespace'],
108
+ endpoint_name: web_service_definition['endpoint_name'] }
109
+ end
110
+
111
+ def create_data_binder(complex_types)
112
+ data_binder = org.jrubycxf.aegis.databinding.AegisDatabinding.new
113
+ aegis_context = org.jrubycxf.aegis.AegisContext.new
114
+ opts = org.jrubycxf.aegis.type.TypeCreationOptions.new
115
+
116
+ opts.set_default_min_occurs(1);
117
+ opts.set_default_nillable(false)
118
+ opts.set_complex_types(complex_types.to_java)
119
+
120
+ aegis_context.set_type_creation_options(opts)
121
+ data_binder.set_aegis_context(aegis_context)
122
+
123
+ return data_binder
124
+ end
125
+
126
+ def create_service_factory(config)
127
+ service_factory = org.apache.cxf.service.factory.ReflectionServiceFactoryBean.new;
128
+ service_configuration = JRubyServiceConfiguration.new
129
+
130
+ service_configuration.service_namespace = config[:service_namespace]
131
+ service_configuration.service_name = config[:service_name]
132
+ service_configuration.declared_methods = config[:declared_methods]
133
+
134
+ service_factory.get_service_configurations.add(0, service_configuration)
135
+
136
+ unless config[:endpoint_name].nil?
137
+ service_factory.set_endpoint_name(QName.new(config[:endpoint_name].to_s))
138
+ end
139
+
140
+ return service_factory
141
+ end
142
+
143
+ def create_server_factory(config)
144
+ server_factory = org.apache.cxf.frontend.ServerFactoryBean.new;
145
+ server_factory.set_service_factory(config[:service_factory])
146
+ server_factory.set_data_binding(config[:data_binder])
147
+ server_factory.set_service_bean(config[:service_bean])
148
+ server_factory.set_address(config[:path])
149
+
150
+ return server_factory
151
+ end
152
+
153
+ def find_complex_types(complex_type, found_complex_types)
154
+
155
+ if is_complex_type? complex_type
156
+ complex_type_class = Kernel.const_get(complex_type)
157
+ complex_type_java_class = get_java_type(complex_type).to_s
158
+ found_complex_types[complex_type_java_class] ||= {}
159
+
160
+ if complex_type_class.complex_type_definition.has_key? 'namespace'
161
+ found_complex_types[complex_type_java_class]['namespace'] = complex_type_class.complex_type_definition['namespace'].to_s
162
+ end
163
+
164
+ complex_type_class.complex_type_definition['members'].each{ |member_name, definition|
165
+ found_complex_types[complex_type_java_class] ||= {}
166
+ found_complex_types[complex_type_java_class][definition[:label]] ||= {}
167
+ found_complex_types[complex_type_java_class][definition[:label]]['required'] = definition[:required]
168
+
169
+ # avoid infinite recursion
170
+ if is_complex_type?(definition[:type]) and Kernel.const_get(definition[:type].to_s) != complex_type_class
171
+ find_complex_types(definition[:type], found_complex_types)
172
+ end
173
+ }
174
+
175
+ end
176
+
177
+ return found_complex_types
178
+ end
179
+
180
+ def is_complex_type?(type)
181
+ Kernel.const_get(type.to_s).included_modules.include? CXF::ComplexType
182
+ rescue
183
+ return false
184
+ end
185
+ end
186
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jruby-cxf
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Claude Mamo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-10 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: JRuby CXF is a JRuby gem that wraps the Apache CXF framework to provide
15
+ a more friendly API for publishing Web Services.
16
+ email: claude.mamo@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/complex_type.rb
22
+ - lib/jruby_cxf.rb
23
+ - lib/jruby_cxf_non_spring_servlet.rb
24
+ - lib/jruby_service_configuration.rb
25
+ - lib/web_service_definition.rb
26
+ - lib/web_service_servlet.rb
27
+ - lib/jruby-cxf-1.0.jar
28
+ homepage: http://github.com/claudemamo/jruby-cxf
29
+ licenses:
30
+ - Apache License, Version 2.0
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.23
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: A wrapper for Apache CXF
53
+ test_files: []