Last active
December 31, 2016 06:49
-
-
Save chaitut715/f07f56f45f7b7aeb83b43ddd0ddba7fa to your computer and use it in GitHub Desktop.
call sakai soap(cxf) calls from java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- for the ws calls --> | |
<dependency> | |
<groupId>org.apache.cxf</groupId> | |
<artifactId>cxf-rt-frontend-jaxws</artifactId> | |
<version>3.1.8</version> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.cxf</groupId> | |
<artifactId>cxf-rt-transports-http</artifactId> | |
<version>3.1.8</version> | |
</dependency> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lombok.extern.apachecommons.CommonsLog; | |
import org.apache.commons.lang.StringUtils; | |
import org.apache.cxf.endpoint.Client; | |
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory; | |
@CommonsLog | |
public class WebServiceSupport { | |
/** | |
* cxf calls are availabe from sakai 10.x | |
* Make a web service call to the given endpoint, calling the method and using the params supplied | |
* @param endpoint wsdl url | |
* @param method method to call | |
* @param params Array of params: | |
* 1. Must be in order required to be sent | |
* * @return the response, or null if any exception is thrown. | |
*/ | |
public static String call(String endpoint, String method, Object[] params) { | |
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); | |
try { | |
Client client = dcf.createClient(endpoint); | |
Object[] returnVals = client.invoke(method, params); | |
//extract returned value. getting 1st value as sakai ws calls returns only one value. | |
if(returnVals!=null && returnVals.length>0) | |
return (String)returnVals[0]; | |
} | |
catch (Exception e) { | |
//e.printStackTrace(); | |
log.error("A connection error occurred: " + e.getClass() + ": " + e.getMessage()); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment