Hi,

You can set the provider in JAXRSClientFactoryBean. Below is the code snippet I 
used in my code:

JAXRSClientFactoryBean factoryBean = new JAXRSClientFactoryBean();
factoryBean.setResourceClass(MobileHotelService.class);
factoryBean.setAddress(url);
factoryBean.setProvider(new MobileJAXBProvider());
                        
interfaze = factoryBean.create(MobileHotelService.class);
org.apache.cxf.jaxrs.client.Client client = WebClient.client(interfaze);
client.accept("application/xml");
client.type("application/xml");
client.header("username", username);
client.header("authtoken", authtoken);

Regards,
Abhishek

-----Original Message-----
From: amathewcxf [mailto:[email protected]] 
Sent: Wednesday, June 06, 2012 6:16 AM
To: [email protected]
Subject: RE: How to use XSD file with cxf

The good news is I was able to get the response from the remote service by
using the following code:

        @Test
        public void testJSONGetAvailability() throws Exception {

                if (this.getAvailabilityService != null) {
                        try {
                                WebClient webClient =
WebClient.create("https://myremotews/v1?eventId=1146";, "username",
"password", null);
                                webClient.accept(MediaType.APPLICATION_JSON);

                                HTTPConduit conduit = 
WebClient.getConfig(webClient).getHttpConduit();
                                
conduit.setTlsClientParameters(getConfiguredClientSSLParms(webClient));
                                Response res = webClient.get();

*                               InputStream resIs = (InputStream) 
res.getEntity();

                                Object availObj = unmarshallJSONFile(resIs);*
                                if (availObj != null) {
                                        if (availObj instanceof Availability) {
                                                Availability avail = 
(Availability) availObj;
                                                // I AM GETTING THE 
AVAILABILITY OBJECT HERE!!!
                                        }
                                }
                        } catch (Throwable e) {
                                System.out.println("Error in 
testGetAvailability:" + e);
                        }

                }
        }

----
Below is the unmarshallJSONFile method:

        public Object unmarshallJSONFile(InputStream is) {

                String response = "";
                try {
                        JAXBContext jc = 
JAXBContext.newInstance(Availability.class); 
                        
                        InputStreamReader sReader = new InputStreamReader(is);
                        LineNumberReader reader = new LineNumberReader(sReader);
                        StringWriter strWriter = new StringWriter();
                        PrintWriter writer = new PrintWriter(strWriter);
                        String str =  reader.readLine(); 
                        while (str != null) {
                                if (str.length() > 0) {
                                        writer.println(str);
                                }
                                str = reader.readLine();
                        }
                        writer.flush();
                        response = strWriter.toString();
                        JSONObject jsonObject = new JSONObject(response);
                        
                Configuration config = new Configuration();   
                MappedNamespaceConvention con = new
MappedNamespaceConvention(config);   
                XMLStreamReader xmlStreamReader = new
MappedXMLStreamReader(jsonObject, con);     
                Unmarshaller unmarshaller = jc.createUnmarshaller();         
                return unmarshaller.unmarshal(xmlStreamReader);                 
        

                } catch (Throwable e) {
                        
                }
                
                return null;
        }

----

But I don't wantto do unmarshallJSONFile coding as I wanted to use
"JacksonJsonProvider" assuming that it  will do the same for me. But with
JacksonJsonProvider, i am not able to send the username/password as I don't
see a WebClient.create method which takes the BaseURI, username, password,
providerList. So i wonder how do i do this? Any thoughts will help me.

Thanks for the help

Anil Mathew







--
View this message in context: 
http://cxf.547215.n5.nabble.com/How-to-use-XSD-file-with-cxf-tp5708311p5709160.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to