You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Joel Turkel <jt...@Endeca.com> on 2011/02/08 04:10:20 UTC

Multiple Instances of Java First JAX-WS Service + Schema Validation

Hi,

I'm trying to publish two different instances of a JAX-WS service to two
different addresses using the Java first approach. Everything works
perfectly until I enable schema validation. When I turn on schema
validation, requests to the first instance of the service work fine but
requests to the second instance of the service  fail with the error
"org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration
of element 'ns2:sayHi'." I'm using CXF 2.2.3 but the problem also
reproduces uses 2.3.2. I can also reproduce the problem using SoapUI.
The test code that reproduces the problem and the service (a simplified
version of the Hello World service from the CXF user guide) is included
below. Am I doing something wrong here?

Thanks,
Joel

public class HelloWorldTest {

	public static void main(String[] args) {
		String address1 = "http://localhost:8888/service1";
		String address2 = "http://localhost:8888/service2";
		publish(new HelloWorldImpl(), address1);
		publish(new HelloWorldImpl(), address2);
		
		getClient(address1).sayHi("hello");

		try {
			getClient(address2).sayHi("hello");
		}
		finally {
			System.exit(0);
		}
	}
	
	private static HelloWorld getClient(String address) {
		JaxWsProxyFactoryBean factory = new
JaxWsProxyFactoryBean();
		factory.setServiceClass(HelloWorld.class);
		factory.setAddress(address);
		return (HelloWorld)factory.create();
	}
	
	private static void publish(HelloWorld service, String address)
{
		Endpoint endpoint = Endpoint.create(service);
		
		// Turn on schema validation
		Map<String, Object> properties = new HashMap<String,
Object>();
		properties.put("schema-validation-enabled", true);
		endpoint.setProperties(properties);
		
		endpoint.publish(address);
	}
}


@WebService
public interface HelloWorld {
		
	public void sayHi(String text);
}


@WebService(endpointInterface="com.sample.HelloWorld",
			serviceName="HelloWorld")
public class HelloWorldImpl implements HelloWorld {
	
	@Override
	public void sayHi(String text) {
		System.out.println(text);
	}
}