Java Code Examples for javax.xml.ws.BindingProvider#getResponseContext()

The following examples show how to use javax.xml.ws.BindingProvider#getResponseContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientServerWebSocketTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasicConnection() throws Exception {

    SOAPService service = new SOAPService();

    Greeter greeter = service.getPort(portName, Greeter.class);
    updateGreeterAddress(greeter, PORT);

    try {
        String reply = greeter.greetMe("test");
        assertNotNull("no response received from service", reply);
        assertEquals("Hello test", reply);

        reply = greeter.sayHi();
        assertNotNull("no response received from service", reply);
        assertEquals("Bonjour", reply);
    } catch (UndeclaredThrowableException ex) {
        throw (Exception)ex.getCause();
    }
    BindingProvider bp = (BindingProvider)greeter;
    Map<String, Object> responseContext = bp.getResponseContext();
    Integer responseCode = (Integer) responseContext.get(Message.RESPONSE_CODE);
    assertEquals(200, responseCode.intValue());
}
 
Example 2
Source File: ClientServerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasicConnection() throws Exception {

    SOAPService service = new SOAPService();
    assertNotNull(service);

    Greeter greeter = service.getPort(portName, Greeter.class);
    updateAddressPort(greeter, PORT);
    try {
        greeter.greetMe("test");

        String reply = greeter.sayHi();
        assertNotNull("no response received from service", reply);
        assertEquals("Bonjour", reply);
    } catch (UndeclaredThrowableException ex) {
        throw (Exception)ex.getCause();
    }
    BindingProvider bp = (BindingProvider)greeter;
    Map<String, Object> responseContext = bp.getResponseContext();
    Integer responseCode = (Integer) responseContext.get(Message.RESPONSE_CODE);
    assertEquals(200, responseCode.intValue());
}
 
Example 3
Source File: JMSSharedQueueTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void callGreetMe() {
    BindingProvider bp = (BindingProvider)port;
    Map<String, Object> requestContext = bp.getRequestContext();
    JMSMessageHeadersType requestHeader = new JMSMessageHeadersType();
    requestContext.put(JMSConstants.JMS_CLIENT_REQUEST_HEADERS, requestHeader);
    String request = "World" + ((prefix != null) ? ":" + prefix : "");
    String correlationID = null;
    if (corrFactory != null) {
        correlationID = corrFactory.createCorrealtionID();
        requestHeader.setJMSCorrelationID(correlationID);
        request +=  ":" + correlationID;
    }
    String expected = "Hello " + request;
    String response = port.greetMe(request);
    Assert.assertEquals("Response didn't match expected request", expected, response);
    if (corrFactory != null) {
        Map<String, Object> responseContext = bp.getResponseContext();
        JMSMessageHeadersType responseHeader =
            (JMSMessageHeadersType)responseContext.get(
                    JMSConstants.JMS_CLIENT_RESPONSE_HEADERS);
        Assert.assertEquals("Request and Response CorrelationID didn't match",
                      correlationID, responseHeader.getJMSCorrelationID());
    }
}
 
Example 4
Source File: AbstractHeaderServiceRpcLitTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void verifyFaultCode(HeaderTester proxy) {
    BindingProvider bp = (BindingProvider)proxy;
    java.util.Map<String, Object> respCtx = bp.getResponseContext();
    assertNotNull(respCtx);
    Integer val = (Integer)respCtx.get(Message.RESPONSE_CODE);
    assertNotNull(val);
    assertEquals("Message.RESPONSE_CODE should be 500", 500,  val.intValue());
}
 
Example 5
Source File: ClientServerXMLTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddPort() throws Exception {
    URL url = getClass().getResource("/wsdl/hello_world_xml_wrapped.wsdl");

    Service service = Service.create(url, wrapServiceName);
    assertNotNull(service);

    service.addPort(wrapFakePortName, "http://cxf.apache.org/bindings/xformat",
            "http://localhost:" + WRAP_PORT + "/XMLService/XMLPort");

    String response1 = new String("Hello ");
    String response2 = new String("Bonjour");

    org.apache.hello_world_xml_http.wrapped.Greeter greeter = service.getPort(wrapPortName,
            org.apache.hello_world_xml_http.wrapped.Greeter.class);
    updateAddressPort(greeter, WRAP_PORT);

    try {
        String username = System.getProperty("user.name");
        String reply = greeter.greetMe(username);

        assertNotNull("no response received from service", reply);
        assertEquals(response1 + username, reply);

        reply = greeter.sayHi();
        assertNotNull("no response received from service", reply);
        assertEquals(response2, reply);

        BindingProvider bp = (BindingProvider) greeter;
        Map<String, Object> responseContext = bp.getResponseContext();
        Integer responseCode = (Integer) responseContext.get(Message.RESPONSE_CODE);
        assertEquals(200, responseCode.intValue());

        greeter.greetMeOneWay(System.getProperty("user.name"));

    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }

}
 
Example 6
Source File: SOAPJMSTestSuiteTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void twoWayTestWithRequestHeader(TestCaseType testcase, final JMSSimplePortType port,
                                         JMSMessageHeadersType requestHeader)
    throws Exception {
    closeable = (java.io.Closeable)port;
    InvocationHandler handler = Proxy.getInvocationHandler(port);
    BindingProvider bp = (BindingProvider)handler;

    Map<String, Object> requestContext = bp.getRequestContext();
    if (requestHeader == null) {
        requestHeader = new JMSMessageHeadersType();
    }
    requestContext.put(JMSConstants.JMS_CLIENT_REQUEST_HEADERS, requestHeader);
    Exception e = null;
    try {
        String response = port.echo("test");
        assertEquals(response, "test");
    } catch (WebServiceException ew) {
        throw ew;
    } catch (Exception e1) {
        e = e1;
    }
    Map<String, Object> responseContext = bp.getResponseContext();
    JMSMessageHeadersType responseHeader = (JMSMessageHeadersType)responseContext
        .get(JMSConstants.JMS_CLIENT_RESPONSE_HEADERS);
    checkJMSProperties(testcase, requestHeader, responseHeader);
    if (e != null) {
        throw e;
    }
}
 
Example 7
Source File: SoapJmsSpecTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testBindingVersionError() throws Exception {
    QName serviceName = new QName(SERVICE_NS, "JMSGreeterService");
    QName portName = new QName(SERVICE_NS, "GreeterPort");
    URL wsdl = getWSDLURL(WSDL);
    JMSGreeterService service = new JMSGreeterService(wsdl, serviceName);

    JMSGreeterPortType greeter = markForClose(service.getPort(portName, JMSGreeterPortType.class, cff));
    BindingProvider bp = (BindingProvider)greeter;

    Map<String, Object> requestContext = bp.getRequestContext();
    JMSMessageHeadersType requestHeader = new JMSMessageHeadersType();
    requestHeader.setSOAPJMSBindingVersion("0.3");
    requestContext.put(JMSConstants.JMS_CLIENT_REQUEST_HEADERS, requestHeader);

    try {
        greeter.greetMe("Milestone-");
        Assert.fail("Should have thrown a fault");
    } catch (SOAPFaultException ex) {
        Assert.assertTrue(ex.getMessage().contains("0.3"));
        Map<String, Object> responseContext = bp.getResponseContext();
        JMSMessageHeadersType responseHdr = (JMSMessageHeadersType)responseContext
            .get(JMSConstants.JMS_CLIENT_RESPONSE_HEADERS);
        if (responseHdr == null) {
            Assert.fail("response Header should not be null");
        }
        Assert.assertTrue(responseHdr.isSOAPJMSIsFault());
    }
}
 
Example 8
Source File: ClientServerWebSocketTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testFaults() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);

    SOAPService service = new SOAPService(wsdl, serviceName);
    ExecutorService ex = Executors.newFixedThreadPool(1);
    service.setExecutor(ex);
    assertNotNull(service);

    String noSuchCodeFault = "NoSuchCodeLitFault";
    String badRecordFault = "BadRecordLitFault";

    Greeter greeter = service.getPort(portName, Greeter.class);
    updateGreeterAddress(greeter, PORT);

    for (int idx = 0; idx < 2; idx++) {
        try {
            greeter.testDocLitFault(noSuchCodeFault);
            fail("Should have thrown NoSuchCodeLitFault exception");
        } catch (NoSuchCodeLitFault nslf) {
            assertNotNull(nslf.getFaultInfo());
            assertNotNull(nslf.getFaultInfo().getCode());
        }

        try {
            greeter.testDocLitFault(badRecordFault);
            fail("Should have thrown BadRecordLitFault exception");
        } catch (BadRecordLitFault brlf) {
            BindingProvider bp = (BindingProvider)greeter;
            Map<String, Object> responseContext = bp.getResponseContext();
            String contentType = (String) responseContext.get(Message.CONTENT_TYPE);
            assertEquals("text/xml; charset=utf-8", contentType.toLowerCase());
            Integer responseCode = (Integer) responseContext.get(Message.RESPONSE_CODE);
            assertEquals(500, responseCode.intValue());
            assertNotNull(brlf.getFaultInfo());
            assertEquals("BadRecordLitFault", brlf.getFaultInfo());
        }

    }

}