Search in sources :

Example 51 with WebServiceException

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Cookie(javax.servlet.http.Cookie) WebServiceException(javax.xml.ws.WebServiceException) HttpSession(javax.servlet.http.HttpSession) MessageContext(javax.xml.ws.handler.MessageContext)

Example 52 with WebServiceException

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
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) BindingProvider(javax.xml.ws.BindingProvider) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 53 with WebServiceException

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."));
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) Greeter(org.apache.cxf.greeter_control.Greeter) Test(org.junit.Test)

Example 54 with WebServiceException

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"));
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) Greeter(org.apache.cxf.greeter_control.Greeter) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.junit.Test)

Example 55 with WebServiceException

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);
    }
}
Also used : AddNumbersPortType(org.apache.cxf.systest.ws.addr_feature.AddNumbersPortType) AddressingFeature(javax.xml.ws.soap.AddressingFeature) WebServiceException(javax.xml.ws.WebServiceException) WebServiceException(javax.xml.ws.WebServiceException) Test(org.junit.Test)

Aggregations

WebServiceException (javax.xml.ws.WebServiceException)120 Test (org.junit.Test)50 URL (java.net.URL)37 BindingProvider (javax.xml.ws.BindingProvider)25 Service (javax.xml.ws.Service)22 QName (javax.xml.namespace.QName)14 IOException (java.io.IOException)10 Message (org.apache.cxf.common.i18n.Message)9 JAXBException (javax.xml.bind.JAXBException)8 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)8 Bus (org.apache.cxf.Bus)7 Packet (com.sun.xml.ws.api.message.Packet)6 AuthStatus (javax.security.auth.message.AuthStatus)6 SOAPException (javax.xml.soap.SOAPException)6 SOAPMessage (javax.xml.soap.SOAPMessage)6 ArrayList (java.util.ArrayList)5 WebService (javax.jws.WebService)5 Subject (javax.security.auth.Subject)5 HttpSession (javax.servlet.http.HttpSession)5 Handler (javax.xml.ws.handler.Handler)5