use of javax.xml.ws.WebServiceException in project cxf by apache.
the class OutBoundConnectionTest method testBasicConnection.
@Test
@org.junit.Ignore
public void testBasicConnection() throws Exception {
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(wsdl);
SOAPService service = new SOAPService(wsdl, serviceName);
assertNotNull(service);
CXFConnectionRequestInfo cri = new CXFConnectionRequestInfo(Greeter.class, wsdl, service.getServiceName(), portName);
cri.setAddress("http://localhost:" + PORT + "/SoapContext/SoapPort");
ManagedConnectionFactory managedFactory = new ManagedConnectionFactoryImpl();
Subject subject = new Subject();
ManagedConnection mc = managedFactory.createManagedConnection(subject, cri);
Object o = mc.getConnection(subject, cri);
// test for the Object hash()
try {
o.hashCode();
o.toString();
} catch (WebServiceException ex) {
fail("The connection object should support Object method");
}
verifyResult(o);
}
use of javax.xml.ws.WebServiceException in project cxf by apache.
the class OASISCatalogTest method testClientWithoutCatalog.
@Test
public void testClientWithoutCatalog() throws Exception {
URL wsdl = getClass().getResource("/wsdl/catalog/hello_world_services.wsdl");
assertNotNull(wsdl);
// set Catalog on the Bus
Bus bus = BusFactory.getDefaultBus();
OASISCatalogManager catalog = new OASISCatalogManager();
bus.setExtension(catalog, OASISCatalogManager.class);
// prevent cache from papering over the lack of a schema.
WSDLManagerImpl mgr = (WSDLManagerImpl) bus.getExtension(WSDLManager.class);
mgr.setDisableSchemaCache(true);
try {
SOAPService service = new SOAPService(wsdl, serviceName);
service.getPort(portName, Greeter.class);
fail("Test did not fail as expected");
} catch (WebServiceException e) {
// ignore
}
// update catalog dynamically now
Enumeration<URL> jaxwscatalog = getClass().getClassLoader().getResources("META-INF/jax-ws-catalog.xml");
assertNotNull(jaxwscatalog);
while (jaxwscatalog.hasMoreElements()) {
URL url = jaxwscatalog.nextElement();
catalog.loadCatalog(url);
}
SOAPService service = new SOAPService(wsdl, serviceName);
Greeter greeter = service.getPort(portName, Greeter.class);
assertNotNull(greeter);
bus.shutdown(true);
}
use of javax.xml.ws.WebServiceException in project cxf by apache.
the class ValidationClientServerTest method runSchemaValidationTest.
private void runSchemaValidationTest(SchemaValidation validation) {
ComplexStruct complexStruct = new ComplexStruct();
complexStruct.setElem1("one");
// Don't initialize a member of the structure.
// Client side validation should throw an exception.
// complexStruct.setElem2("two");
complexStruct.setElem3(3);
try {
/*boolean result =*/
validation.setComplexStruct(complexStruct);
fail("Set ComplexStruct should have thrown ProtocolException");
} catch (WebServiceException e) {
String expected = "'{\"http://apache.org/schema_validation/types\":elem2}' is expected.";
assertTrue(e.getMessage(), e.getMessage().indexOf(expected) != -1);
}
OccuringStruct occuringStruct = new OccuringStruct();
// Populate the list in the wrong order.
// Client side validation should throw an exception.
List<Serializable> floatIntStringList = occuringStruct.getVarFloatAndVarIntAndVarString();
floatIntStringList.add(new Integer(42));
floatIntStringList.add(new Float(4.2f));
floatIntStringList.add("Goofus and Gallant");
try {
/*boolean result =*/
validation.setOccuringStruct(occuringStruct);
fail("Set OccuringStruct should have thrown ProtocolException");
} catch (WebServiceException e) {
String expected = "'{\"http://apache.org/schema_validation/types\":varFloat}' is expected.";
assertTrue(e.getMessage().indexOf(expected) != -1);
}
try {
// The server will attempt to return an invalid ComplexStruct
// When validation is disabled on the server side, we'll get the
// exception while unmarshalling the invalid response.
/*complexStruct =*/
validation.getComplexStruct("Hello");
fail("Get ComplexStruct should have thrown ProtocolException");
} catch (WebServiceException e) {
String expected = "'{\"http://apache.org/schema_validation/types\":elem2}' is expected.";
assertTrue("Found message " + e.getMessage(), e.getMessage().indexOf(expected) != -1);
}
try {
// The server will attempt to return an invalid OccuringStruct
// When validation is disabled on the server side, we'll get the
// exception while unmarshalling the invalid response.
/*occuringStruct =*/
validation.getOccuringStruct("World");
fail("Get OccuringStruct should have thrown ProtocolException");
} catch (WebServiceException e) {
String expected = "'{\"http://apache.org/schema_validation/types\":varFloat}' is expected.";
assertTrue(e.getMessage().indexOf(expected) != -1);
}
SomeRequest req = new SomeRequest();
req.setId("9999999999");
try {
validation.doSomething(req);
fail("Should have faulted");
} catch (DoSomethingFault e) {
assertEquals("1234", e.getFaultInfo().getErrorCode());
}
req.setId("8888888888");
try {
validation.doSomething(req);
fail("Should have faulted");
} catch (DoSomethingFault e) {
fail("Should not have happened");
} catch (WebServiceException e) {
String expected = "Value '1' is not facet-valid";
assertTrue(e.getMessage().indexOf(expected) != -1);
}
}
use of javax.xml.ws.WebServiceException in project cxf by apache.
the class GreeterSessionImpl method greetMeOneWay.
public void greetMeOneWay(String me) {
LOG.info("Executing operation greetMeOneWay");
LOG.info("Message received: " + me);
MessageContext mc = context.getMessageContext();
HttpServletRequest req = (HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST);
HttpSession session = req.getSession();
if (session == null) {
throw new WebServiceException("No session in WebServiceContext");
}
String name = (String) session.getAttribute("name");
if (name == null) {
name = me;
LOG.info("Starting the Session");
}
session.setAttribute("name", me);
}
use of javax.xml.ws.WebServiceException in project cxf by apache.
the class SmallNumberHandler method handleMessage.
// Implementation of javax.xml.ws.handler.Handler
public final boolean handleMessage(LogicalMessageContext messageContext) {
System.out.println("LogicalMessageHandler handleMessage called");
try {
boolean outbound = (Boolean) messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outbound) {
// get the LogicalMessage from our context
//
LogicalMessage msg = messageContext.getMessage();
// check the payload, if its an AddNumbers request, we'll intervene
//
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
Object payload = msg.getPayload(jaxbContext);
if (payload instanceof JAXBElement) {
payload = ((JAXBElement) payload).getValue();
}
if (payload instanceof AddNumbers) {
AddNumbers req = (AddNumbers) payload;
// now, if the arguments are small, let's do the calculation here
//
int a = req.getArg0();
int b = req.getArg1();
if (isSmall(a) && isSmall(b)) {
int answer = a + b;
// System.out.printf("SmallNumberHandler addNumbers(%d, %d) == %d\n", a, b, answer);
// ok, we've done the calculation, so build the
// response and set it as the payload of the message
AddNumbersResponse resp = new AddNumbersResponse();
resp.setReturn(answer);
msg.setPayload(new ObjectFactory().createAddNumbersResponse(resp), jaxbContext);
Source src = msg.getPayload();
msg.setPayload(src);
payload = msg.getPayload(jaxbContext);
if (payload instanceof JAXBElement) {
payload = ((JAXBElement) payload).getValue();
}
AddNumbersResponse resp2 = (AddNumbersResponse) payload;
if (resp2 == resp) {
throw new WebServiceException("Shouldn't be the same object");
}
// returned to the client
return false;
}
}
}
return true;
} catch (JAXBException ex) {
throw new ProtocolException(ex);
}
}
Aggregations