summaryrefslogtreecommitdiffstats
path: root/test/core/clientapi
diff options
context:
space:
mode:
authorGravatar gmcdonald2010-02-13 01:32:03 +0000
committerGravatar gmcdonald2010-02-13 01:32:03 +0000
commit0425aadc78680e53000fd0108b540d6eca048516 (patch)
tree8ec7ab8e015d454c5ec586dfc91e05a2dce1cfc0 /test/core/clientapi
downloadaxis2c-0425aadc78680e53000fd0108b540d6eca048516.tar.gz
axis2c-0425aadc78680e53000fd0108b540d6eca048516.tar.bz2
Moving axis svn, part of TLP move INFRA-2441
git-svn-id: http://svn.apache.org/repos/asf/axis/axis2/c/core/trunk@909681 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/core/clientapi')
-rw-r--r--test/core/clientapi/Makefile.am49
-rw-r--r--test/core/clientapi/addr_echo.xml23
-rw-r--r--test/core/clientapi/echo.xml1
-rw-r--r--test/core/clientapi/test_client.c182
-rw-r--r--test/core/clientapi/test_clientapi.c119
-rw-r--r--test/core/clientapi/test_svc_client_handler_count.c22
6 files changed, 396 insertions, 0 deletions
diff --git a/test/core/clientapi/Makefile.am b/test/core/clientapi/Makefile.am
new file mode 100644
index 0000000..e88c350
--- /dev/null
+++ b/test/core/clientapi/Makefile.am
@@ -0,0 +1,49 @@
+TESTS = test_client test_clientapi test_svc_client_handler_count
+noinst_PROGRAMS = test_client test_clientapi test_svc_client_handler_count
+check_PROGRAMS = test_client test_clientapi test_svc_client_handler_count
+SUBDIRS =
+AM_CFLAGS = -g -pthread
+test_client_SOURCES = test_client.c
+test_clientapi_SOURCES = test_clientapi.c
+test_svc_client_handler_count_SOURCES = test_svc_client_handler_count.c
+
+test_clientapi_LDADD = \
+ ../../../util/src/libaxutil.la \
+ ../../../axiom/src/om/libaxis2_axiom.la \
+ ../../../axiom/src/parser/$(WRAPPER_DIR)/libaxis2_parser.la \
+ $(top_builddir)/neethi/src/libneethi.la \
+ -lpthread \
+ $(top_builddir)/src/core/engine/libaxis2_engine.la \
+ $(top_builddir)/src/core/transport/http/sender/libaxis2_http_sender.la
+
+test_client_LDADD = \
+ ../../../util/src/libaxutil.la \
+ ../../../axiom/src/om/libaxis2_axiom.la \
+ ../../../axiom/src/parser/$(WRAPPER_DIR)/libaxis2_parser.la \
+ $(top_builddir)/neethi/src/libneethi.la \
+ -lpthread \
+ $(top_builddir)/src/core/engine/libaxis2_engine.la \
+ $(top_builddir)/src/core/transport/http/sender/libaxis2_http_sender.la
+
+test_svc_client_handler_count_LDADD = \
+ ../../../util/src/libaxutil.la \
+ ../../../axiom/src/om/libaxis2_axiom.la \
+ ../../../axiom/src/parser/$(WRAPPER_DIR)/libaxis2_parser.la \
+ $(top_builddir)/neethi/src/libneethi.la \
+ -lpthread \
+ $(top_builddir)/src/core/engine/libaxis2_engine.la \
+ $(top_builddir)/src/core/transport/http/sender/libaxis2_http_sender.la
+
+
+INCLUDES = -I${CUTEST_HOME}/include \
+ -I$(top_builddir)/include \
+ -I$(top_builddir)/src/core/description \
+ -I$(top_builddir)/src/core/context \
+ -I$(top_builddir)/src/core/phaseresolver \
+ -I$(top_builddir)/src/core/deployment \
+ -I$(top_builddir)/src/core/engine \
+ -I$(top_builddir)/src/core/clientapi \
+ -I ../../../util/include \
+ -I ../../../neethi/include \
+ -I ../../../axiom/include
+
diff --git a/test/core/clientapi/addr_echo.xml b/test/core/clientapi/addr_echo.xml
new file mode 100644
index 0000000..85284bf
--- /dev/null
+++ b/test/core/clientapi/addr_echo.xml
@@ -0,0 +1,23 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa=
+"http://schemas.xmlsoap.org/ws/2004/08/addressing">
+ <soapenv:Header>
+ <wsrm:Sequence xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm" soapenv:mustUnderstand="1">
+ <wsrm:Identifier>uuid:967F11455D2EC0EC9411374901147634</wsrm:Identifier>
+ <wsrm:MessageNumber>1</wsrm:MessageNumber>
+ <wsrm:LastMessage />
+ </wsrm:Sequence>
+ <wsa:To xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">http://127.0.0.1:9090/axis2/services/echo</wsa:To>
+ <wsa:Action xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">http://127.0.0.1:9090/axis2/services/echo/__OPERATION_OUT_IN__</wsa:Action>
+ <wsa:ReplyTo xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
+ <wsa:Address>http://192.168.1.217:9090/axis2/services/__ANONYMOUS_SERVICE__/__OPERATION_OUT_IN__</wsa:Address>
+ </wsa:ReplyTo>
+ <wsa:MessageID xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">38DDECF77196B604F511374901138822
+ </wsa:MessageID>
+ </soapenv:Header>
+ <soapenv:Body>
+ <echoString xmlns="">
+ <text xmlns="">echo5</text>
+ </echoString>
+ </soapenv:Body>
+ </soapenv:Envelope> \ No newline at end of file
diff --git a/test/core/clientapi/echo.xml b/test/core/clientapi/echo.xml
new file mode 100644
index 0000000..fad1895
--- /dev/null
+++ b/test/core/clientapi/echo.xml
@@ -0,0 +1 @@
+<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><echoString><text>echo5</text></echoString></soapenv:Body></soapenv:Envelope>
diff --git a/test/core/clientapi/test_client.c b/test/core/clientapi/test_client.c
new file mode 100644
index 0000000..83a417e
--- /dev/null
+++ b/test/core/clientapi/test_client.c
@@ -0,0 +1,182 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+#include <stdio.h>
+#include <strings.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <axis2_const.h>
+#include <stdlib.h>
+
+/* Function prototypes */
+int write_to_socket(
+ const char *address,
+ const char *port,
+ const char *filename,
+ const char *endpoint);
+
+/* End of function prototypes */
+
+void
+error(
+ const char *msg)
+{
+ perror(msg);
+ exit(0);
+}
+
+int
+main(
+ int argc,
+ char *argv[])
+{
+ const axis2_char_t *hostname = "localhost";
+ const axis2_char_t *port = "9090";
+ const axis2_char_t *filename = "echo.xml";
+ const axis2_char_t *endpoint = "/axis2/services/echo/echo";
+ int c;
+ extern char *optarg;
+
+ while ((c = getopt(argc, argv, ":h:p:f:e:")) != -1)
+ {
+ switch (c)
+ {
+ case 'h':
+ hostname = optarg;
+ break;
+ case 'p':
+ port = optarg;
+ break;
+ case 'f':
+ filename = optarg;
+ break;
+ case 'e':
+ endpoint = optarg;
+ break;
+ }
+ }
+
+ write_to_socket(hostname, port, filename, endpoint);
+ return 0;
+}
+
+int
+write_to_socket(
+ const char *address,
+ const char *port,
+ const char *filename,
+ const char *endpoint)
+{
+ axis2_char_t buffer_l[4999];
+ int sockfd,
+ portno,
+ n,
+ i;
+ struct sockaddr_in serv_addr;
+ struct hostent *server;
+ struct stat buf;
+ axis2_char_t *buffer;
+ axis2_char_t tmpstr[10];
+ int bufsize = 0;
+
+ portno = atoi(port);
+ sockfd = socket(AF_INET, SOCK_STREAM, 0);
+ if (sockfd < 0)
+ error("ERROR opening socket");
+ server = gethostbyname(address);
+ if (server == NULL)
+ {
+ fprintf(stderr, "ERROR, no such host\n");
+ exit(0);
+ }
+ bzero((char *) &serv_addr, sizeof(serv_addr));
+ serv_addr.sin_family = AF_INET;
+ bcopy((char *) server->h_addr,
+ (char *) &serv_addr.sin_addr.s_addr, server->h_length);
+ serv_addr.sin_port = htons(portno);
+ if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
+ error("ERROR connecting");
+
+ /* Read from file */
+ stat(filename, &buf);
+ bufsize = (buf.st_size + 1) * sizeof(char);
+ buffer = (char *) malloc(bufsize);
+ int fd = open(filename, O_RDONLY, 0);
+ if (fd == -1)
+ {
+ printf("can't open file %s\n", filename);
+ return -1;
+ }
+ else
+ printf("opened file %s\n", filename);
+
+ i = read(fd, buffer, bufsize - 1);
+ if (i > 0)
+ {
+ buffer[i] = '\0';
+ printf("%s...\n", buffer);
+ }
+ sprintf(buffer_l,
+ "POST %s HTTP/1.1\r\nUser-Agent: Axis/2.0/C\r\nConnection: Keep-Alive\r\nHost: ",
+ endpoint);
+ strcat(buffer_l, address);
+ strcat(buffer_l, ":");
+ strcat(buffer_l, port);
+ strcat(buffer_l, "\r\n");
+ strcat(buffer_l, "Content-Length: ");
+ sprintf(tmpstr, "%d", (int) strlen(buffer));
+ strcat(buffer_l, tmpstr);
+ strcat(buffer_l, "\r\n");
+ /*strcat(buffer_l, "SOAPAction: http://localhost:9090/axis2/services/echo/echo\r\n"); */
+ strcat(buffer_l, "Content-Type: application/soap+xml;\r\n");
+ strcat(buffer_l, "\r\n");
+
+ printf("Writing buffer_1...\n%s", buffer_l);
+ n = write(sockfd, buffer_l, strlen(buffer_l));
+
+ n = write(sockfd, buffer, strlen(buffer));
+ if (n < 0)
+ error("ERROR writing to socket");
+
+ printf("Done writing to server\n");
+
+ buffer[0] = '\0';
+
+ printf("Reading the reply from server :\n");
+ while ((n = read(sockfd, buffer, bufsize - 1)) > 0)
+ {
+ buffer[n] = '\0';
+ printf("%s", buffer);
+ }
+ printf("\nReading from server done ...\n");
+
+ if (n < 0)
+ {
+ error("ERROR reading from socket");
+ buffer[0] = '\0';
+ }
+ free(buffer);
+ return 0;
+}
diff --git a/test/core/clientapi/test_clientapi.c b/test/core/clientapi/test_clientapi.c
new file mode 100644
index 0000000..e20d44a
--- /dev/null
+++ b/test/core/clientapi/test_clientapi.c
@@ -0,0 +1,119 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+#include <axis2_const.h>
+#include <axutil_env.h>
+#include <axis2_engine.h>
+#include <axutil_allocator.h>
+#include <axis2_svc_client.h>
+#include <axis2_options.h>
+#include <platforms/axutil_platform_auto_sense.h>
+
+axiom_node_t *build_om_payload_for_echo_svc(
+ const axutil_env_t * env,
+ const axis2_char_t * echo_str);
+
+void
+axis2_test_svc_client_blocking(
+ )
+{
+ axutil_env_t *env = NULL;
+ axis2_options_t *options = NULL;
+ const axis2_char_t *client_home = NULL;
+ axis2_svc_client_t *svc_client = NULL;
+ axiom_node_t *payload = NULL;
+ axiom_node_t *ret_node = NULL;
+ const axis2_char_t *address = NULL;
+ axis2_endpoint_ref_t *endpoint_ref = NULL;
+
+ axutil_allocator_t *allocator = axutil_allocator_init(NULL);
+ env = axutil_env_create(allocator);
+ axiom_element_t *result_ele = NULL;
+ const axis2_char_t *echo_text = "echo_text";
+ axis2_char_t *result = NULL;
+
+ address = "http://localhost:9090/axis2/services/echo/echo";
+ endpoint_ref = axis2_endpoint_ref_create(env, address);
+ client_home = AXIS2_GETENV("AXIS2C_HOME");
+ if (!client_home)
+ client_home = "../../deploy";
+
+ svc_client = axis2_svc_client_create(env, client_home);
+
+ if (!svc_client)
+ {
+ printf("axis2_test axis2_svc_client_create FAILURE\n");
+ printf
+ ("Client repository path not properly set. Please check AXIS2C_HOME setting\n");
+ return;
+ }
+
+ options = axis2_options_create(env);
+ axis2_options_set_to(options, env, endpoint_ref);
+ axis2_svc_client_set_options(svc_client, env, options);
+
+ payload = build_om_payload_for_echo_svc(env, echo_text);
+ ret_node = axis2_svc_client_send_receive(svc_client, env, payload);
+ if (ret_node)
+ {
+ if (axiom_node_get_node_type(ret_node, env) == AXIOM_ELEMENT)
+ {
+ ret_node = axiom_node_get_first_child(ret_node, env);
+ result_ele =
+ (axiom_element_t *) axiom_node_get_data_element(ret_node, env);
+ result = axiom_element_get_text(result_ele, env, ret_node);
+ if (!strcmp(result, echo_text))
+ printf("axis2_test SVC_CLIENT_SEND_RECEIVE SUCCESS\n");
+ else
+ printf("axis2_test SVC_CLIENT_SEND_RECEIVE FAILURE\n");
+ }
+ }
+ axis2_svc_client_free(svc_client, env);
+}
+
+/* build SOAP request message content using OM */
+axiom_node_t *
+build_om_payload_for_echo_svc(
+ const axutil_env_t * env,
+ const axis2_char_t * echo_text)
+{
+ axiom_node_t *echo_om_node = NULL;
+ axiom_element_t *echo_om_ele = NULL;
+ axiom_node_t *text_om_node = NULL;
+ axiom_element_t *text_om_ele = NULL;
+ axiom_namespace_t *ns1 = NULL;
+
+ ns1 =
+ axiom_namespace_create(env, "http://ws.apache.org/axis2/c/samples",
+ "ns1");
+ echo_om_ele =
+ axiom_element_create(env, NULL, "echoString", ns1, &echo_om_node);
+ text_om_ele =
+ axiom_element_create(env, echo_om_node, "text", NULL, &text_om_node);
+ axiom_element_set_text(text_om_ele, env, echo_text, text_om_node);
+
+ return echo_om_node;
+}
+
+int
+main(
+ )
+{
+ axis2_test_svc_client_blocking();
+ return 0;
+}
diff --git a/test/core/clientapi/test_svc_client_handler_count.c b/test/core/clientapi/test_svc_client_handler_count.c
new file mode 100644
index 0000000..a4904dd
--- /dev/null
+++ b/test/core/clientapi/test_svc_client_handler_count.c
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <axis2_util.h>
+#include <axis2_client.h>
+
+int
+main(
+ )
+{
+ axutil_env_t *env =
+ axutil_env_create_all("hello_client.log", AXIS2_LOG_LEVEL_TRACE);
+ const int TIMES = 1000;
+ int i;
+ for (i = 1; i <= TIMES; ++i)
+ {
+ printf("%d\n", i);
+ axis2_svc_client_t *svc_client =
+ axis2_svc_client_create(env, AXIS2_GETENV("AXIS2C_HOME"));
+ axis2_svc_client_free(svc_client, env);
+ }
+ axutil_env_free(env);
+ return 0;
+}