use of javax.xml.ws.WebServiceException in project cxf by apache.
the class GreeterSessionImpl method greetMe.
// greetMe will use session to return last called name
public String greetMe(String me) {
LOG.info("Executing operation greetMe");
LOG.info("Message received: " + me);
MessageContext mc = context.getMessageContext();
HttpServletRequest req = (HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST);
Cookie[] cookies = req.getCookies();
String val = "";
if (cookies != null) {
for (Cookie cookie : cookies) {
val += ";" + cookie.getName() + "=" + cookie.getValue();
}
}
HttpSession session = req.getSession();
// Get a session property "counter" from context
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);
return "Hello " + name + val;
}
use of javax.xml.ws.WebServiceException in project cxf by apache.
the class JettyDigestAuthTest method doTest.
private void doTest(boolean async) throws Exception {
setupClient(async);
assertEquals("Hello Alice", greeter.greetMe("Alice"));
assertEquals("Hello Bob", greeter.greetMe("Bob"));
try {
BindingProvider bp = (BindingProvider) greeter;
if (async) {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("blah", "foo");
bp.getRequestContext().put(Credentials.class.getName(), creds);
} else {
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "blah");
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "foo");
}
greeter.greetMe("Alice");
fail("Password was wrong, should have failed");
} catch (WebServiceException wse) {
// ignore - expected
}
}
use of javax.xml.ws.WebServiceException in project cxf by apache.
the class CircuitBreakerFailoverTest method testWithAlternativeEnpdpoints.
@Test
public void testWithAlternativeEnpdpoints() throws Exception {
final Greeter g = getGreeter(REPLICA_A);
startTarget(REPLICA_E);
try {
final String response = g.greetMe("fred");
assertNotNull("expected non-null response", response);
} finally {
stopTarget(REPLICA_E);
}
try {
g.greetMe("fred");
fail("Expecting no alternative endpoints exception");
} catch (WebServiceException ex) {
assertThat(ex.getMessage(), equalTo("Could not send Message."));
}
}
use of javax.xml.ws.WebServiceException in project cxf by apache.
the class CircuitBreakerFailoverTest method testWithNoAlternativeEndpoints.
@Test
public void testWithNoAlternativeEndpoints() throws Exception {
final Greeter g = getGreeter(REPLICA_E);
try {
g.greetMe("fred");
fail("Expecting communication exception");
} catch (WebServiceException ex) {
assertThat(ex.getMessage(), equalTo("Could not send Message."));
}
try {
g.greetMe("fred");
fail("Expecting no alternative endpoints exception");
} catch (SOAPFaultException ex) {
assertThat(ex.getMessage(), equalTo("None of alternative addresses are available at the moment"));
}
}
use of javax.xml.ws.WebServiceException in project cxf by apache.
the class WSADisableTest method testDisableServerEnableClientRequired.
// CXF-3060
@Test
public void testDisableServerEnableClientRequired() throws Exception {
AddNumbersPortType port = getService().getAddNumbersPort(new AddressingFeature(true, true));
((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + PORT + "/jaxws/add");
try {
port.addNumbers(1, 2);
fail("Expected missing WSA header exception");
} catch (Exception e) {
assertTrue("expected WebServiceException", e instanceof WebServiceException);
String expected = "A required header representing a Message Addressing" + " Property is not present";
assertTrue("Caught unexpected exception : " + e.getMessage(), e.getMessage().indexOf(expected) > -1);
}
}
Aggregations