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

Axis 2 example source code file (PolymorphicTests.java)

This example Axis 2 source code file (PolymorphicTests.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

file, file, io, net, network, package, polymorphicshapeservice, sending, set, square, square, string, string, test, test, threedsquare, util, wsdl4jwrapper

The Axis 2 PolymorphicTests.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.jaxws.polymorphic.shape.tests;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.ConnectException;
import java.net.UnknownHostException;
import java.net.URL;
import java.util.Iterator;
import java.util.Set;

import javax.wsdl.WSDLException;

import junit.framework.TestCase;
import org.apache.axis2.jaxws.polymorphic.shape.sei.PolymorphicShapePortType;
import org.apache.axis2.jaxws.polymorphic.shape.sei.PolymorphicShapeService;
import org.apache.axis2.jaxws.util.WSDL4JWrapper;
import org.apache.axis2.jaxws.util.WSDLWrapper;
import org.apache.axis2.jaxws.wsdl.SchemaReaderException;
import org.apache.axis2.jaxws.wsdl.impl.SchemaReaderImpl;
import org.apache.axis2.jaxws.TestLogger;
import org.test.shape.Shape;
import org.test.shape.Square;
import org.test.shape.threed.ThreeDSquare;

public class PolymorphicTests extends TestCase {

	public void testFormalAndActualTypeInDifferentPackages(){
        TestLogger.logger.debug("------------------------------");
        TestLogger.logger.debug("Test : " + getName());
		PolymorphicShapeService service = new PolymorphicShapeService();
		PolymorphicShapePortType port = service.getPolymorphicShapePort();
		Shape shapeType;

        TestLogger.logger.debug("Sending Request to draw Square");
		Square shape = new Square();
		shape.setXAxis(1);
		shape.setYAxis(1);
		shape.setLength(10);
		shapeType = port.draw(shape);
		assertTrue(shapeType instanceof Square);
        TestLogger.logger.debug("Square was drawn");

        TestLogger.logger.debug("Sending Request to draw 3D Square");
		ThreeDSquare threeDshape = new ThreeDSquare();
		threeDshape.setXAxis(1);
		threeDshape.setYAxis(1);
		threeDshape.setLength(10);
		threeDshape.setWidth(10);
		threeDshape.setBredth(10);
		shapeType = port.draw3D(threeDshape);
		assertTrue(shapeType instanceof ThreeDSquare);
        TestLogger.logger.debug("3D Square was drawn");
        TestLogger.logger.debug("-------------------------------");
	}
	
	public void testInlineUseOfJAXBBinding(){
        TestLogger.logger.debug("------------------------------");
        TestLogger.logger.debug("Test : " + getName());
		String schemaBindingPkgName = "org.test.echomessage";
		String standardPkgName= "org.test.complextype.nonanonymous";
		String wsdlLocation="test-resources/wsdl/JAXB_Customization_Sample.wsdl";
		URL url = null;
		try{
			try{
				String baseDir = new File(System.getProperty("basedir",".")).getCanonicalPath();
				wsdlLocation = new File(baseDir +File.separator+ wsdlLocation).getAbsolutePath();
			}catch(Exception e){
				e.printStackTrace();
				fail();
			}
			File file = new File(wsdlLocation);
			url = file.toURL();
			WSDLWrapper wsdlWrapper = new WSDL4JWrapper(url);
			org.apache.axis2.jaxws.wsdl.SchemaReader sr= new SchemaReaderImpl();
			Set<String> set= sr.readPackagesFromSchema(wsdlWrapper.getDefinition());
			assertNotNull(set);
			Iterator<String> iter = set.iterator();
			while(iter.hasNext()){
				String pkg = iter.next();
                TestLogger.logger.debug("Package = " + pkg);
			}
            TestLogger.logger.debug("------------------------------");
		} catch (MalformedURLException e) {
			e.printStackTrace();
			fail();
		}catch(FileNotFoundException e) {
			e.printStackTrace();
			fail();
		}catch(UnknownHostException e) {
			e.printStackTrace();
			fail();
		}catch(ConnectException e) {
			e.printStackTrace();
			fail();
		}catch(IOException e) {
		    e.printStackTrace();
            fail();
        }catch(WSDLException e){
			e.printStackTrace();
			fail();
		}catch(SchemaReaderException e){
			e.printStackTrace();
			fail();
		}
	}
	
	public void testSchemaReader(){
        TestLogger.logger.debug("------------------------------");
        TestLogger.logger.debug("Test : " + getName());
		String wsdlLocation="test-resources/wsdl/shapes.wsdl";
		URL url = null;
		try{
			try{
				String baseDir = new File(System.getProperty("basedir",".")).getCanonicalPath();
				wsdlLocation = new File(baseDir +File.separator+ wsdlLocation).getAbsolutePath();
			}catch(Exception e){
				e.printStackTrace();
				fail();
			}
			File file = new File(wsdlLocation);
			url = file.toURL();
			WSDLWrapper wsdlWrapper = new WSDL4JWrapper(url);
			org.apache.axis2.jaxws.wsdl.SchemaReader sr= new SchemaReaderImpl();
			Set<String> set= sr.readPackagesFromSchema(wsdlWrapper.getDefinition());
			assertNotNull(set);
			Iterator<String> iter = set.iterator();
			while(iter.hasNext()){
                TestLogger.logger.debug("Package =" + iter.next());
			}
            TestLogger.logger.debug("------------------------------");
		} catch (MalformedURLException e) {
			e.printStackTrace();
			fail();
		}catch(FileNotFoundException e) {
			e.printStackTrace();
			fail();
		}catch(UnknownHostException e) {
			e.printStackTrace();
			fail();
		}catch(ConnectException e) {
			e.printStackTrace();
			fail();
        }catch(IOException e) {
            e.printStackTrace();
            fail();
		}catch(WSDLException e){
			e.printStackTrace();
			fail();
		}catch(SchemaReaderException e){
			e.printStackTrace();
			fail();
		}
		
		
		        
	}
}

Other Axis 2 examples (source code examples)

Here is a short list of links related to this Axis 2 PolymorphicTests.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.