Wednesday, February 22, 2012

Http request uing jersy client

 ClientConfig config = new DefaultClientConfig();
        Client client = Client.create(config);
        WebResource service = client.resource(uri);
       
       
       
        try {
           
            PersistenceService salesForceService = new SalesForceService();
            PartnerConnection connection = salesForceService.authenticate(authEndpoint, username, password);
            String sessionId = connection.getSessionHeader().getSessionId();
            String serviceEndpoint = connection.getConfig().getServiceEndpoint();
           
            Date date = new Date();
            logger.debug("Document received at " + new Timestamp(date.getTime()));
            InputStream inputStream = new FileInputStream(fileName);
           
            String response =
                service.path(mapping).type("text/xml; charset=utf-8").accept(MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN)
                .header("sessionId", sessionId)
                .header("serviceEndpoint", serviceEndpoint)
                    .post(String.class, inputStream);
           
           
            System.out.println(response);
           
        } catch (Exception e) {
            e.printStackTrace();
        }

No comments:

Post a Comment