You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by pi...@apache.org on 2008/01/24 07:49:00 UTC
svn commit: r614804 - in /webservices/axis2/trunk/c: build.sh
include/axis2_http_transport.h
src/core/transport/http/sender/libcurl/axis2_libcurl.c
Author: pini
Date: Wed Jan 23 22:48:51 2008
New Revision: 614804
URL: http://svn.apache.org/viewvc?rev=614804&view=rev
Log:
Fixing jira issue 828
Modified:
webservices/axis2/trunk/c/build.sh
webservices/axis2/trunk/c/include/axis2_http_transport.h
webservices/axis2/trunk/c/src/core/transport/http/sender/libcurl/axis2_libcurl.c
Modified: webservices/axis2/trunk/c/build.sh
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/build.sh?rev=614804&r1=614803&r2=614804&view=diff
==============================================================================
--- webservices/axis2/trunk/c/build.sh (original)
+++ webservices/axis2/trunk/c/build.sh Wed Jan 23 22:48:51 2008
@@ -7,13 +7,13 @@
echo "AXIS2C_HOME = ${AXIS2C_HOME}"
-sh configure --prefix=${AXIS2C_HOME} --enable-tests=yes
+sh configure --prefix=${AXIS2C_HOME} --enable-tests=yes --enable-libcurl=yes
make -j 10
make install
cd samples
sh autogen.sh
-sh configure --prefix=${AXIS2C_HOME} --with-axis2=${AXIS2C_HOME}/include/axis2-1.2
+sh configure --prefix=${AXIS2C_HOME} --with-axis2=${AXIS2C_HOME}/include/axis2-1.2 --enable-libcurl=yes
make -j 10
make install
Modified: webservices/axis2/trunk/c/include/axis2_http_transport.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/include/axis2_http_transport.h?rev=614804&r1=614803&r2=614804&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_http_transport.h (original)
+++ webservices/axis2/trunk/c/include/axis2_http_transport.h Wed Jan 23 22:48:51 2008
@@ -142,7 +142,7 @@
* HEADER_CONTENT_TYPE
*/
#define AXIS2_HTTP_HEADER_CONTENT_TYPE "Content-Type"
-#define AXIS2_HTTP_HEADER_CONTENT_TYPE_ "Content-Type:"
+#define AXIS2_HTTP_HEADER_CONTENT_TYPE_ "Content-Type: "
/**
*USER DEFINED HEADER CONTENT TYPE
@@ -166,7 +166,7 @@
*/
#define AXIS2_HTTP_HEADER_CONTENT_LENGTH "Content-Length"
-#define AXIS2_HTTP_HEADER_CONTENT_LENGTH_ "Content-Length:"
+#define AXIS2_HTTP_HEADER_CONTENT_LENGTH_ "Content-Length: "
/**
* HEADER_CONTENT_LOCATION
@@ -182,7 +182,7 @@
* HEADER_SOAP_ACTION
*/
#define AXIS2_HTTP_HEADER_SOAP_ACTION "SOAPAction"
-#define AXIS2_HTTP_HEADER_SOAP_ACTION_ "SOAPAction:"
+#define AXIS2_HTTP_HEADER_SOAP_ACTION_ "SOAPAction: "
/**
* HEADER_AUTHORIZATION
@@ -317,11 +317,11 @@
/**
* HEADER_USER_AGENT_AXIS2C
*/
-#define AXIS2_HTTP_HEADER_USER_AGENT_AXIS2C "User-Agent:Axis2/C"
+#define AXIS2_HTTP_HEADER_USER_AGENT_AXIS2C "User-Agent: Axis2/C"
-#define AXIS2_HTTP_HEADER_ACCEPT_ "Accept:"
+#define AXIS2_HTTP_HEADER_ACCEPT_ "Accept: "
-#define AXIS2_HTTP_HEADER_EXPECT_ "Expect:"
+#define AXIS2_HTTP_HEADER_EXPECT_ "Expect: "
/**
* HEADER_CACHE_CONTROL
Modified: webservices/axis2/trunk/c/src/core/transport/http/sender/libcurl/axis2_libcurl.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/sender/libcurl/axis2_libcurl.c?rev=614804&r1=614803&r2=614804&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/sender/libcurl/axis2_libcurl.c (original)
+++ webservices/axis2/trunk/c/src/core/transport/http/sender/libcurl/axis2_libcurl.c Wed Jan 23 22:48:51 2008
@@ -20,6 +20,13 @@
#include "libcurl_stream.h"
static int ref = 0;
+
+typedef struct axis2_libcurl_header
+{
+ axutil_array_list_t *alist;
+ const axutil_env_t *env;
+} axis2_libcurl_header_t;
+
static CURL *handler;
typedef struct axis2_libcurl
@@ -27,6 +34,7 @@
axis2_char_t *memory;
axutil_array_list_t *alist;
unsigned int size;
+ axis2_libcurl_header_t *header;
const axutil_env_t *env;
char errorbuffer[CURL_ERROR_SIZE];
} axis2_libcurl_t;
@@ -47,9 +55,26 @@
const axutil_env_t * env);
void axis2_libcurl_free(
- void *curl,
+ axis2_libcurl_t *curl,
+ const axutil_env_t * env);
+
+axis2_char_t *
+axis2_libcurl_get_content_type(
+ axis2_libcurl_header_t * header,
+ const axutil_env_t * env);
+
+axis2_ssize_t
+axis2_libcurl_get_content_length(
+ axis2_libcurl_header_t * header,
const axutil_env_t * env);
+axis2_http_header_t *AXIS2_CALL
+axis2_libcurl_get_first_header(
+ axis2_libcurl_header_t * header,
+ const axutil_env_t * env,
+ const axis2_char_t * str);
+
+
axis2_status_t AXIS2_CALL
axis2_libcurl_send(
axiom_output_t * om_output,
@@ -88,6 +113,11 @@
axutil_param_t *write_xml_declaration_param = NULL;
axutil_hash_t *transport_attrs = NULL;
axis2_bool_t write_xml_declaration = AXIS2_FALSE;
+ axutil_property_t *property;
+ int *response_length = NULL;
+ axis2_http_status_line_t *status_line = NULL;
+ axis2_char_t *status_line_str = NULL;
+ int status_code = 0;
data = axis2_libcurl_create(env);
if (!data)
@@ -253,16 +283,22 @@
env);
if (AXIS2_TRUE != axis2_msg_ctx_get_is_soap_11(msg_ctx, env))
{
- /* handle SOAP action for SOAP 1.2 case */
if (axutil_strcmp(soap_action, ""))
{
+ /* handle SOAP action for SOAP 1.2 case */
axis2_char_t *temp_content_type = NULL;
- temp_content_type =
- axutil_stracat(env, content_type, ";action=");
+ temp_content_type = axutil_stracat (env,
+ content_type,
+ ";action=\"");
+ content_type = temp_content_type;
+ temp_content_type = axutil_stracat (env,
+ content_type,
+ soap_action);
+ AXIS2_FREE (env->allocator, content_type);
content_type = temp_content_type;
temp_content_type =
- axutil_stracat(env, content_type, soap_action);
- AXIS2_FREE(env->allocator, content_type);
+ axutil_stracat (env, content_type, "\"");
+ AXIS2_FREE (env->allocator, content_type);
content_type = temp_content_type;
}
}
@@ -381,9 +417,9 @@
axis2_libcurl_write_memory_callback);
curl_easy_setopt(handler, CURLOPT_WRITEDATA, data);
-/* curl_easy_setopt (handler, CURLOPT_HEADERFUNCTION, axis2_libcurl_header_callback); */
+ curl_easy_setopt (handler, CURLOPT_HEADERFUNCTION, axis2_libcurl_header_callback);
-/* curl_easy_setopt (handler, CURLOPT_WRITEHEADER, header); */
+ curl_easy_setopt (handler, CURLOPT_WRITEHEADER, data->header);
if (curl_easy_perform(handler))
{
AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "%s", &data->errorbuffer);
@@ -406,6 +442,53 @@
axis2_msg_ctx_set_property(msg_ctx, env, AXIS2_TRANSPORT_IN,
trans_in_property);
+ if (axutil_array_list_size((data->header)->alist, env) > 0)
+ {
+ status_line_str = axutil_array_list_get((data->header)->alist, env, 0);
+ if (status_line_str)
+ {
+ status_line = axis2_http_status_line_create(env, status_line_str);
+ }
+ }
+ if (status_line)
+ {
+ status_code = axis2_http_status_line_get_status_code(status_line, env);
+ }
+ axis2_msg_ctx_set_status_code (msg_ctx, env, status_code);
+ content_type = axis2_libcurl_get_content_type(data->header, env);
+ if (content_type)
+ {
+ if (strstr (content_type, AXIS2_HTTP_HEADER_ACCEPT_MULTIPART_RELATED)
+ && strstr (content_type, AXIS2_HTTP_HEADER_XOP_XML))
+ {
+ axis2_ctx_t *axis_ctx =
+ axis2_op_ctx_get_base (axis2_msg_ctx_get_op_ctx (msg_ctx, env),
+ env);
+ property = axutil_property_create (env);
+ axutil_property_set_scope (property, env, AXIS2_SCOPE_REQUEST);
+ axutil_property_set_value (property,
+ env, axutil_strdup (env, content_type));
+ axis2_ctx_set_property (axis_ctx,
+ env, MTOM_RECIVED_CONTENT_TYPE, property);
+ }
+ }
+
+ buffer_size = (unsigned int) axis2_libcurl_get_content_length(data->header, env);
+ response_length = AXIS2_MALLOC (env->allocator, sizeof (int));
+ memcpy (response_length, &buffer_size, sizeof (int));
+ property = axutil_property_create (env);
+ axutil_property_set_scope (property, env, AXIS2_SCOPE_REQUEST);
+ axutil_property_set_value (property, env, response_length);
+ axis2_msg_ctx_set_property (msg_ctx, env,
+ AXIS2_HTTP_HEADER_CONTENT_LENGTH, property);
+
+ curl_slist_free_all (headers);
+ ref--;
+ if (ref == 0)
+ {
+ curl_easy_cleanup (handler);
+ }
+
axis2_libcurl_free(data, env);
return AXIS2_SUCCESS;
}
@@ -442,17 +525,17 @@
size_t nmemb,
void *data)
{
+ axis2_char_t *memory;
size_t realsize = size * nmemb;
- axis2_libcurl_t *mem = (axis2_libcurl_t *) data;
- mem->memory = AXIS2_MALLOC(mem->env->allocator, realsize + 1);
- mem->size = 0;
- if (mem->memory)
+ axis2_libcurl_header_t *mem = (axis2_libcurl_header_t *) data;
+ memory = (axis2_char_t *)AXIS2_MALLOC(mem->env->allocator, realsize + 1);
+ if (memory)
{
- memcpy(&(mem->memory[mem->size]), ptr, realsize);
- mem->size += realsize;
- mem->memory[mem->size] = 0;
+ memcpy(&(memory[0]), ptr, realsize);
+ memory[realsize] = 0;
axutil_array_list_add(mem->alist, mem->env,
- axutil_strdup(mem->env, mem->memory));
+ axutil_strdup(mem->env, memory));
+ AXIS2_FREE(mem->env->allocator, memory);
}
return realsize;
}
@@ -469,19 +552,120 @@
{
curl->size = 0;
curl->alist = axutil_array_list_create(env, 7);
+ curl->header = (axis2_libcurl_header_t *) AXIS2_MALLOC(env->allocator,
+ sizeof(axis2_libcurl_header_t));
+ if (curl->header)
+ {
+ (curl->header)->alist = axutil_array_list_create(env, 15);
+ (curl->header)->env = env;
+ }
curl->env = env;
}
return curl;
}
-void
+void
axis2_libcurl_free(
- void *curl,
+ axis2_libcurl_t *curl,
const axutil_env_t * env)
{
+ if (curl->alist)
+ {
+ axutil_array_list_free(curl->alist, env);
+ curl->alist = NULL;
+ }
+
+ if (curl->header)
+ {
+ if((curl->header)->alist)
+ {
+ axutil_array_list_free((curl->header)->alist, env);
+ (curl->header)->alist = NULL;
+ }
+ AXIS2_FREE(env->allocator, curl->header);
+ }
+
AXIS2_FREE(env->allocator, curl);
+}
+
+axis2_http_header_t *
+axis2_libcurl_get_first_header(
+ axis2_libcurl_header_t * payload,
+ const axutil_env_t * env,
+ const axis2_char_t * str)
+{
+ axis2_http_header_t *tmp_header = NULL;
+ axis2_char_t *tmp_header_str = NULL;
+ axis2_char_t *tmp_name = NULL;
+ int i = 0;
+ int count = 0;
+ axutil_array_list_t *header_group = NULL;
+
+ AXIS2_ENV_CHECK(env, NULL);
+ AXIS2_PARAM_CHECK(env->error, str, NULL);
-/* curl_slist_free_all (headers); */
+ header_group = payload->alist;
+ if (!header_group)
+ {
+ return NULL;
+ }
+ if (0 == axutil_array_list_size(header_group, env))
+ {
+ return NULL;
+ }
-/* curl_easy_cleanup (handler); */
+ count = axutil_array_list_size(header_group, env);
+
+ for (i = 0; i < count; i++)
+ {
+ tmp_header_str = (axis2_char_t *) axutil_array_list_get(header_group,
+ env, i);
+ if(!tmp_header_str)
+ {
+ continue;
+ }
+ tmp_header = (axis2_http_header_t *) axis2_http_header_create_by_str(env, tmp_header_str);
+ if(!tmp_header)
+ {
+ continue;
+ }
+ tmp_name = axis2_http_header_get_name(tmp_header, env);
+ if (0 == axutil_strcasecmp(str, tmp_name))
+ {
+ return tmp_header;
+ }
+ }
+ return NULL;
+
+}
+
+axis2_ssize_t
+axis2_libcurl_get_content_length(
+ axis2_libcurl_header_t * payload,
+ const axutil_env_t * env)
+{
+ axis2_http_header_t *tmp_header = NULL;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ tmp_header = axis2_libcurl_get_first_header
+ (payload, env, AXIS2_HTTP_HEADER_CONTENT_LENGTH);
+ if (tmp_header)
+ {
+ return AXIS2_ATOI(axis2_http_header_get_value(tmp_header, env));
+ }
+ return -1;
+}
+
+axis2_char_t *
+axis2_libcurl_get_content_type(
+ axis2_libcurl_header_t * payload,
+ const axutil_env_t * env)
+{
+ axis2_http_header_t *tmp_header = NULL;
+ AXIS2_ENV_CHECK(env, NULL);
+ tmp_header = axis2_libcurl_get_first_header
+ (payload, env, AXIS2_HTTP_HEADER_CONTENT_TYPE);
+ if (tmp_header)
+ return axis2_http_header_get_value(tmp_header, env);
+
+ return AXIS2_HTTP_HEADER_ACCEPT_TEXT_PLAIN;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org