alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Axis 2 example source code file (FastInfosetTest.java)

This example Axis 2 source code file (FastInfosetTest.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Axis 2 tags/keywords

comment, endpointreference, exception, hello, hello, io, net, network, remoteexception, rmi, serversocket, simpleaddserviceclient, simpleaddserviceclient, simplehttpserver, string, string, world, world

The Axis 2 FastInfosetTest.java source code

/*
 * 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.
 */

package org.apache.axis2.fastinfoset;

import java.io.File;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.SocketException;
import java.rmi.RemoteException;

import junit.framework.TestCase;
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.extensions.TestSetup;

import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.transport.http.SimpleHTTPServer;

/**
 * @author Sanjaya Karunasena (sanjayak@yahoo.com)
 * @date Feb 16, 2007
 */
public class FastInfosetTest extends TestCase {

	private static SimpleHTTPServer server;
	private static AxisService service;
	private static EndpointReference target;
	private static ConfigurationContext configurationContext;
	
	public void testAdd() throws RemoteException {
		SimpleAddServiceClient client = new SimpleAddServiceClient(target); //Comment to test with tcpmon.
//		SimpleAddServiceClient client = new SimpleAddServiceClient(); //Uncomment to test with tcpmon.
		
		String result = client.addStrings("Hello ", "World!");
		System.out.println("Output: " + result);
		TestCase.assertEquals("Hello World!", result);
		
		int result1 = client.addInts(17, 33);
		System.out.println("Output: " + result1);
		TestCase.assertEquals(50, result1);
		
		float result2 = client.addFloats(17.64f, 32.36f);
		System.out.println("Output: " + result2);
		TestCase.assertEquals(50.0f, result2, 0.0005f);
	}


	public void testAdd2() throws RemoteException {
        SimpleAddServiceClient client = new SimpleAddServiceClient(target, true); //Comment to test with tcpmon.
////		SimpleAddServiceClient client = new SimpleAddServiceClient(); //Uncomment to test with tcpmon.
////
		String result = client.addStrings("Hello ", "World!");
		System.out.println("Output: " + result);
		TestCase.assertEquals("Hello World!", result);

		int result1 = client.addInts(17, 33);
		System.out.println("Output: " + result1);
		TestCase.assertEquals(50, result1);

		float result2 = client.addFloats(17.64f, 32.36f);
		System.out.println("Output: " + result2);
		TestCase.assertEquals(50.0f, result2, 0.0005f);
	}

	private static int findAvailablePort() throws SocketException, IOException {
		//Create a server socket on any free socket to find a free socket.
		ServerSocket ss = new ServerSocket(0);
		int port = ss.getLocalPort();
		ss.close();
   	
    	return port;
    }
	
    public static Test suite() {
        return new TestSetup(new TestSuite(FastInfosetTest.class)) {
            public void setUp() throws Exception {

                System.out.println("Setting up the Simple HTTP Server");

                    int port = findAvailablePort();
                    port = 5555; //Uncomment to test with tcpmon
                    target = new EndpointReference("http://127.0.0.1:" + (port)
                            + "/axis2/services/SimpleAddService");

                    File configFile = new File(System.getProperty("basedir",".") + "/test-resources/axis2.xml");
                    configurationContext = ConfigurationContextFactory
                    .createConfigurationContextFromFileSystem("target/test-classes", configFile
                            .getAbsolutePath());

                    server = new SimpleHTTPServer(configurationContext, port);

                    server.start();

                service = AxisService.createService("org.apache.axis2.fastinfoset.SimpleAddService",
                        server.getConfigurationContext().getAxisConfiguration());

                server.getConfigurationContext().getAxisConfiguration().addService(
                        service);

                System.out.println("Simple HTTP Server is started");
            }

            public void tearDown() throws Exception {
                    server.stop();
                    System.out.println("Stopped the Simple HTTP Server");
            }
        };
    }
}

Other Axis 2 examples (source code examples)

Here is a short list of links related to this Axis 2 FastInfosetTest.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.