Exemple #1
0
//-----------------------------------------------------------------------------
// This function is invoked via sp_func_at_nodes() from sp_add_soapurl()
static int f_add_soapurl(
	const axutil_env_t * env,
	axiom_node_t *target_node,
	void *arg3)
{
    //
    // Find the paths
    //   HTTP
    //   and add the SOAP capability.
    // If none found it is not considered an error.
    //
    /*
    <ows:Post xlink:type="simple" xlink:href="http://SERVER_UNDEFINED/service">
      <ows:Constraint name="PostEncoding">
        <ows:AllowedValues>
          <ows:Value>SOAP</ows:Value>
        </ows:AllowedValues>
      </ows:Constraint>
    */

    axis2_char_t *soap_ops_url = (axis2_char_t *) arg3;
    if (NULL == soap_ops_url)
    {
        soap_ops_url = "";
    }

    axiom_node_t *top_node = rp_find_named_child(env, target_node, "HTTP", 1);
    if (NULL == top_node) return 0;

    axiom_namespace_t * root_ns = rp_get_namespace (env, top_node);

    axiom_node_t    *post_node = axiom_node_create(env);
    axiom_element_t *post_ele  =
      axiom_element_create(env, top_node, "Post", root_ns, &post_node);

    axiom_namespace_t *xlink_ns = axiom_namespace_create(
      env, SP_XLINK_NAMESPACE_STR, "xlink");

    axiom_attribute_t *attr =
      axiom_attribute_create (env, "type", "simple", xlink_ns);
    axiom_element_add_attribute (post_ele, env, attr, post_node);

    attr = axiom_attribute_create (env, "href", soap_ops_url, xlink_ns);
    axiom_element_add_attribute (post_ele, env, attr, post_node);

    Name_value c_nv;  c_nv.name = "Constraint";  c_nv.value = NULL;
    Name_value p_nv;  p_nv.name = "name";        p_nv.value = "PostEncoding";
    axiom_node_t *c_node = rp_add_child(env, post_node, &c_nv, &p_nv, NULL);

    axiom_node_t *a_node = rp_add_child_el(env, c_node, "AllowedValues", NULL);

    c_nv.name  = "Value";
    c_nv.value = "SOAP";
    rp_add_child(env, a_node, &c_nv, NULL, NULL);

    return 0;
}
Exemple #2
0
/**
 * Add whitespace if not null.
 * @param env
 * @param root_node
 * @param whitespace
 */
void sp_add_whspace(
	const axutil_env_t *env,
    axiom_node_t       *root_node,
    const axis2_char_t *whitespace)
{
	if (whitespace)
	{
		axiom_node_t *whitespace_node  = axiom_node_create(env);
		axiom_text_create (env, root_node, whitespace, &whitespace_node);
	}
}
Exemple #3
0
AXIS2_EXTERN axiom_text_t *AXIS2_CALL
axiom_text_create(
    const axutil_env_t * env,
    axiom_node_t * parent,
    const axis2_char_t * value,
    axiom_node_t ** node)
{
    axiom_text_t *om_text = NULL;
    AXIS2_ENV_CHECK(env, NULL);
    AXIS2_PARAM_CHECK(env->error, node, NULL);

    *node = axiom_node_create(env);

    if(!(*node))
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }
    om_text = (axiom_text_t *)AXIS2_MALLOC(env->allocator, sizeof(axiom_text_t));
    if(!om_text)
    {
        AXIS2_FREE(env->allocator, *node);
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }

    om_text->mime_type = NULL;
    om_text->optimize = AXIS2_FALSE;
    om_text->is_binary = AXIS2_FALSE;
    om_text->is_swa = AXIS2_FALSE;
    om_text->content_id = NULL;
    om_text->om_attribute = NULL;
    om_text->value = NULL;
    om_text->ns = NULL;
    om_text->data_handler = NULL;
    om_text->mime_type = NULL;

    if(value)
    {
        om_text->value = axutil_string_create(env, value);
    }

    axiom_node_set_data_element((*node), env, om_text);
    axiom_node_set_node_type((*node), env, AXIOM_TEXT);
    axiom_node_set_complete((*node), env, AXIS2_FALSE);

    if(parent && axiom_node_get_node_type(parent, env) == AXIOM_ELEMENT)
    {
        axiom_node_add_child(parent, env, (*node));
    }

    return om_text;
}
Exemple #4
0
AXIS2_EXTERN axiom_text_t *AXIS2_CALL
axiom_text_create_str(
    const axutil_env_t * env,
    axiom_node_t * parent,
    axutil_string_t * value,
    axiom_node_t ** node)
{
    axiom_text_t *om_text = NULL;
    AXIS2_ENV_CHECK(env, NULL);
    AXIS2_PARAM_CHECK(env->error, node, NULL);

    *node = axiom_node_create(env);
    if(!(*node))
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Unable to create node needed by om text");
        return NULL;
    }

    om_text = (axiom_text_t *)AXIS2_MALLOC(env->allocator, sizeof(axiom_text_t));
    if(!om_text)
    {
        AXIS2_FREE(env->allocator, *node);
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Insufficient memory to create om text");
        return NULL;
    }

    memset(om_text, 0, sizeof(axiom_text_t));
    if(value)
    {
        om_text->value = axutil_string_clone(value, env);
    }

    axiom_node_set_data_element((*node), env, om_text);
    axiom_node_set_node_type((*node), env, AXIOM_TEXT);

    if(parent && axiom_node_get_node_type(parent, env) == AXIOM_ELEMENT)
    {
        axiom_node_add_child(parent, env, (*node));
    }

    return om_text;
}
Exemple #5
0
/** Add a node with an element to root_node, either as child or as sibling.
 *   The element name is in the same namespace as the root node's name.
 *   The element may optionally include one attribute; if no attribute
 *   is desired then pass 'NULL'.
 *
 *  Example with attribute:
 *     node_id.name="foo";     node.value="bar";
 *     attribute.name="attr";  attribute.value="Zar";
 *  Result :  <ns:foo attr="Zar">bar</ns:foo>
 *
 * @param env
 * @param root_node
 * @param node_id
 *   node_id.name:  name of element to be added,
 *   node_id.value: text of element
 * @param attribute optional Name_value pair for setting an attribute,
 *   may be NULL.
 * @param sibling 1: add as sibling, 0: add as child.
 * @param whitespace: whitespace added before the newly added element (the
 *  newly added element is indented by this space.
 * @return ptr to the the newly added node.
 */
static axiom_node_t *rp_add_node(
    const axutil_env_t *env,
    axiom_node_t       *root_node,
    Name_value         *node_id,
    Name_value         *attribute,
    int                sibling,
    const axis2_char_t *whitespace
 )
{

	sp_add_whspace(env, root_node, whitespace);

    axiom_namespace_t * ns = rp_get_namespace (env, root_node);

    axiom_node_t    *new_node = axiom_node_create(env);
    axiom_element_t *new_ele =
      axiom_element_create(env, NULL, node_id->name, ns, &new_node);
    if (NULL != node_id->value)
    {
    	axiom_element_set_text(new_ele, env, node_id->value, new_node);
    }

    if (NULL != attribute)
    {
        axiom_attribute_t *attr =
          axiom_attribute_create (env, attribute->name, attribute->value, NULL);
        axiom_element_add_attribute (new_ele, env, attr, new_node);
    }

    axis2_status_t success = (
    		sibling ?
    				axiom_node_insert_sibling_after (root_node, env, new_node) :
    				axiom_node_add_child            (root_node, env, new_node)
    );

    if (AXIS2_SUCCESS != success)
    {
    	rp_log_error(env, "*** S2P(%s:%d): Failed to add node name='%s'\n",
    			__FILE__, __LINE__, node_id->name);
    }

    return new_node;
}
Exemple #6
0
//-----------------------------------------------------------------------------
void
sp_update_lineage(
    const axutil_env_t * env,
    const sp_props     *props,
    axiom_node_t *return_node,
    axiom_node_t *request_node,
    time_t        request_time)
{
    axiom_node_t *eom_node =
    		rp_find_named_child(env, return_node, "EOMetadata", 1);
    if (NULL == eom_node)
    {
    	rp_log_error(env, "*Warning S2P(%s:%d): %s node not found.\n",
    			__FILE__, __LINE__,  "EOMetadata");
    	return;
    }

    time_t lineage_time = 0;
    axiom_node_t *curr_lineage =
    		sp_latest_named(env, eom_node, "lineage", &lineage_time);

    // TODO: should improve handling of insignificant whitespace.

    // grab some whitespace for future use
    axiom_node_t *lin_whsp_node = sp_get_last_text_node(curr_lineage, env);
    axiom_node_t *eom_whsp_node = sp_get_last_text_node(eom_node,     env);

    const axis2_char_t *lin_whsp_str = sp_get_text_text(lin_whsp_node, env);
    const axis2_char_t *eom_whsp_str = sp_get_text_text(eom_whsp_node, env);
    int whspace_indent = SP_DEFAULT_WHSPACE;
    if (NULL != lin_whsp_str && NULL != eom_whsp_str)
    {
    	whspace_indent =
    			axutil_strlen(lin_whsp_str) - axutil_strlen(eom_whsp_str);
    	if (whspace_indent < 0 || whspace_indent >12)
    	{
    		rp_log_error(env,
    				"*Warning S2P: funny whitespace indent (%d) calculated.\n",
    				whspace_indent);
    		whspace_indent = SP_DEFAULT_WHSPACE;
    	}
    }

    axis2_char_t curr_whspace[SP_MAX_LOCAL_STR_LEN];
    strncpy(curr_whspace, lin_whsp_str, SP_MAX_LOCAL_STR_LEN-1);
    curr_whspace[SP_MAX_LOCAL_STR_LEN-1] = '\0';

    // The most recent Lineage data is deleted only if it has been added
    // in the time period since we started processing this request.
    if (NULL != curr_lineage && lineage_time >= request_time)
    {
    	// OK to delete lineage
    	axiom_node_detach    (curr_lineage, env);
		axiom_node_free_tree (curr_lineage, env);
		curr_lineage  = NULL;
		lin_whsp_node = NULL;
		lin_whsp_str  = NULL;
    }
    else
    {
    	sp_add_whspace(env, eom_node, curr_whspace);
    }

    // Add a new lineage.  here is an example:
    //    <wcseo:lineage>
    //        <wcseo:referenceGetCoverage>
    //            <ows:ServiceReference xlink:href="http://www.someWCS.org">
    //                <ows:RequestMessage>
    //                    <wcs:GetCoverage service="WCS" version="2.0.0">
    //                        <wcs:format>application/gml+xml</wcs:format>
    //                        <wcs:CoverageId>someEOCoverage1</wcs:CoverageId>
    //                    </wcs:GetCoverage>
    //                </ows:RequestMessage>
    //            </ows:ServiceReference>
    //        </wcseo:referenceGetCoverage>
    //        <gml:timePosition>2011-08-24T14:18:52Z</gml:timePosition>
    //    </wcseo:lineage>


    // <wcseo:lineage>
    axiom_node_t *lineage_node =
    		rp_add_child_el(env, eom_node, "lineage", NULL);

    sp_inc_whspace(curr_whspace, whspace_indent);
    sp_add_whspace(env, lineage_node, curr_whspace);

    // comment
    axiom_node_t *comment  = axiom_node_create(env);
    axiom_comment_create (
    		env,
    		lineage_node,
    		"POST GetCoverage request added by SOAP-TO-POST proxy.",
    		&comment);

	//<wcseo:referenceGetCoverage>
	axiom_node_t *ref_g1_node =
			rp_add_child_el(env, lineage_node, "referenceGetCoverage", curr_whspace);

	// <ows:ServiceReference xlink:href="http://www.someWCS.org">
    sp_inc_whspace(curr_whspace, whspace_indent);
    sp_add_whspace(env, ref_g1_node, curr_whspace);
	axiom_namespace_t *ows_ns =
			sp_find_or_create_ns(env, return_node, SP_OWS_NAMESPACE_STR, "ows");

    axiom_node_t    *service_ref_node = axiom_node_create(env);
    axiom_element_t *service_ref_el =
      axiom_element_create(
    		  env, ref_g1_node, "ServiceReference", ows_ns, &service_ref_node);

	axiom_namespace_t *xlink_ns = sp_find_or_create_ns(
			env, return_node, SP_XLINK_NAMESPACE_STR, "xlink");

    axiom_attribute_t *attr =
      axiom_attribute_create (env, "type", "simple", xlink_ns);
    axiom_element_add_attribute (service_ref_el, env, attr, service_ref_node);

    attr = axiom_attribute_create (env, "href", rp_getSoapOpsURL(env, props), xlink_ns);
    axiom_element_add_attribute (service_ref_el, env, attr, service_ref_node);

    //<ows:RequestMessage>
    axiom_node_t *req_msg_node =
    		rp_add_child_el(env,
    				service_ref_node, "RequestMessage", curr_whspace);
    sp_inc_whspace(curr_whspace, whspace_indent);


    // Detach the request GetCoverage element from its parent
    //  and attach it here.
    axiom_node_t *gc_node =
    		rp_find_named_node(env, request_node, "GetCoverage", 1);
    if (gc_node)
    {
    	// TODO - pretty-up the the indentation to match current.
        sp_add_whspace(env, req_msg_node, curr_whspace);
    	axiom_node_detach    (gc_node, env);
    	axiom_node_add_child (req_msg_node, env, gc_node);
    }

    // Adjust the indentation of closing tags
    sp_inc_whspace(curr_whspace, -whspace_indent);
    sp_add_whspace(env, req_msg_node, curr_whspace);
    sp_inc_whspace(curr_whspace, -whspace_indent);
    sp_add_whspace(env, service_ref_node, curr_whspace);
    sp_inc_whspace(curr_whspace, -whspace_indent);
    sp_add_whspace(env, ref_g1_node, curr_whspace);
    sp_inc_whspace(curr_whspace, -whspace_indent);

    //<gml:timePosition>2011-08-24T14:18:52Z</gml:timePosition>
    sp_add_whspace(env, lineage_node, curr_whspace);
	axiom_namespace_t *gml_ns = sp_find_or_create_ns(
			env, return_node, SP_GML_NAMESPACE_STR, "gml");

    axiom_node_t    *time_pos_node = axiom_node_create(env);
    axiom_element_t *time_pos_el = axiom_element_create(
    		env, lineage_node, "timePosition", gml_ns, &time_pos_node);

    char tmbuf[22];
    sp_time_str(tmbuf, time(NULL));
    axiom_element_set_text(time_pos_el, env, tmbuf, time_pos_node);

    // Adjust the indentation of remaining closing tags
    sp_inc_whspace(curr_whspace, -whspace_indent);
    sp_add_whspace(env, lineage_node, curr_whspace);

    // Adjust whitespace before the element
    // that follows our new lineage element, whatever it may be.
    sp_add_whspace(env, eom_node, eom_whsp_str);

    // Delete the whitespace before any our insertions.
	axiom_node_detach    (eom_whsp_node, env);
	axiom_node_free_tree (eom_whsp_node, env);
}