summaryrefslogtreecommitdiffstats
path: root/tags/cpp-0.1.incubating-M1-final/sca/runtime/ws_service/axis2c/src/Axis2EntryPointService_skeleton.cpp
blob: c2a06e05c019a9f3922046c5ec3b2bb957866abe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
 * Copyright 2006 The Apache Software Foundation.
 *
 * 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.
 */
#if defined(WIN32)  || defined (_WINDOWS)
#pragma warning(disable: 4786)
#pragma warning(disable: 4091)
#endif

#include <axis2_svc_skeleton.h>
#include <axis2_array_list.h>
#include <axis2_log_default.h>
#include <axis2_error_default.h>
#include <axiom.h>
#include <stdio.h>

#include <sdo_axiom.h>
using namespace commonj::sdo;
using namespace commonj::sdo_axiom;

#include "tuscany/sca/util/Utils.h"
using namespace tuscany::sca;

#include "tuscany/sca/ws/EntryPointProxy.h"
#include "Axis2Utils.h"
using namespace tuscany::sca::ws;


int AXIS2_CALL
Axis2EntryPointService_free(axis2_svc_skeleton_t *svc_skeleton,
          const axis2_env_t *env);

/*
 * This method invokes the right service method 
 */
axiom_node_t* AXIS2_CALL 
Axis2EntryPointService_invoke(axis2_svc_skeleton_t *svc_skeleton,
            const axis2_env_t *env,
            axiom_node_t *node,
            axis2_msg_ctx_t *msg_ctx);

int AXIS2_CALL Axis2EntryPointService_init(axis2_svc_skeleton_t *svc_skeleton,
                        const axis2_env_t *env);

EntryPointProxy* entryPointProxy = NULL;

axis2_svc_skeleton_t *
axis2_Axis2EntryPointService_create(axis2_env_t *env)
{
    axis2_svc_skeleton_t *svc_skeleton = NULL;
    svc_skeleton = (axis2_svc_skeleton_t *) AXIS2_MALLOC((env)->allocator, 
        sizeof(axis2_svc_skeleton_t));

    
    svc_skeleton->ops = (axis2_svc_skeleton_ops_t *) AXIS2_MALLOC(
        (env)->allocator, sizeof(axis2_svc_skeleton_ops_t));

    svc_skeleton->func_array = NULL;

    svc_skeleton->ops->free = Axis2EntryPointService_free;
    svc_skeleton->ops->init = Axis2EntryPointService_init;
    svc_skeleton->ops->invoke = Axis2EntryPointService_invoke;
    /*svc_skeleton->ops->on_fault = Axis2Service_on_fault;*/

    if(entryPointProxy == NULL)
    {
        entryPointProxy = EntryPointProxy::getInstance();
    }

    return svc_skeleton;
}

int AXIS2_CALL
Axis2EntryPointService_init(axis2_svc_skeleton_t *svc_skeleton,
                        const axis2_env_t *env)
{
    // This method never seems to be called - an old Axis2C artifact?

    svc_skeleton->func_array = axis2_array_list_create(env, 0);
    return AXIS2_SUCCESS;
}

int AXIS2_CALL
Axis2EntryPointService_free(axis2_svc_skeleton_t *svc_skeleton,
            const axis2_env_t *env)
{
    /*if(svc_skeleton->func_array)
    {
        AXIS2_ARRAY_LIST_FREE(svc_skeleton->func_array, env);
        svc_skeleton->func_array = NULL;
    }*/

    if(svc_skeleton->ops)
    {
        AXIS2_FREE((env)->allocator, svc_skeleton->ops);
        svc_skeleton->ops = NULL;
    }
    
    if(svc_skeleton)
    {
        AXIS2_FREE((env)->allocator, svc_skeleton);
        svc_skeleton = NULL;
    }
    return AXIS2_SUCCESS; 
}

/*
 * This method invokes the right service method 
 */
axiom_node_t* AXIS2_CALL
Axis2EntryPointService_invoke(axis2_svc_skeleton_t *svc_skeleton,
            const axis2_env_t *env,
            axiom_node_t *node,
            axis2_msg_ctx_t *msg_ctx)
{
	axiom_node_t *returnNode = node;

    /* Depending on the function name invoke the
     *  corresponding Axis2Service method
     */
    if (node)
    {
        if (AXIOM_NODE_GET_NODE_TYPE(node, env) == AXIOM_ELEMENT)
        {
            axiom_element_t *element = NULL;
            element = (axiom_element_t *)AXIOM_NODE_GET_DATA_ELEMENT(node, env);
            if (element)
            {
                // This gets the operation name from the root element name - this is correct for DocLit Wrapped style
                axis2_char_t *op_name = AXIOM_ELEMENT_GET_LOCALNAME(element, env);
                if (op_name)
				{
                    char* systemRoot = Axis2Utils::getAxisServiceParameterValue(env, msg_ctx, "TuscanySystemRoot");
                    char* fullEntryPointName = Axis2Utils::getAxisServiceParameterValue(env, msg_ctx, "TuscanyEntryPoint");

                    AXIS2_LOG_INFO((env)->log, "Axis2EntryPointService invoke called with system root: %s entrypoint name: %s operation name: %s", systemRoot, fullEntryPointName, op_name);

                    //LOGINFO_2(4, "Axis2EntryPointService invoke called with system root: %s and entrypoint name: %s", systemRoot, fullEntryPointName);
                    //LOGINFO_1(4, "Axis2EntryPointService invoke called with operation", op_name);
                    entryPointProxy->init(systemRoot, fullEntryPointName);

                    //Utils::printTypes(entryPointProxy->getDataFactory());

                    AxiomHelper* axiomHelper = AxiomHelper::getHelper();
                    if (entryPointProxy->getDataFactory() == 0)
                    {
                		AXIS2_LOG_ERROR((env)->log, AXIS2_LOG_SI, "Axis2EntryPointService_invoke: EntryPoint has no SCA implementation");
                        return 0;
                    }

                    char* om_str = NULL;
                    om_str = AXIOM_NODE_TO_STRING(node, env);
                    if (om_str)
                    {
                        AXIS2_LOG_INFO((env)->log, "Axis2EntryPointService invoke has request OM: %s\n", om_str);
                    }

                    DataObjectPtr inputDataObject = axiomHelper->toSdo(node, entryPointProxy->getDataFactory());

                    //printf("Axis2EntryPoint inputDataObject: (%d)\n", inputDataObject);

                    if(!inputDataObject)
                    {
                        AXIS2_LOG_ERROR((env)->log, AXIS2_LOG_SI, "Axis2EntryPointService_invoke: Could not convert received Axiom node to SDO");
                        //LOGERROR(0, "Axis2EntryPointService_invoke: Failure whilst invoking EntryPoint");
                        /** TODO: return a SOAP fault here */
                        return 0;
                    }                    
                    //Utils::printDO(inputDataObject);			
                    
                    DataObjectPtr outputDataObject = entryPointProxy->invoke(op_name, inputDataObject);

                    //printf("Axis2EntryPoint outputDataObject: %d\n", outputDataObject);
                    //Utils::printDO(outputDataObject);			
                    //printf("Axis2EntryPoint outputDataObject printed\n");
                    if(!outputDataObject)
                    {
                		AXIS2_LOG_ERROR((env)->log, AXIS2_LOG_SI, "Axis2EntryPointService_invoke: Failure whilst invoking EntryPoint");
                        //LOGERROR(0, "Axis2EntryPointService_invoke: Failure whilst invoking EntryPoint");
                        /** TODO: return a SOAP fault here */
                        return 0;
                    }

					returnNode = axiomHelper->toAxiomNode(outputDataObject);
						
                    om_str = NULL;
                    om_str = AXIOM_NODE_TO_STRING(returnNode, env);
                    if (om_str)
                    {
                        AXIS2_LOG_INFO((env)->log, "Axis2EntryPointService invoke has response OM : %s\n", om_str);
                    }
                        
					AxiomHelper::releaseHelper(axiomHelper);												

                	//LOGEXIT(1, "Axis2EntryPointService_invoke");						
					return returnNode;
                }
            }
        }
    }
    
	AXIS2_LOG_ERROR((env)->log, AXIS2_LOG_SI, "Axis2EntryPointService_invoke: invalid OM parameters in request");
    //LOGERROR(0, "Axis2Service service ERROR: invalid OM parameters in request\n");
    
    /** TODO: return a SOAP fault here */
    return node;
}


extern "C"
{                                                                                   
/**
 * Following block distinguish the exposed part of the dll.
 */

AXIS2_EXPORT int axis2_get_instance(axis2_svc_skeleton **inst,
                        axis2_env_t *env)
{
    *inst = axis2_Axis2EntryPointService_create(env);
    /*if(NULL != *inst)
    {
        status = *inst->init();
    }*/
    if(!(*inst))
    {
        return AXIS2_FAILURE;
    }

    return AXIS2_SUCCESS;
}

AXIS2_EXPORT int axis2_remove_instance(axis2_svc_skeleton_t *inst,
                            axis2_env_t *env)
{
    axis2_status_t status = AXIS2_FAILURE;
	if (inst)
	{
        status = AXIS2_SVC_SKELETON_FREE(inst, env);
    }
    return status;
}
}