Commit 8f3b9737 authored by Jeremie Guillemotte's avatar Jeremie Guillemotte

Add simpleRegistryService integration to have the list of registered services...

Add simpleRegistryService integration to have the list of registered services displayed in the Proxy WS App template.
parent 1fadbfef
......@@ -424,6 +424,19 @@
<version>${frascati.version}</version>
</dependency>
<!-- FraSCAti intents -->
<dependency>
<groupId>org.ow2.frascati.intent</groupId>
<artifactId>frascati-authentication</artifactId>
<version>${frascati.version}</version>
</dependency>
<dependency>
<groupId>org.ow2.frascati.intent</groupId>
<artifactId>frascati-intent-apache-cxf</artifactId>
<version>${frascati.version}</version>
</dependency>
</dependencies>
<!-- ======== -->
......@@ -524,7 +537,8 @@
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
<!--<goal>copy-dependencies</goal>-->
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
......@@ -564,6 +578,28 @@
<version>0.5-SNAPSHOT</version>
<type>jar</type>
</artifactItem>
<!-- For simple registry service integration in proxy WS App -->
<artifactItem>
<groupId>org.easysoa.registry</groupId>
<artifactId>easysoa-registry-rest-client</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</artifactItem>
<artifactItem>
<groupId>org.easysoa.registry</groupId>
<artifactId>easysoa-registry-rest-core</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</artifactItem>
<artifactItem>
<groupId>org.ow2.frascati</groupId>
<artifactId>frascati-binding-http</artifactId>
<version>1.5-SNAPSHOT</version>
<type>jar</type>
</artifactItem>
<!--<artifactItem>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
......
#!/bin/sh
export MAVEN_OPTS="-XX:MaxPermSize=128m"
#export MAVEN_OPTS="-XX:MaxPermSize=128m -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8484,server=y,suspend=y"
mvn -DEasysoa -Pexplorer,remote-fscript -Dmaven.test.skip=true
......@@ -30,9 +30,13 @@ package org.easysoa.codegenerator;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLConnection;
import java.util.Set;
import java.util.logging.Logger;
......@@ -41,6 +45,8 @@ import javax.wsdl.Service;
import javax.wsdl.WSDLException;
import javax.xml.namespace.QName;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
import org.apache.cxf.tools.common.ToolContext;
import org.apache.cxf.tools.common.ToolException;
import org.apache.cxf.tools.wsdlto.WSDLToJava;
......@@ -160,11 +166,36 @@ public class CodeGeneratorWsdlToJSImpl implements CodeGenerator {
return null;
}
/**
* TODO better : local filename, auth, reuse or overwrite
* @param wsdlLocation
* @return
* @throws IOException
*/
private String downloadWsdl(String wsdlLocation) throws IOException{
URL url = new URL(wsdlLocation);
URLConnection uc = url.openConnection();
String userpass = "Administrator:Administrator";//TODO
String basicAuth = "Basic " + new String(new sun.misc.BASE64Encoder().encode(userpass.getBytes()));
uc.setRequestProperty ("Authorization", basicAuth);
InputStream in = uc.getInputStream();
File localWsdlFile = new File("/home/jguillemotte/test_" + System.currentTimeMillis() + ".wsdl");//TODO dans l'app
if (!localWsdlFile.createNewFile()) {
throw new IOException("Unable to create local WSDL file at " + localWsdlFile.getAbsolutePath());
}
IOUtils.copy(in, new FileOutputStream(localWsdlFile));//TODO closes ?
wsdlLocation = localWsdlFile.toURI().toURL().toString();
return wsdlLocation;
}
private void compile(String userId, String wsdlLocation) throws ToolException{
try {
if (!wsdlLocation.startsWith("http://")) {
wsdlLocation = downloadWsdl(wsdlLocation);
// TODO better
/*if (!wsdlLocation.startsWith("http://")) {
wsdlLocation = "http://" + wsdlLocation;
}
}*/
WebServiceCommandLine cmd = new WebServiceCommandLine("wsdl2java");
String[] args = new String[4];
......@@ -226,6 +257,12 @@ public class CodeGeneratorWsdlToJSImpl implements CodeGenerator {
private WsdlInformations loadWsdl(String wsdl) throws FileNotFoundException{
try {
wsdl = downloadWsdl(wsdl);
} catch (IOException e) {
throw new FileNotFoundException("Unable to download wsdl " + wsdl + " " + e.getMessage());
}
WsdlInformations wsdlInformations = new WsdlInformations();
try {
Definition definition = wsdlCompiler.readWSDL(wsdl);
......
......@@ -32,9 +32,14 @@ import com.sun.xml.bind.api.impl.NameConverter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.Set;
import java.util.logging.Logger;
......@@ -44,9 +49,13 @@ import javax.wsdl.Service;
import javax.wsdl.WSDLException;
import javax.xml.namespace.QName;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.cxf.tools.common.ToolContext;
import org.apache.cxf.tools.common.ToolException;
import org.apache.cxf.tools.wsdlto.WSDLToJava;
import org.apache.cxf.transport.https.HttpsURLConnectionFactory;
import org.easysoa.api.CodeGenerator;
import org.easysoa.api.PreferencesManagerItf;
import org.easysoa.api.ServiceManager;
......@@ -88,6 +97,14 @@ public class CodeGeneratorWsdlToJavaImpl implements CodeGenerator {
*/
@Override
public String generate(String userId, String service, String portTypeName, String wsdlLocation){
try {
wsdlLocation = downloadWsdl(wsdlLocation);
} catch (IOException e) {
String msg = "Unable to download wsdl " + wsdlLocation + " " + e.getMessage();
LOG.info(msg);
return msg;
}
try{
this.compile(userId, wsdlLocation);
}
......@@ -190,12 +207,60 @@ public class CodeGeneratorWsdlToJavaImpl implements CodeGenerator {
}
return null;
}
/**
* TODO better : local filename OK TEST, auth, reuse or overwrite OK TEST
* TODO OR DO rather queryEndpoints() and use their urls ?!??
* @param wsdlLocation The WSDL URL of the file to download
* @return the temporary URL of the downloaded file
* @throws IOException
*
* TODO If using the serviceInformation wsdl download url, we have to get the wsdl from the nuxeo system.
* Problem : the used url's in the generated composite use the nuxei file addresse and there some authentification problems
*
* The temporary solution is to use the information contained in the endpoints instead of these contained in the information service.
* In the endpoint, there is the real address of the wsdl so there is no need to download and record a local copy of the wsdl.
*/
private String downloadWsdl(String wsdlLocation/*, String userId, String service*/) throws IOException {
File localWsdlFile;
/*if (service == null) {
localWsdlFile = File.createTempFile("frascati-studio_" + userId + "_" + service, "wsdl");
} else {
Application application = serviceManager.getCurrentApplication(userId);
application.setCurrentWorskpacePath(preferences.getWorkspacePath());
String sources = application.retrieveAbsoluteSources();
File dir = new File(sources + File.separator + "impl");
localWsdlFile = new File(dir + File.separator + service
+ ".java");
if (!localWsdlFile.exists()) {
localWsdlFile.createNewFile();
}
}*/
URL url = new URL(wsdlLocation);
URLConnection uc = url.openConnection();
String userpass = "Administrator:Administrator";//TODO
String basicAuth = "Basic " + new String(new sun.misc.BASE64Encoder().encode(userpass.getBytes()));
uc.setRequestProperty ("Authorization", basicAuth);
InputStream in = uc.getInputStream();
localWsdlFile = new File("/home/jguillemotte/test_" + System.currentTimeMillis() + ".wsdl");//TODO dans l'app
if (!localWsdlFile.createNewFile()) {
throw new IOException("Unable to create local WSDL file at " + localWsdlFile.getAbsolutePath());
}
IOUtils.copy(in, new FileOutputStream(localWsdlFile));//TODO closes ?
wsdlLocation = localWsdlFile.toURI().toURL().toString();
return wsdlLocation;
}
private void compile(String userId, String wsdlLocation) throws ToolException{
try {
if (!wsdlLocation.startsWith("http://")) {
wsdlLocation = downloadWsdl(wsdlLocation);
/*if (!wsdlLocation.startsWith("http://")) {
wsdlLocation = "http://" + wsdlLocation;
}
}*///TODO better
WebServiceCommandLine cmd = new WebServiceCommandLine("wsdl2java");
String[] args = new String[4];
......@@ -251,6 +316,12 @@ public class CodeGeneratorWsdlToJavaImpl implements CodeGenerator {
private WsdlInformations loadWsdl(String wsdl) throws FileNotFoundException
{
try {
wsdl = downloadWsdl(wsdl);
} catch (IOException e) {
throw new FileNotFoundException("Unable to download wsdl " + wsdl + " " + e.getMessage());
}
WsdlInformations wsdlInformations = new WsdlInformations();
try {
Definition definition = wsdlCompiler.readWSDL(wsdl);
......
......@@ -14,7 +14,7 @@ import org.osoa.sca.annotations.Reference;
/**
*
* Template action for the helloworld composite sample app
* Template action for the Easysoa helloworld composite sample app
* @author jguillemotte
*
*/
......
......@@ -10,7 +10,7 @@ import org.osoa.sca.annotations.Reference;
/**
*
* Template action for the Discovery proxy app
* Template action for the Easysoa HTTP proxy app
* @author jguillemotte
*
*/
......
/**
*
*/
package org.easysoa.registry.rest.integration;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
//import org.codehaus.jackson.annotate.JsonAutoDetect;
//import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility;
/**
* @author jguillemotte
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
//@JsonAutoDetect(fieldVisibility=Visibility.ANY, getterVisibility=Visibility.NONE, setterVisibility=Visibility.NONE)
public class EndpointInformation/* extends WSDLInformation */{
private String environment;
private String endpointUrl;
public EndpointInformation(){
//super();
this.environment = "";
this.endpointUrl = "";
////////////////////
this.description = "";
this.name = "";
this.nuxeoID = "";
this.objectType = "";
this.projectID = "";
this.soaName = "";
this.wsdlDownloadUrl = "";
}
/**
* @return the endpoint
*/
public String getEndpointUrl() {
return endpointUrl;
}
/**
* @param endpoint the endpoint to set
*/
public void setEndpointUrl(String endpointUrl) {
this.endpointUrl = checkNotNull(endpointUrl);
}
/**
* @return the environment
*/
public String getEnvironment() {
return environment;
}
/**
* @param environment the environment to set
*/
public void setEnvironment(String environment) {
this.environment = checkNotNull(environment);
}
// copied from InformationService (to avoid inheriting from it to simplify mapping to REST)
private String projectID;
private String nuxeoID;
private String name;
private String description;
private String soaName;
private String objectType;
private String wsdlDownloadUrl;
private String wsdlPortType;
private String wsdlServiceName;
private String restPath;
private String restAccepts;
private String restContentType;
/**
* Default constructor
*/
/*public WSDLInformation(){
this.description = "";
this.name = "";
this.nuxeoID = "";
this.objectType = "";
this.projectID = "";
this.soaName = "";
this.wsdlDownloadUrl = "";
}*/
/**
* @return the projectID
*/
public String getProjectID() {
return projectID;
}
/**
* @param projectID the projectID to set
*/
public void setProjectID(String projectID) {
this.projectID = checkNotNull(projectID);
}
/**
* @return the nuxeoID
*/
public String getNuxeoID() {
return nuxeoID;
}
/**
* @param nuxeoID the nuxeoID to set
*/
public void setNuxeoID(String nuxeoID) {
this.nuxeoID = checkNotNull(nuxeoID);
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = checkNotNull(name);
}
/**
* @return the description
*/
public String getDescription() {
return description;
}
/**
* @param description the description to set
*/
public void setDescription(String description) {
this.description = checkNotNull(description);
}
/**
* @return the soaName
*/
public String getSoaName() {
return soaName;
}
/**
* @param soaName the soaName to set
*/
public void setSoaName(String soaName) {
this.soaName = checkNotNull(soaName);
}
/**
* @return the wsdlDownloadUrl
*/
public String getWsdlDownloadUrl() {
return wsdlDownloadUrl;
}
/**
* @param wsdlDownloadUrl the wsdlDownloadUrl to set
*/
public void setWsdlDownloadUrl(String wsdlDownloadUrl) {
this.wsdlDownloadUrl = checkNotNull(wsdlDownloadUrl);
}
/**
* @return the objectType
*/
public String getObjectType() {
return objectType;
}
/**
* @param objectType the objectType to set
*/
public void setObjectType(String objectType) {
this.objectType = checkNotNull(objectType);
}
public String getWsdlPortType() {
return wsdlPortType;
}
public void setWsdlPortType(String wsdlPortType) {
this.wsdlPortType = wsdlPortType;
}
public String getWsdlServiceName() {
return wsdlServiceName;
}
public void setWsdlServiceName(String wsdlServiceName) {
this.wsdlServiceName = wsdlServiceName;
}
public String getRestPath() {
return restPath;
}
public void setRestPath(String restPath) {
this.restPath = restPath;
}
public String getRestAccepts() {
return restAccepts;
}
public void setRestAccepts(String restAccepts) {
this.restAccepts = restAccepts;
}
public String getRestContentType() {
return restContentType;
}
public void setRestContentType(String restContentType) {
this.restContentType = restContentType;
}
/**
*
* @param param The parameter to check
* @return The param avlue or empty string if the param is null
*/
private String checkNotNull(String param){
if(param != null){
return param;
} else {
return "";
}
}
}
/**
*
*/
package org.easysoa.registry.rest.integration;
import java.util.ArrayList;
import java.util.List;
//import javax.xml.bind.annotation.XmlAccessType;
//import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
//import org.codehaus.jackson.annotate.JsonAutoDetect;
//import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility;
/**
* @author jguillemotte
*
*/
@XmlRootElement
//@JsonAutoDetect(fieldVisibility=Visibility.ANY, getterVisibility=Visibility.NONE, setterVisibility=Visibility.NONE)
public class EndpointInformations {
@XmlElement
private List<EndpointInformation> endpointInformations;
/**
*
*/
public EndpointInformations(){
endpointInformations = new ArrayList<EndpointInformation>();
}
/**
*
* @param information
*/
public void addEndpointInformation(EndpointInformation information){
this.endpointInformations.add(information);
}
/**
*
* @return
*/
public List<EndpointInformation> getEndpointInformationList() {
return endpointInformations;
}
/**
*
* @param wsdlInformationList
*/
public void setEndpointInformationList(List<EndpointInformation> endpointInformations) {
if(endpointInformations != null){
this.endpointInformations = endpointInformations;
} else {
this.endpointInformations = new ArrayList<EndpointInformation>();
}
}
}
/**
*
*/
package org.easysoa.registry.rest.integration;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
//import org.codehaus.jackson.annotate.JsonAutoDetect;
//import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility;
/**
* @author jguillemotte
*
*/
@XmlRootElement // TODO rm
@XmlAccessorType(XmlAccessType.FIELD)
//@JsonAutoDetect(fieldVisibility=Visibility.ANY, getterVisibility=Visibility.NONE, setterVisibility=Visibility.NONE)
public class ServiceInformation /*extends WSDLInformation*/ {
@XmlElement
private EndpointInformations endpoints;
/**
* Default constructor
*/
public ServiceInformation(){
//super();
endpoints = new EndpointInformations();
///////////////////
this.description = "";
this.name = "";
this.nuxeoID = "";
this.objectType = "";
this.projectID = "";
this.soaName = "";
this.wsdlDownloadUrl = "";
}
/**
* Returns the endpoints for the service
* @return
*/
public EndpointInformations getEndpoints(){
return this.endpoints;
}
/**
* Set the endpoints associated with the service
* @param endpoints
*/
public void setEndpoints(EndpointInformations endpoints){
if(endpoints != null){
this.endpoints = endpoints;
} else {
this.endpoints = new EndpointInformations();
}
}
protected String projectID;
protected String nuxeoID;
protected String name;
protected String description;
protected String soaName;
protected String objectType;
protected String wsdlDownloadUrl;
protected String wsdlPortType;
protected String wsdlServiceName;
protected String restPath;
protected String restAccepts;
protected String restContentType;