Jack BeNimble
Jack BeNimble

Reputation: 36673

Axis2 and fastinfoset - cannot get content-type to change

I've been trying to enable fastinfoset compression on my web services. However, I'm having a problem getting the content-type to change on the request from the client. At least, I think that's why it's not compressing.

I've tried a lot of different things, but the content-type always remains "text/xml". I'm pretty sure that it's supposed go through as "application/soap+fastinfoset" the way I have it set up now. I'm running Axis2 as a standalone, but again I think the problem is that the content type header isn't changing.

I know the options themselves are getting set on the request because I was able to change another option from "UTF-8" to "UTF-16", and it showed up in the header. Here's the current header output from TCPMonitor:

POST /axis2/services/AddressBookService HTTP/1.1
Content-Type: text/xml; charset=UTF-16
SOAPAction: "urn:anonRobustOp"
User-Agent: Axis2
Host: 127.0.0.1:1237
Transfer-Encoding: chunked

The client code is shown below. Any help much appreciated.

package sample.addressbook.rpcclient;

import javax.xml.namespace.QName;    
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.apache.axis2.Constants; 
import sample.addressbook.entry.Entry;

public class AddressBookRPCClient {

    public static void main(String[] args1) throws AxisFault {

        RPCServiceClient serviceClient = new RPCServiceClient();
   
        Options options = serviceClient.getOptions();
 
        options.setProperty(Constants.Configuration.MESSAGE_TYPE,
                "application/soap+fastinfoset");

        options.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, "UTF-16");

        EndpointReference targetEPR = new EndpointReference(
                "http://127.0.0.1:1237/axis2/services/AddressBookService");
  
        options.setTo(targetEPR);

        // /////////////////////////////////////////////////////////////////////

    serviceClient.setOptions(options);
    
        /*
         * Creates an Entry and stores it in the AddressBook.    
         */

        // QName of the target method 
        QName opAddEntry = new QName("http://service.addressbook.sample", "addEntry");
    
        /*
         * Constructing a new Entry
         */
        Entry entry = new Entry();

        entry.setName("Abby Cadabby");
        entry.setStreet("Sesame Street");
        entry.setCity("Sesame City");
        entry.setState("Sesame State");
        entry.setPostalCode("11111111111111111111111111111111111111111111111111111111111111111111111111111");


        // Constructing the arguments array for the method invocation
        Object[] opAddEntryArgs = new Object[] { entry };

        // Invoking the method
        serviceClient.invokeRobust(opAddEntry, opAddEntryArgs);

        /*
         * Fetching an Entry from the Address book
         */

        // QName of the method to invoke 

        QName opFindEntry = new QName("http://service.addressbook.sample", "findEntry");

        //
        String name = "Abby Cadabby";
        Object[] opFindEntryArgs = new Object[] { name };
        Class[] returnTypes = new Class[] { Entry.class };
  
        Object[] response = serviceClient.invokeBlocking(opFindEntry,
                opFindEntryArgs, returnTypes); 

        Entry result = (Entry) response[0];

        if (result == null) {
            System.out.println("No entry found for " + name);
            return;
        } 

        System.out.println("Name   :" + result.getName());
        System.out.println("Street :" + result.getStreet());
        System.out.println("City   :" + result.getCity());
        System.out.println("State  :" + result.getState());
        System.out.println("Postal Code :" + result.getPostalCode());

    }
}

Upvotes: 0

Views: 1383

Answers (2)

Kelum Senanayake
Kelum Senanayake

Reputation: 21

Pass axis2.xml file as a JVM argument as

-Daxis2.xml="location of axis2.xml" 

Here axis2.xml should be configured to FI (messageFormatters and messageBuilders)

Upvotes: 2

Alexander Philippou
Alexander Philippou

Reputation: 64

Read "How to Enable Fast Infoset in Axis2/Java". Hope it helps.

Upvotes: -1

Related Questions