Search in sources :

Example 81 with WebServiceException

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);
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) ManagedConnectionFactory(javax.resource.spi.ManagedConnectionFactory) WebServiceException(javax.xml.ws.WebServiceException) CXFConnectionRequestInfo(org.apache.cxf.jca.cxf.CXFConnectionRequestInfo) ManagedConnectionFactoryImpl(org.apache.cxf.jca.cxf.ManagedConnectionFactoryImpl) ManagedConnection(javax.resource.spi.ManagedConnection) URL(java.net.URL) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 82 with WebServiceException

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);
}
Also used : SOAPService(org.apache.hello_world.services.SOAPService) Bus(org.apache.cxf.Bus) WebServiceException(javax.xml.ws.WebServiceException) Greeter(org.apache.hello_world.Greeter) OASISCatalogManager(org.apache.cxf.catalog.OASISCatalogManager) WSDLManagerImpl(org.apache.cxf.wsdl11.WSDLManagerImpl) WSDLManager(org.apache.cxf.wsdl.WSDLManager) URL(java.net.URL) Test(org.junit.Test)

Example 83 with WebServiceException

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);
    }
}
Also used : Serializable(java.io.Serializable) OccuringStruct(org.apache.schema_validation.types.OccuringStruct) DoSomethingFault(org.apache.schema_validation.DoSomethingFault) WebServiceException(javax.xml.ws.WebServiceException) SomeRequest(org.apache.schema_validation.types.SomeRequest) ComplexStruct(org.apache.schema_validation.types.ComplexStruct)

Example 84 with WebServiceException

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

Example 85 with WebServiceException

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);
    }
}
Also used : ProtocolException(javax.xml.ws.ProtocolException) WebServiceException(javax.xml.ws.WebServiceException) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) AddNumbersResponse(org.apache.handlers.types.AddNumbersResponse) JAXBElement(javax.xml.bind.JAXBElement) Source(javax.xml.transform.Source) ObjectFactory(org.apache.handlers.types.ObjectFactory) AddNumbers(org.apache.handlers.types.AddNumbers) LogicalMessage(javax.xml.ws.LogicalMessage)

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