1 Reply Latest reply: Nov 20, 2009 1:14 AM by Aaron Zhang RSS

    access a SOAP webservice from Clearspace

    Alistair Lenhard

      Hi All,

       

      I am new to this webservice idea- however we have something implemented as a webservice and we can make available a wsdl -

      I would like to access that from clearspace as clearspace will be the login point. Is that possible and if yes how would I start in doing so?

       

      Any examples? I mean I saw quite a lot of documentation on how to access clearspace from a webservice but not the other way around.

       

      Hints and tips are highly appreciated!!!!

       

      Thank you so much.

      Alistair

        • Re: access a SOAP webservice from Clearspace
          Aaron Zhang

          REST WebService

           

          /**
               * 
               */
              public Community createCommunity(Community community) {
                      HttpClient client = new HttpClient();
                      Credentials defaultcreds = new UsernamePasswordCredentials("admin","pw");
                      client.getState().setCredentials(AuthScope.ANY, defaultcreds);
          
                      PostMethod method = new PostMethod("http://localhost:8080/2512/rpc/rest/communityService/communities");
          
                   
                      StringRequestEntity xml = new StringRequestEntity(
                          "<createCommunity>" + 
                              "<name><![CDATA[" +  community.getName() + "]]></name>" +
                              "<displayName><![CDATA[" + GURU_COMMUNITY_PREFIX + community.getName() + "]]></displayName>" +
                              "<description><![CDATA[" + community.getName() + "]]></description>" +
                              "<communityID><![CDATA[" + community.getParentCommunityID() + "]]></communityID>" +
                          "</createCommunity>);");
                    
                      try{
                          method.setRequestEntity(xml);
                          method.setRequestHeader("Content-Type", "text/xml");
                           client.executeMethod(method);
                          InputStream in = method.getResponseBodyAsStream();
                          SAXReader reader = new SAXReader();
                          Document document = reader.read(in);
                          
          //                XMLWriter writer = new XMLWriter(System.out, OutputFormat.createPrettyPrint());
          //                writer.write(document);
                          
                          Node node = document.selectSingleNode("/createCommunityResponse/return/ID");    
                          community.setID(Long.valueOf(node.getText()));
                          
                          method.releaseConnection();
                          
                          log.info(community.getName() + " creation  succeedeed.");
                          
                      } catch(Exception e){
                          log.error(community.getName() + " creation  failed.");
                          log.debug(e, e);
                      }
                      return community;
              }
          

           

          Hope it is helpful to you.