Posts Tagged ‘axis2’

gSoap WITH_NOIO

Thursday, December 13th, 2007

I´m using an Axis2 Java client to communicate with a gSoap web service. Axis2 rejects the gSoap response so I used wireshark to see what´s gSoap sending back. Now it´s clear what is the problem, gSoap is not sending the “HTTP/1.1 200 OK” as the first line. That´s because i´m using WITH_NOIO, so if your are having the same problem either write yourself the “HTTP/1.1 200 OK” line into the response or change the stdsoap2.c file to send the line anyway. just look for the line

if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket))
...
sprintf(soap->tmpbuf, "HTTP/%s %s", soap->http_version, s);

nor soap->master nor soap->socket would be valid sockets if you are handling the sockets yourself outside gSoap (and if you ´re usig WITH_NOID that´s probably the case) so that if clause will be always false. you can wrap that if clause with a “#ifndef WITH_NOID” or just comment out the if.

Passing configuration parameter to Axis2 services

Tuesday, October 16th, 2007

One way to pass parameters to you Axis2 service:

1) write a <parameter> tag inside your services.xml

 
<?xml version="1.0" encoding="UTF-8"?>
<!-- This file was auto-generated from WSDL -->
<!-- by the Apache Axis2 version: 1.3  Built on : Aug 10, 2007 (04:45:47 LKT) -->
<serviceGroup>
    <service name="xxxxxxx" class="MyServiceLifeCycleImpl">
 
....
        <parameter name="jdbcConnectionString">jdbc:derby:c:/demoderby2b;create=true;user=a;password=b;</parameter>
        <parameter name="jdbcDriver">org.apache.derby.jdbc.EmbeddedDriver</parameter>
 
...
    </service>
</serviceGroup>

2) Write a ServiceLifeCycle class


public class MyServiceLifeCycleImpl implements ServiceLifeCycle {
    private Log log = LogFactory.getLog(MyServiceLifeCycleImpl.class);

    public void startUp(ConfigurationContext confCtx, AxisService axisService) {
        try {


            String jdbcConnectionString = (String) axisService.getParameterValue("jdbcConnectionString");
            String jdbcDriver = (String) axisService.getParameterValue("jdbcDriver");
            Class.forName(jdbcDriver).newInstance();
            Connection connection = DriverManager
                    .getConnection(jdbcConnectionString);
            axisService.addParameter("jdbcConnection", connection);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

....


3) Add init method to your service


....
       private ServiceContext serviceContext;

    public void init(ServiceContext serviceContext) {
        this.serviceContext = serviceContext;

    }
....

4) Access the parameter jdbcConnection from your service through serviceContext


....
        Connection conn = (Connection) serviceContext.getAxisService()
                    .getParameterValue("jdbcConnection");

....