Difference between revisions of "User talk:Svaitsis.gss"

From OpenKM Documentation
Jump to: navigation, search
(Implementing a Java Client Web Service to consume OpenKM W/S Using Eclipse Part B: new section)
Line 271: Line 271:
 
Finally if you see some timeout exceptions do the following things:
 
Finally if you see some timeout exceptions do the following things:
 
# Give a couple of calls, since JBoss may need to re-cache the service.
 
# Give a couple of calls, since JBoss may need to re-cache the service.
 +
# Try to clear the Jboss cash server/default/tmp and restart the server.
 +
 +
Hope you enjoyed. Here is the project's code:
 +
 +
[[Media:MyOpenKmClient.rar]]
 +
 +
== Implementing a Java Client Web Service to consume OpenKM W/S Using Eclipse Part B ==
 +
 +
 +
 +
<b>Michael Mountrakis</b><i> Solutions Architect @UIT.GR</i>
 +
 +
 +
The second part describes how to create a simple OpenKM Client using Eclipse only, without the <b>wsimport</b> utility.
 +
 +
<b>Step 1</b>
 +
 +
Now the first step is to create a new Dynamic Web Project in Eclipse IDE. Select from Left Upper Menu:
 +
File -> New -> Other
 +
 +
From the Wizards menu that appears, select the Web->Dynamic Web Project
 +
 +
[[File:eclipse_new_dynamic_web_project.png]]
 +
 +
 +
Follow the steps of the Dynamic Web Project Wizard
 +
 +
[[File:eclipse_dynamic_web_project2.png]]
 +
 +
Follow the steps of the Dynamic Web Project Wizard
 +
# Give your project a name, I named it MyOpenKmClient
 +
# Give your project a run-time. I have chosen the jboss-4.2.3.GA that comes with the OpenKM
 +
# Give your project a dynamic web module version. For that just leave the default 2.5
 +
# Don't select EAR deployment
 +
# Click <b>Next</b>
 +
 +
[[File:eclipse_dynamic_web_project3.png]]
 +
 +
Click <b>Next</b>
 +
 +
[[File:eclipse_dynamic_web_project4.png]]
 +
 +
Select the option <i>Generate web.xml deployment descriptor.</i>
 +
 +
Click <b>Next</b>
 +
 +
[[File:eclipse_dynamic_web_project5.png]]
 +
 +
Click <b>Finish</b> to finish the wizard. When wizards finishes, you should have the following project created in your project space:
 +
 +
[[File:eclipse_created_dynamic_web_project.png]]
 +
 +
<b>Step 2</b> Creating the Web Service Client Library inside the Project.
 +
# Click on your project head node in the project's tree view to select the project.
 +
# Right click on the project and from the options  New -> Other. From the Wizards menu that appears, select the Web Services -> Web Service Client
 +
# Click Next
 +
 +
[[File:eclipse_select_web_service_client.png]]
 +
 +
Follows the client creation screen
 +
 +
[[File:eclipse_create_web_service_client.png]]
 +
 +
In this screen, put the URL of the OpenKM service you want to implement. For the example, I have used our OpenKM installation at UIT, and the service I need to write a client for is the OKMAuth listening to the following URI:
 +
http://office.uit.gr:8888/OpenKM/OKMAuth?wsdl
 +
 +
The easiest way to test if your OpenKM service is up and listening, is by opening the Mozilla (or any other browser) and put the service's URL: http://localhost:8080/OpenKM/OKMAuth?wsdl or any other URL. (Notice that in UIT's URL we run OpenKM to a different port 8888). Then hit return, and the browser will return you the Web Service's WSDL file:
 +
 +
Also put the Assemble Bar to the Assemble Client level.
 +
 +
Finally, check the Option <i>Overwrite files without warning.</i>
 +
 +
Click <b>Finish</b> to finish the wizard.
 +
When wizards finishes, you should have a new package created inside your project sources: <b>com.openkm.ws.endpoint</b>
 +
 +
Those are the classes to support your client.
 +
 +
<b>Step 3</b> Creating the Web Service Client Class (your code)
 +
 +
# Click on the <b> src </b> of your Project to select it. Right click and from the options select New->Package. Create a package like for example gr.uit.openkm.clients 
 +
# Select to the last node of the package (clients) to select it.  Right click and from the options select New->Class. Create a new Java Class and call it AuthTester.java. This will be your client implementation.
 +
# Add some simple implementation code:
 +
 +
<pre>
 +
package gr.uit.openkm.clients;
 +
 +
 +
 +
import java.util.logging.Logger;
 +
import com.openkm.ws.endpoint.OKMAuthProxy;
 +
 +
public class AuthTester {
 +
private static Logger logger = Logger.getLogger(AuthTester.class.getName());
 +
 +
public static void main(String [] argv ){
 +
OKMAuthProxy authProxy = new OKMAuthProxy();
 +
authProxy.setEndpoint("http://office.uit.gr:8888/OpenKM/OKMAuth?wsdl");
 +
try {
 +
String authToken = authProxy.login("mountrakis", "not_gonna_tell_you");
 +
logger.info("Logged : " + authToken);
 +
 +
} catch (Exception e) {
 +
logger.severe("Error : " + e.getMessage());
 +
e.printStackTrace();
 +
}
 +
}
 +
}
 +
</pre>
 +
 +
And get the results:
 +
<pre>
 +
Feb 12, 2011 11:15:01 PM gr.uit.openkm.clients.AuthTester main
 +
INFO: Logged : 83557117735219403024651823084
 +
</pre>
 +
 +
Method authProxy.setEndpoint() will be used when you need to call the same web service with on a different port, say for example when you will set your client to post to a production site rather than your localhost.
 +
 +
Finally if you see some timeout exceptions do the following things:
 +
# Give a cuple of calls, since JBoss may need to re-cache the service.
 
# Try to clear the Jboss cash server/default/tmp and restart the server.
 
# Try to clear the Jboss cash server/default/tmp and restart the server.
  

Revision as of 23:36, 12 February 2011

Implementing a Java Client Web Service to consume OpenKM W/S Using Eclipse Part A

Michael Mountrakis Solutions Architect @UIT.GR


The first part describes how we can compile the WSDL from our OpenKM installation using the wsimport utility that comes with JDK1.6 and above. The produced client library JAR file is then imported in the Eclipse IDE in order to assist our development.

The example starts with a simple MSDOS batch file that generates the client library JAR to support the OpenKM Java Client like the one given in the official Wiki Web Services page

http://wiki.openkm.com/index.php/Java_client

The create_okm_client.bat is the following one:

rem set your javahome and your openKM host
set javahome=C:\jdk1.6.0_21
set okmhost=http://office.uit.gr:8888/OpenKM
rem -----------------------------------------
echo Creating OpenKM Clients
set wsimport=%javahome%\bin\wsimport.exe
set jar=%javahome%\bin\jar.exe 

echo Deleting old clients if exist.
del /f okm-ws-client.jar

%wsimport% -p com.openkm.ws.client %okmhost%/OKMAuth?wsdl
%wsimport% -p com.openkm.ws.client %okmhost%/OKMDocument?wsdl
%wsimport% -p com.openkm.ws.client %okmhost%/OKMFolder?wsdl
%wsimport% -p com.openkm.ws.client %okmhost%/OKMSearch?wsdl
%wsimport% -p com.openkm.ws.client %okmhost%/OKMNotification?wsdl
%wsimport% -p com.openkm.ws.client %okmhost%/OKMRepository?wsdl

echo Packaging to a jar 
%jar% cvf okm-ws-client.jar com

echo Deleting temporary directory  
del /f /s /q com

We run the program as a command line in the MS DOS prompt. Uppon successful completion, the file okm-ws-client.jar will be produced.

Next step is to add the okm-ws-client.jar to your Eclipse project:

Eclipse.png

Implementing a Java Client Web Service to consume OpenKM W/S Using Eclipse Part B

Michael Mountrakis Solutions Architect @UIT.GR


The second part describes how to create a simple OpenKM Client using Eclipse only, without the wsimport utility.

Step 1

Now the first step is to create a new Dynamic Web Project in Eclipse IDE. Select from Left Upper Menu: File -> New -> Other

From the Wizards menu that appears, select the Web->Dynamic Web Project

Eclipse new dynamic web project.png


Follow the steps of the Dynamic Web Project Wizard

Eclipse dynamic web project2.png

Follow the steps of the Dynamic Web Project Wizard

  1. Give your project a name, I named it MyOpenKmClient
  2. Give your project a run-time. I have chosen the jboss-4.2.3.GA that comes with the OpenKM
  3. Give your project a dynamic web module version. For that just leave the default 2.5
  4. Don't select EAR deployment
  5. Click Next

Eclipse dynamic web project3.png

Click Next

Eclipse dynamic web project4.png

Select the option Generate web.xml deployment descriptor.

Click Next

Eclipse dynamic web project5.png

Click Finish to finish the wizard. When wizards finishes, you should have the following project created in your project space:

Eclipse created dynamic web project.png

Step 2 Creating the Web Service Client Library inside the Project.

  1. Click on your project head node in the project's tree view to select the project.
  2. Right click on the project and from the options New -> Other. From the Wizards menu that appears, select the Web Services -> Web Service Client
  3. Click Next

Eclipse select web service client.png

Follows the client creation screen

Eclipse create web service client.png

In this screen, put the URL of the OpenKM service you want to implement. For the example, I have used our OpenKM installation at UIT, and the service I need to write a client for is the OKMAuth listening to the following URI: http://office.uit.gr:8888/OpenKM/OKMAuth?wsdl

The easiest way to test if your OpenKM service is up and listening, is by opening the Mozilla (or any other browser) and put the service's URL: http://localhost:8080/OpenKM/OKMAuth?wsdl or any other URL. (Notice that in UIT's URL we run OpenKM to a different port 8888). Then hit return, and the browser will return you the Web Service's WSDL file:

Also put the Assemble Bar to the Assemble Client level.

Finally, check the Option Overwrite files without warning.

Click Finish to finish the wizard. When wizards finishes, you should have a new package created inside your project sources: com.openkm.ws.endpoint

Those are the classes to support your client.

Step 3 Creating the Web Service Client Class (your code)

  1. Click on the src of your Project to select it. Right click and from the options select New->Package. Create a package like for example gr.uit.openkm.clients
  2. Select to the last node of the package (clients) to select it. Right click and from the options select New->Class. Create a new Java Class and call it AuthTester.java. This will be your client implementation.
  3. Add some simple implementation code:
package gr.uit.openkm.clients;



import java.util.logging.Logger;
import com.openkm.ws.endpoint.OKMAuthProxy;

public class AuthTester {
	private static Logger logger = Logger.getLogger(AuthTester.class.getName());
	
	public static void main(String [] argv ){
		OKMAuthProxy authProxy = new OKMAuthProxy();
		authProxy.setEndpoint("http://office.uit.gr:8888/OpenKM/OKMAuth?wsdl");
		try {
			String authToken = authProxy.login("mountrakis", "not_gonna_tell_you");
			logger.info("Logged : " + authToken);
			
		} catch (Exception e) {
			logger.severe("Error : " + e.getMessage());
			e.printStackTrace();
		}
	}
}

And get the results:

Feb 12, 2011 11:15:01 PM gr.uit.openkm.clients.AuthTester main
INFO: Logged : 83557117735219403024651823084

Method authProxy.setEndpoint() will be used when you need to call the same web service with on a different port, say for example when you will set your client to post to a production site rather than your localhost.

Finally if you see some timeout exceptions do the following things:

  1. Give a cuple of calls, since JBoss may need to re-cache the service.
  2. Try to clear the Jboss cash server/default/tmp and restart the server.

Hope you enjoyed. Here is the project's code:

Media:MyOpenKmClient.rar

Implementing a Java Client Web Service to consume OpenKM W/S Using Eclipse Part B

Michael Mountrakis Solutions Architect @UIT.GR


The second part describes how to create a simple OpenKM Client using Eclipse only, without the wsimport utility.

Step 1

Now the first step is to create a new Dynamic Web Project in Eclipse IDE. Select from Left Upper Menu: File -> New -> Other

From the Wizards menu that appears, select the Web->Dynamic Web Project

Eclipse new dynamic web project.png


Follow the steps of the Dynamic Web Project Wizard

Eclipse dynamic web project2.png

Follow the steps of the Dynamic Web Project Wizard

  1. Give your project a name, I named it MyOpenKmClient
  2. Give your project a run-time. I have chosen the jboss-4.2.3.GA that comes with the OpenKM
  3. Give your project a dynamic web module version. For that just leave the default 2.5
  4. Don't select EAR deployment
  5. Click Next

Eclipse dynamic web project3.png

Click Next

Eclipse dynamic web project4.png

Select the option Generate web.xml deployment descriptor.

Click Next

Eclipse dynamic web project5.png

Click Finish to finish the wizard. When wizards finishes, you should have the following project created in your project space:

Eclipse created dynamic web project.png

Step 2 Creating the Web Service Client Library inside the Project.

  1. Click on your project head node in the project's tree view to select the project.
  2. Right click on the project and from the options New -> Other. From the Wizards menu that appears, select the Web Services -> Web Service Client
  3. Click Next

Eclipse select web service client.png

Follows the client creation screen

Eclipse create web service client.png

In this screen, put the URL of the OpenKM service you want to implement. For the example, I have used our OpenKM installation at UIT, and the service I need to write a client for is the OKMAuth listening to the following URI: http://office.uit.gr:8888/OpenKM/OKMAuth?wsdl

The easiest way to test if your OpenKM service is up and listening, is by opening the Mozilla (or any other browser) and put the service's URL: http://localhost:8080/OpenKM/OKMAuth?wsdl or any other URL. (Notice that in UIT's URL we run OpenKM to a different port 8888). Then hit return, and the browser will return you the Web Service's WSDL file:

Also put the Assemble Bar to the Assemble Client level.

Finally, check the Option Overwrite files without warning.

Click Finish to finish the wizard. When wizards finishes, you should have a new package created inside your project sources: com.openkm.ws.endpoint

Those are the classes to support your client.

Step 3 Creating the Web Service Client Class (your code)

  1. Click on the src of your Project to select it. Right click and from the options select New->Package. Create a package like for example gr.uit.openkm.clients
  2. Select to the last node of the package (clients) to select it. Right click and from the options select New->Class. Create a new Java Class and call it AuthTester.java. This will be your client implementation.
  3. Add some simple implementation code:
package gr.uit.openkm.clients;



import java.util.logging.Logger;
import com.openkm.ws.endpoint.OKMAuthProxy;

public class AuthTester {
	private static Logger logger = Logger.getLogger(AuthTester.class.getName());
	
	public static void main(String [] argv ){
		OKMAuthProxy authProxy = new OKMAuthProxy();
		authProxy.setEndpoint("http://office.uit.gr:8888/OpenKM/OKMAuth?wsdl");
		try {
			String authToken = authProxy.login("mountrakis", "not_gonna_tell_you");
			logger.info("Logged : " + authToken);
			
		} catch (Exception e) {
			logger.severe("Error : " + e.getMessage());
			e.printStackTrace();
		}
	}
}

And get the results:

Feb 12, 2011 11:15:01 PM gr.uit.openkm.clients.AuthTester main
INFO: Logged : 83557117735219403024651823084

Method authProxy.setEndpoint() will be used when you need to call the same web service with on a different port, say for example when you will set your client to post to a production site rather than your localhost.

Finally if you see some timeout exceptions do the following things:

  1. Give a couple of calls, since JBoss may need to re-cache the service.
  2. Try to clear the Jboss cash server/default/tmp and restart the server.

Hope you enjoyed. Here is the project's code:

Media:MyOpenKmClient.rar

Implementing a Java Client Web Service to consume OpenKM W/S Using Eclipse Part B

Michael Mountrakis Solutions Architect @UIT.GR


The second part describes how to create a simple OpenKM Client using Eclipse only, without the wsimport utility.

Step 1

Now the first step is to create a new Dynamic Web Project in Eclipse IDE. Select from Left Upper Menu: File -> New -> Other

From the Wizards menu that appears, select the Web->Dynamic Web Project

Eclipse new dynamic web project.png


Follow the steps of the Dynamic Web Project Wizard

Eclipse dynamic web project2.png

Follow the steps of the Dynamic Web Project Wizard

  1. Give your project a name, I named it MyOpenKmClient
  2. Give your project a run-time. I have chosen the jboss-4.2.3.GA that comes with the OpenKM
  3. Give your project a dynamic web module version. For that just leave the default 2.5
  4. Don't select EAR deployment
  5. Click Next

Eclipse dynamic web project3.png

Click Next

Eclipse dynamic web project4.png

Select the option Generate web.xml deployment descriptor.

Click Next

Eclipse dynamic web project5.png

Click Finish to finish the wizard. When wizards finishes, you should have the following project created in your project space:

Eclipse created dynamic web project.png

Step 2 Creating the Web Service Client Library inside the Project.

  1. Click on your project head node in the project's tree view to select the project.
  2. Right click on the project and from the options New -> Other. From the Wizards menu that appears, select the Web Services -> Web Service Client
  3. Click Next

Eclipse select web service client.png

Follows the client creation screen

Eclipse create web service client.png

In this screen, put the URL of the OpenKM service you want to implement. For the example, I have used our OpenKM installation at UIT, and the service I need to write a client for is the OKMAuth listening to the following URI: http://office.uit.gr:8888/OpenKM/OKMAuth?wsdl

The easiest way to test if your OpenKM service is up and listening, is by opening the Mozilla (or any other browser) and put the service's URL: http://localhost:8080/OpenKM/OKMAuth?wsdl or any other URL. (Notice that in UIT's URL we run OpenKM to a different port 8888). Then hit return, and the browser will return you the Web Service's WSDL file:

Also put the Assemble Bar to the Assemble Client level.

Finally, check the Option Overwrite files without warning.

Click Finish to finish the wizard. When wizards finishes, you should have a new package created inside your project sources: com.openkm.ws.endpoint

Those are the classes to support your client.

Step 3 Creating the Web Service Client Class (your code)

  1. Click on the src of your Project to select it. Right click and from the options select New->Package. Create a package like for example gr.uit.openkm.clients
  2. Select to the last node of the package (clients) to select it. Right click and from the options select New->Class. Create a new Java Class and call it AuthTester.java. This will be your client implementation.
  3. Add some simple implementation code:
package gr.uit.openkm.clients;



import java.util.logging.Logger;
import com.openkm.ws.endpoint.OKMAuthProxy;

public class AuthTester {
	private static Logger logger = Logger.getLogger(AuthTester.class.getName());
	
	public static void main(String [] argv ){
		OKMAuthProxy authProxy = new OKMAuthProxy();
		authProxy.setEndpoint("http://office.uit.gr:8888/OpenKM/OKMAuth?wsdl");
		try {
			String authToken = authProxy.login("mountrakis", "not_gonna_tell_you");
			logger.info("Logged : " + authToken);
			
		} catch (Exception e) {
			logger.severe("Error : " + e.getMessage());
			e.printStackTrace();
		}
	}
}

And get the results:

Feb 12, 2011 11:15:01 PM gr.uit.openkm.clients.AuthTester main
INFO: Logged : 83557117735219403024651823084

Method authProxy.setEndpoint() will be used when you need to call the same web service with on a different port, say for example when you will set your client to post to a production site rather than your localhost.

Finally if you see some timeout exceptions do the following things:

  1. Give a cuple of calls, since JBoss may need to re-cache the service.
  2. Try to clear the Jboss cash server/default/tmp and restart the server.

Hope you enjoyed. Here is the project's code:

Media:MyOpenKmClient.rar