AXIS2_EXTERN axis2_status_t AXIS2_CALL sandesha2_msg_ctx_set_transport_out_stream( sandesha2_msg_ctx_t *rm_msg_ctx, const axutil_env_t *env, axutil_stream_t *stream) { if(!rm_msg_ctx->msg_ctx) return AXIS2_FAILURE; return axis2_msg_ctx_set_transport_out_stream(rm_msg_ctx->msg_ctx, env, stream); }
AXIS2_EXTERN axis2_bool_t AXIS2_CALL axis2_tcp_worker_process_request( axis2_tcp_worker_t * tcp_worker, const axutil_env_t * env, axis2_simple_tcp_svr_conn_t * svr_conn, axis2_char_t * simple_request) { axis2_conf_ctx_t *conf_ctx = NULL; axis2_transport_out_desc_t *out_desc = NULL; axis2_transport_in_desc_t *in_desc = NULL; axis2_msg_ctx_t *msg_ctx = NULL; axiom_xml_reader_t *reader = NULL; axiom_stax_builder_t *builder = NULL; axiom_soap_builder_t *soap_builder = NULL; axiom_soap_envelope_t *soap_envelope = NULL; axis2_engine_t *engine = NULL; axis2_status_t status = AXIS2_FALSE; axutil_stream_t *svr_stream = NULL; axis2_char_t *buffer = NULL; int len = 0; int write = -1; axutil_stream_t *out_stream = NULL; AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "start:axis2_tcp_worker_process_request"); reader = axiom_xml_reader_create_for_memory(env, simple_request, axutil_strlen(simple_request), NULL, AXIS2_XML_PARSER_TYPE_BUFFER); if(!reader) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to create XML reader"); return AXIS2_FAILURE; } builder = axiom_stax_builder_create(env, reader); if(!builder) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to create Stax builder"); return AXIS2_FAILURE; } soap_builder= axiom_soap_builder_create(env, builder, NULL); if(!soap_builder) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to create SOAP builder"); return AXIS2_FAILURE; } conf_ctx = tcp_worker->conf_ctx; if(!conf_ctx) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "conf ctx not available"); return AXIS2_FAILURE; } out_desc = axis2_conf_get_transport_out(axis2_conf_ctx_get_conf(conf_ctx, env), env, AXIS2_TRANSPORT_ENUM_TCP); if(!out_desc) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Transport out not set"); return AXIS2_FAILURE; } in_desc = axis2_conf_get_transport_in(axis2_conf_ctx_get_conf(conf_ctx, env), env, AXIS2_TRANSPORT_ENUM_TCP); msg_ctx = axis2_msg_ctx_create(env, conf_ctx, in_desc, out_desc); axis2_msg_ctx_set_server_side(msg_ctx, env, AXIS2_TRUE); out_stream = axutil_stream_create_basic(env); axis2_msg_ctx_set_transport_out_stream(msg_ctx, env, out_stream); soap_envelope = axiom_soap_builder_get_soap_envelope(soap_builder, env); axis2_msg_ctx_set_soap_envelope(msg_ctx, env, soap_envelope); engine = axis2_engine_create(env, conf_ctx); status = axis2_engine_receive(engine, env, msg_ctx); svr_stream = axis2_simple_tcp_svr_conn_get_stream(svr_conn, env); buffer = out_stream->buffer; len = out_stream->len; buffer[len] = 0; if(svr_stream && buffer) { write = axutil_stream_write(svr_stream, env, buffer, len + 1); if(write < 0) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "stream write failed"); return AXIS2_FAILURE; } AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "stream wrote:%s", buffer); } AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "end:axis2_tcp_worker_process_request"); return AXIS2_SUCCESS; }
AXIS2_EXTERN axis2_msg_ctx_t * AXIS2_CALL axis2_engine_create_fault_msg_ctx( axis2_engine_t * engine, const axutil_env_t * env, axis2_msg_ctx_t * processing_context, const axis2_char_t * code_value, const axis2_char_t * reason_text) { axis2_msg_ctx_t *fault_ctx = NULL; axis2_endpoint_ref_t *fault_to = NULL; axis2_endpoint_ref_t *reply_to = NULL; axutil_stream_t *stream = NULL; axiom_soap_envelope_t *envelope = NULL; const axis2_char_t *wsa_action = NULL; const axis2_char_t *msg_id = NULL; axis2_relates_to_t *relates_to = NULL; axis2_char_t *msg_uuid = NULL; axis2_msg_info_headers_t *msg_info_headers = NULL; axis2_bool_t doing_rest = AXIS2_FALSE; AXIS2_PARAM_CHECK(env->error, processing_context, NULL); if(axis2_msg_ctx_get_process_fault(processing_context, env)) { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_STATE_PROCESSING_FAULT_ALREADY, AXIS2_FAILURE); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Creating fault message contex failed"); return NULL; } fault_ctx = axis2_msg_ctx_create(env, engine->conf_ctx, axis2_msg_ctx_get_transport_in_desc( processing_context, env), axis2_msg_ctx_get_transport_out_desc(processing_context, env)); axis2_msg_ctx_set_process_fault(fault_ctx, env, AXIS2_TRUE); fault_to = axis2_msg_ctx_get_fault_to(processing_context, env); if(fault_to) { const axis2_char_t *address = axis2_endpoint_ref_get_address(fault_to, env); if(!address) { fault_to = NULL; } else if(axutil_strcmp(AXIS2_WSA_NONE_URL, address) == 0 || axutil_strcmp( AXIS2_WSA_NONE_URL_SUBMISSION, address) == 0) { reply_to = axis2_msg_ctx_get_reply_to(processing_context, env); if(reply_to) { axis2_msg_ctx_set_fault_to(fault_ctx, env, reply_to); } else { axis2_msg_ctx_set_fault_to(fault_ctx, env, fault_to); } } else { axis2_msg_ctx_set_fault_to(fault_ctx, env, fault_to); } } stream = axis2_msg_ctx_get_transport_out_stream(processing_context, env); if(stream) { axis2_msg_ctx_set_transport_out_stream(fault_ctx, env, stream); axis2_msg_ctx_reset_transport_out_stream(processing_context, env); } if(!fault_to && !stream) { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NOWHERE_TO_SEND_FAULT, AXIS2_FAILURE); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Soap fault target destination not found"); return NULL; } /* Set WSA action */ msg_info_headers = axis2_msg_ctx_get_msg_info_headers(processing_context, env); if(msg_info_headers) { wsa_action = axis2_msg_info_headers_get_action(msg_info_headers, env); if(wsa_action) { /* We have to use the action set by user, cannot use the default always. wsa_action = "http://www.w3.org/2005/08/addressing/fault"; */ axis2_msg_ctx_set_wsa_action(fault_ctx, env, wsa_action); } } /* Set relates to */ msg_id = axis2_msg_ctx_get_msg_id(processing_context, env); /* we can create with default Relates to namespace. Actual namespace based on addressing version will be created in addressing out handler */ relates_to = axis2_relates_to_create(env, msg_id, AXIS2_WSA_RELATES_TO_RELATIONSHIP_TYPE_DEFAULT_VALUE); axis2_msg_ctx_set_relates_to(fault_ctx, env, relates_to); /* Set msg id */ msg_uuid = axutil_uuid_gen(env); axis2_msg_ctx_set_message_id(fault_ctx, env, msg_uuid); if(msg_uuid) { AXIS2_FREE(env->allocator, msg_uuid); msg_uuid = NULL; } /** Copy the property map from the current message context to the newly created fault message context. */ { axis2_ctx_t *ctx = axis2_msg_ctx_get_base(processing_context, env); axis2_ctx_t *fault_base_ctx = axis2_msg_ctx_get_base(fault_ctx, env); if(ctx && fault_ctx) { axis2_ctx_set_property_map(fault_base_ctx, env, axis2_ctx_get_property_map(ctx, env)); } } axis2_msg_ctx_set_op_ctx(fault_ctx, env, axis2_msg_ctx_get_op_ctx(processing_context, env)); axis2_msg_ctx_set_process_fault(fault_ctx, env, AXIS2_TRUE); axis2_msg_ctx_set_server_side(fault_ctx, env, AXIS2_TRUE); envelope = axis2_msg_ctx_get_fault_soap_envelope(processing_context, env); if(!envelope) { if(axis2_msg_ctx_get_is_soap_11(processing_context, env)) { envelope = axiom_soap_envelope_create_default_soap_fault_envelope(env, code_value, reason_text, AXIOM_SOAP11, NULL, NULL); } else { envelope = axiom_soap_envelope_create_default_soap_fault_envelope(env, code_value, reason_text, AXIOM_SOAP12, NULL, NULL); } if(!envelope) { AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Creating default soap envelope failed"); return NULL; } } else { axis2_msg_ctx_set_fault_soap_envelope(processing_context, env, NULL); } doing_rest = axis2_msg_ctx_get_doing_rest(processing_context, env); axis2_msg_ctx_set_doing_rest(fault_ctx, env, doing_rest); axis2_msg_ctx_set_soap_envelope(fault_ctx, env, envelope); axis2_msg_ctx_set_out_transport_info(fault_ctx, env, axis2_msg_ctx_get_out_transport_info( processing_context, env)); axis2_msg_ctx_reset_out_transport_info(processing_context, env); return fault_ctx; }
/* Process a request. If the request has a response the response structure will be populated */ AXIS2_EXTERN axis2_bool_t AXIS2_CALL axis2_udp_receiver_process_request( const axutil_env_t * env, axis2_conf_ctx_t *conf_ctx, axis2_udp_request_t * request, axis2_udp_response_t * responce) { axis2_transport_out_desc_t *out_desc = NULL; axis2_transport_in_desc_t *in_desc = NULL; axis2_msg_ctx_t *msg_ctx = NULL; axiom_xml_reader_t *reader = NULL; axiom_stax_builder_t *builder = NULL; axiom_soap_builder_t *soap_builder = NULL; axiom_soap_envelope_t *soap_envelope = NULL; axis2_engine_t *engine = NULL; axis2_status_t status = AXIS2_FALSE; axutil_stream_t *out_stream = NULL; AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "start:axis2_udp_worker_process_request"); if (!conf_ctx) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "conf ctx not available"); return AXIS2_FAILURE; } reader = axiom_xml_reader_create_for_memory(env, request->buff, request->buf_size, NULL, AXIS2_XML_PARSER_TYPE_BUFFER); if (!reader) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to create XML reader"); return AXIS2_FAILURE; } builder = axiom_stax_builder_create(env, reader); if (!builder) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to create Stax builder"); return AXIS2_FAILURE; } soap_builder = axiom_soap_builder_create(env, builder, AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI); if (!soap_builder) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to create SOAP builder"); return AXIS2_FAILURE; } out_desc = axis2_conf_get_transport_out(axis2_conf_ctx_get_conf(conf_ctx, env), env, AXIS2_TRANSPORT_ENUM_UDP); if (!out_desc) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Transport out not set"); return AXIS2_FAILURE; } in_desc = axis2_conf_get_transport_in(axis2_conf_ctx_get_conf(conf_ctx, env), env, AXIS2_TRANSPORT_ENUM_UDP); msg_ctx = axis2_msg_ctx_create(env, conf_ctx, in_desc, out_desc); axis2_msg_ctx_set_server_side(msg_ctx, env, AXIS2_TRUE); out_stream = axutil_stream_create_basic(env); axis2_msg_ctx_set_transport_out_stream(msg_ctx, env, out_stream); soap_envelope = axiom_soap_builder_get_soap_envelope(soap_builder, env); axis2_msg_ctx_set_soap_envelope(msg_ctx, env, soap_envelope); if (request->svc) { axis2_msg_ctx_set_svc(msg_ctx, env, request->svc); } if (request->op) { axis2_msg_ctx_set_op(msg_ctx, env, request->op); } engine = axis2_engine_create(env, conf_ctx); status = axis2_engine_receive(engine, env, msg_ctx); responce->buff = axutil_stream_get_buffer(out_stream, env); responce->buf_size = axutil_stream_get_len(out_stream, env); AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "end:axis2_udp_worker_process_request"); return AXIS2_SUCCESS; }