Package org.apache.camel.component.cxf.jaxrs.testbean

Examples of org.apache.camel.component.cxf.jaxrs.testbean.Customer


            }
           
        });
    
        // get the response message
        Customer response = (Customer) exchange.getOut().getBody();
       
        assertNotNull("The response should not be null ", response);
        assertEquals("Get a wrong customer id ", String.valueOf(response.getId()), "123");
        assertEquals("Get a wrong customer name", response.getName(), "John");
        // END SNIPPET: example       
    }
View Full Code Here


            }
           
        });
    
        // get the response message
        Customer response = (Customer) exchange.getOut().getBody();
       
        assertNotNull("The response should not be null ", response);
        assertEquals("Get a wrong customer id ", String.valueOf(response.getId()), "123");
        assertEquals("Get a wrong customer name", response.getName(), "John");
        // END SNIPPET: example-http
    }
View Full Code Here

                inMessage.setBody(null);               
            }
        });
    
        // get the response message
        Customer response = (Customer) exchange.getOut().getBody();
       
        assertNotNull("The response should not be null ", response);
        assertEquals("Get a wrong customer id ", String.valueOf(response.getId()), "123");
        assertEquals("Get a wrong customer name", response.getName(), "John");
        assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
    }
View Full Code Here

                inMessage.setBody(null);               
            }
        });
    
        // get the response message
        Customer response = (Customer) exchange.getOut().getBody();
       
        assertNotNull("The response should not be null ", response);
        assertEquals("Get a wrong customer id ", String.valueOf(response.getId()), "123");
        assertEquals("Get a wrong customer name", response.getName(), "John");
        assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
    }
View Full Code Here

                            assertEquals("Get a wrong http method", "GET", httpMethod);
                            String path = inMessage.getHeader(Exchange.HTTP_PATH, String.class);
                            // The parameter of the invocation is stored in the body of in message
                            String id = inMessage.getBody(String.class);
                            if ("/customerservice/customers/126".equals(path)) {                           
                                Customer customer = new Customer();
                                customer.setId(Long.parseLong(id));
                                customer.setName("Willem");
                                // We just put the response Object into the out message body
                                exchange.getOut().setBody(customer);
                            } else {
                                if ("/customerservice/customers/400".equals(path)) {
                                    // We return the remote client IP address this time
                                    org.apache.cxf.message.Message cxfMessage = inMessage.getHeader(CxfConstants.CAMEL_CXF_MESSAGE, org.apache.cxf.message.Message.class);
                                    ServletRequest request = (ServletRequest) cxfMessage.get("HTTP.REQUEST");
                                    String remoteAddress = request.getRemoteAddr();
                                    Response r = Response.status(200).entity("The remoteAddress is " + remoteAddress).build();
                                    exchange.getOut().setBody(r);
                                    return;
                                }
                                if ("/customerservice/customers/123".equals(path)) {
                                    // send a customer response back
                                    Response r = Response.status(200).entity("customer response back!").build();
                                    exchange.getOut().setBody(r);
                                    return;
                                }
                                if ("/customerservice/customers/456".equals(path)) {
                                    Response r = Response.status(404).entity("Can't found the customer with uri " + path).build();
                                    throw new WebApplicationException(r);
                                } else {
                                    throw new RuntimeCamelException("Can't found the customer with uri " + path);
                                }
                            }
                        }
                        if ("updateCustomer".equals(operationName)) {
                            assertEquals("Get a wrong customer message header", "header1;header2", inMessage.getHeader("test"));
                            String httpMethod = inMessage.getHeader(Exchange.HTTP_METHOD, String.class);
                            assertEquals("Get a wrong http method", "PUT", httpMethod);
                            Customer customer = inMessage.getBody(Customer.class);
                            assertNotNull("The customer should not be null.", customer);
                            // Now you can do what you want on the customer object
                            assertEquals("Get a wrong customer name.", "Mary", customer.getName());
                            // set the response back
                            exchange.getOut().setBody(Response.ok().build());
                        }
                       
                    }
View Full Code Here

        return new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/jaxrs/CxfOperationException.xml");
    }

    @Test(expected = CamelExecutionException.class)
    public void testRestServerDirectlyAddCustomer() {
        Customer input = new Customer();
        input.setName("Donald Duck");

        // we cannot convert directly to Customer as we need camel-jaxb
        String response = template.requestBodyAndHeader("cxfrs:http://localhost:" + PORT1 + "/CxfOperationExceptionTest/customerservice/customers?throwExceptionOnFailure=true", input,
            Exchange.HTTP_METHOD, "POST", String.class);
View Full Code Here

        assertTrue(response.endsWith("<name>Donald Duck</name></Customer>"));
    }

    @Test
    public void testRestServerDirectlyAddCustomerWithExceptionsTurnedOff() {
        Customer input = new Customer();
        input.setName("Donald Duck");

        // we cannot convert directly to Customer as we need camel-jaxb
        String response = template.requestBodyAndHeader("cxfrs:bean:rsClient?throwExceptionOnFailure=false", input,
            Exchange.HTTP_METHOD, "POST", String.class);
View Full Code Here

                inMessage.setBody("123");
            }
        });
    
        // get the response message
        Customer response = (Customer) exchange.getOut().getBody();
       
        assertNotNull("The response should not be null ", response);
        assertEquals("Get a wrong customer id ", String.valueOf(response.getId()), "123");
        assertEquals("Get a wrong customer name", response.getName(), "John");
        assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
        assertEquals("Get a wrong header value", "value", exchange.getOut().getHeader("key"));
        // END SNIPPET: ProxyExample    
    }
View Full Code Here

    
        // get the response message
        List<Customer> response = CastUtils.cast((List<?>) exchange.getOut().getBody());
       
        assertNotNull("The response should not be null ", response);
        assertTrue("Dan is missing!", response.contains(new Customer(113, "Dan")));
        assertTrue("John is missing!", response.contains(new Customer(123, "John")));
        assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
    }
View Full Code Here

                inMessage.setBody(null);               
            }
        });
    
        // get the response message
        Customer response = (Customer) exchange.getOut().getBody();
       
        assertNotNull("The response should not be null ", response);
        assertEquals("Get a wrong customer id ", String.valueOf(response.getId()), "123");
        assertEquals("Get a wrong customer name", response.getName(), "John");
        assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
        assertEquals("Get a wrong header value", "value", exchange.getOut().getHeader("key"));
        // END SNIPPET: HttpExample
    }
View Full Code Here

TOP

Related Classes of org.apache.camel.component.cxf.jaxrs.testbean.Customer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.