Difference between revisions of "Java client - OpenKM 6.2"

From OpenKM Documentation
Jump to: navigation, search
 
(14 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
First, we need to generate the client stuff using this command. Keep on mind that you need JDK 1.6 to run it:
 
First, we need to generate the client stuff using this command. Keep on mind that you need JDK 1.6 to run it:
  
  $ wsimport -d client -s client http://localhost:8080/OpenKM/OKMAuth?wsdl
+
  $ wsimport -p com.openkm.ws.client -keep http://localhost:8080/OpenKM/services/OKMAuth?wsdl
  
 
You can use the following script to generate a complete OpenKM webservices client library:
 
You can use the following script to generate a complete OpenKM webservices client library:
Line 10: Line 10:
 
#/bin/bash
 
#/bin/bash
  
wsimport -p com.openkm.ws.client http://localhost:8080/OpenKM/OKMAuth?wsdl
+
wsimport -p com.openkm.ws.client.auth -keep http://localhost:8080/OpenKM/services/OKMAuth?wsdl
wsimport -p com.openkm.ws.client http://localhost:8080/OpenKM/OKMDocument?wsdl
+
wsimport -p com.openkm.ws.client.bookmark -keep http://localhost:8080/OpenKM/services/OKMBookmark?wsdl
wsimport -p com.openkm.ws.client http://localhost:8080/OpenKM/OKMFolder?wsdl
+
wsimport -p com.openkm.ws.client.document -keep http://localhost:8080/OpenKM/services/OKMDocument?wsdl
wsimport -p com.openkm.ws.client http://localhost:8080/OpenKM/OKMSearch?wsdl
+
wsimport -p com.openkm.ws.client.folder -keep http://localhost:8080/OpenKM/services/OKMFolder?wsdl
wsimport -p com.openkm.ws.client http://localhost:8080/OpenKM/OKMNotification?wsdl
+
wsimport -p com.openkm.ws.client.mail -keep http://localhost:8080/OpenKM/services/OKMMail?wsdl
wsimport -p com.openkm.ws.client http://localhost:8080/OpenKM/OKMRepository?wsdl
+
wsimport -p com.openkm.ws.client.note -keep http://localhost:8080/OpenKM/services/OKMNote?wsdl
wsimport -p com.openkm.ws.client http://localhost:8080/OpenKM/OKMPropertyGroup?wsdl
+
wsimport -p com.openkm.ws.client.notification -keep http://localhost:8080/OpenKM/services/OKMNotification?wsdl
wsimport -p com.openkm.ws.client http://localhost:8080/OpenKM/OKMWorkflow?wsdl
+
wsimport -p com.openkm.ws.client.propertyGroup -keep http://localhost:8080/OpenKM/services/OKMPropertyGroup?wsdl
 +
wsimport -p com.openkm.ws.client.property -keep http://localhost:8080/OpenKM/services/OKMProperty?wsdl
 +
wsimport -p com.openkm.ws.client.repository -keep http://localhost:8080/OpenKM/services/OKMRepository?wsdl
 +
wsimport -p com.openkm.ws.client.search -keep http://localhost:8080/OpenKM/services/OKMSearch?wsdl
 +
wsimport -p com.openkm.ws.client.workflow -keep http://localhost:8080/OpenKM/services/OKMWorkflow?wsdl
  
jar cvf okm-ws-client-6.0.jar com
+
jar cvf okm-ws-client-6.2.jar com
  
 
rm -rf com
 
rm -rf com
 +
</source>
 +
 +
'''How can I change the Web Service address dynamically for a request ?'''
 +
<source lang="java">
 +
OKMAuth okmAuth = new OKMAuth_Service(new URL(url + "/services/OKMAuth?wsdl"),
 +
    new QName("http://ws.openkm.com", "OKMAuth")).getOKMAuthPort();
 +
</source>
 +
 +
or
 +
 +
<source lang="java">
 +
((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "...");
 
</source>
 
</source>
  
Line 29: Line 45:
 
package com.openkm.ws.test;
 
package com.openkm.ws.test;
  
import com.openkm.ws.client.Auth;
+
import com.openkm.ws.client.auth.OKMAuth;
import com.openkm.ws.client.Auth_Service;
+
import com.openkm.ws.client.auth.OKMAuth_Service;
  
 
public class Authentication {
 
public class Authentication {
 
     public static void main(String[] args) {
 
     public static void main(String[] args) {
 
         try {
 
         try {
             Auth_Service authService = new Auth_Service();
+
             OKMAuth okmAuth = new OKMAuth_Service().getOKMAuthPort();
            Auth auth = authService.getAuthPort();
 
  
 
             // Login
 
             // Login
             String token = auth.login("okmAdmin", "admin");
+
             String token = okmAuth.login("okmAdmin", "admin");
             System.out.println("Es: " + token);
+
             System.out.println("Token: " + token);
  
 
             // Logout
 
             // Logout
Line 59: Line 74:
 
import java.util.List;
 
import java.util.List;
  
import com.openkm.ws.client.Auth;
+
import com.openkm.ws.client.auth.OKMAuth;
import com.openkm.ws.client.Auth_Service;
+
import com.openkm.ws.client.auth.OKMAuth_Service;
 
import com.openkm.ws.client.PropertyGroup;
 
import com.openkm.ws.client.PropertyGroup;
 
import com.openkm.ws.client.PropertyGroup_Service;
 
import com.openkm.ws.client.PropertyGroup_Service;
Line 66: Line 81:
  
 
public class PropertyGroups {
 
public class PropertyGroups {
public static void main(String[] args) throws Exception {
+
    public static void main(String[] args) throws Exception {
                // login
+
        OKMAuth okmAuth = new OKMAuth_Service().getOKMAuthPort();
Auth_Service authService = new Auth_Service();
+
        OKMPropertyGroup okmPg = new OKMPropertyGroup_Service().getOKMPropertyGroupPort();
Auth auth = authService.getAuthPort();
+
       
String token = auth.login("okmAdmin", "admin");
+
        // login
+
        String token = okmAuth.login("okmAdmin", "admin");
                // property groups
+
       
PropertyGroup_Service pgservice = new PropertyGroup_Service();
+
        // property groups
PropertyGroup pg = pgservice.getPropertyGroupPort();
+
        List<StringPair> spList = new ArrayList<StringPair>();
+
        StringPair sp = new StringPair();
List<StringPair> spList = new ArrayList<StringPair>();
+
        sp.setKey("okp:technology.comment");
StringPair sp = new StringPair();
+
        sp.setValue("Other comment from PHP");
sp.setKey("okp:technology.comment");
+
        spList.add(sp);
sp.setValue("Other comment from PHP");
+
        okmPg.setPropertiesSimple(token, "/okm:root/test/hosts.txt", "okg:technology", spList);
spList.add(sp);
+
       
pg.setPropertiesSimple(token, "/okm:root/test/hosts.txt", "okg:technology", spList);
+
        // logout
+
        okmAuth.logout(token);
                // logout
+
    }
auth.logout(token);
 
}
 
 
}
 
}
 
</source>
 
</source>
  
 
[[Category: Webservices Guide]]
 
[[Category: Webservices Guide]]

Latest revision as of 09:12, 7 January 2013

First, we need to generate the client stuff using this command. Keep on mind that you need JDK 1.6 to run it:

$ wsimport -p com.openkm.ws.client -keep http://localhost:8080/OpenKM/services/OKMAuth?wsdl

You can use the following script to generate a complete OpenKM webservices client library:

#/bin/bash

wsimport -p com.openkm.ws.client.auth -keep http://localhost:8080/OpenKM/services/OKMAuth?wsdl
wsimport -p com.openkm.ws.client.bookmark -keep http://localhost:8080/OpenKM/services/OKMBookmark?wsdl
wsimport -p com.openkm.ws.client.document -keep http://localhost:8080/OpenKM/services/OKMDocument?wsdl
wsimport -p com.openkm.ws.client.folder -keep http://localhost:8080/OpenKM/services/OKMFolder?wsdl
wsimport -p com.openkm.ws.client.mail -keep http://localhost:8080/OpenKM/services/OKMMail?wsdl
wsimport -p com.openkm.ws.client.note -keep http://localhost:8080/OpenKM/services/OKMNote?wsdl
wsimport -p com.openkm.ws.client.notification -keep http://localhost:8080/OpenKM/services/OKMNotification?wsdl
wsimport -p com.openkm.ws.client.propertyGroup -keep http://localhost:8080/OpenKM/services/OKMPropertyGroup?wsdl
wsimport -p com.openkm.ws.client.property -keep http://localhost:8080/OpenKM/services/OKMProperty?wsdl
wsimport -p com.openkm.ws.client.repository -keep http://localhost:8080/OpenKM/services/OKMRepository?wsdl
wsimport -p com.openkm.ws.client.search -keep http://localhost:8080/OpenKM/services/OKMSearch?wsdl
wsimport -p com.openkm.ws.client.workflow -keep http://localhost:8080/OpenKM/services/OKMWorkflow?wsdl

jar cvf okm-ws-client-6.2.jar com

rm -rf com

How can I change the Web Service address dynamically for a request ?

OKMAuth okmAuth = new OKMAuth_Service(new URL(url + "/services/OKMAuth?wsdl"),
    new QName("http://ws.openkm.com", "OKMAuth")).getOKMAuthPort();

or

((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "...");

Authentication

package com.openkm.ws.test;

import com.openkm.ws.client.auth.OKMAuth;
import com.openkm.ws.client.auth.OKMAuth_Service;

public class Authentication {
    public static void main(String[] args) {
        try {
            OKMAuth okmAuth = new OKMAuth_Service().getOKMAuthPort();

            // Login
            String token = okmAuth.login("okmAdmin", "admin");
            System.out.println("Token: " + token);

            // Logout
            okmAuth.logout(token);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

PropertyGroups

package com.openkm.ws.test;

import java.util.ArrayList;
import java.util.List;

import com.openkm.ws.client.auth.OKMAuth;
import com.openkm.ws.client.auth.OKMAuth_Service;
import com.openkm.ws.client.PropertyGroup;
import com.openkm.ws.client.PropertyGroup_Service;
import com.openkm.ws.client.StringPair;

public class PropertyGroups {
    public static void main(String[] args) throws Exception {
        OKMAuth okmAuth = new OKMAuth_Service().getOKMAuthPort();
        OKMPropertyGroup okmPg = new OKMPropertyGroup_Service().getOKMPropertyGroupPort();
        
        // login
        String token = okmAuth.login("okmAdmin", "admin");
        
        // property groups
        List<StringPair> spList = new ArrayList<StringPair>();
        StringPair sp = new StringPair();
        sp.setKey("okp:technology.comment");
        sp.setValue("Other comment from PHP");
        spList.add(sp);
        okmPg.setPropertiesSimple(token, "/okm:root/test/hosts.txt", "okg:technology", spList);
        
        // logout
        okmAuth.logout(token);
    }
}