Commit 1469f1c0 authored by Jeremie Guillemotte's avatar Jeremie Guillemotte

Refactor the web resources download service. It works now with an itent based on a rest binding.

parent 2020ea1d
......@@ -57,7 +57,7 @@ import org.easysoa.api.CodeGenerator;
import org.easysoa.api.PreferencesManagerItf;
import org.easysoa.api.ServiceManager;
import org.easysoa.model.Application;
import org.easysoa.registry.rest.integration.resources.RoutingWebResourceDownloadService;
import org.easysoa.registry.rest.integration.resources.ResourceDownloadService;
import org.easysoa.utils.WsdlInformations;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
......
......@@ -52,7 +52,7 @@ import org.easysoa.api.CodeGenerator;
import org.easysoa.api.PreferencesManagerItf;
import org.easysoa.api.ServiceManager;
import org.easysoa.model.Application;
import org.easysoa.registry.rest.integration.resources.RoutingWebResourceDownloadService;
import org.easysoa.registry.rest.integration.resources.ResourceDownloadService;
import org.easysoa.utils.WsdlInformations;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
......
......@@ -7,7 +7,7 @@ import java.io.IOException;
import java.net.URL;
import org.easysoa.codegenerator.CodeGeneratorWsdlToJSImpl;
import org.easysoa.registry.rest.integration.resources.RoutingWebResourceDownloadService;
import org.easysoa.registry.rest.integration.resources.ResourceDownloadService;
import org.osoa.sca.annotations.Reference;
/**
......@@ -17,7 +17,7 @@ import org.osoa.sca.annotations.Reference;
public class RegistryCodeGeneratorWsdlToJSImpl extends CodeGeneratorWsdlToJSImpl {
@Reference
protected RoutingWebResourceDownloadService routingService;
protected ResourceDownloadService routingService;
/**
* TODO better : local filename, auth, reuse or overwrite
......
......@@ -7,7 +7,7 @@ import java.io.IOException;
import java.net.URL;
import org.easysoa.codegenerator.CodeGeneratorWsdlToJavaImpl;
import org.easysoa.registry.rest.integration.resources.RoutingWebResourceDownloadService;
import org.easysoa.registry.rest.integration.resources.ResourceDownloadService;
import org.osoa.sca.annotations.Reference;
/**
......@@ -17,7 +17,7 @@ import org.osoa.sca.annotations.Reference;
public class RegistryCodeGeneratorWsdlToJavaImpl extends CodeGeneratorWsdlToJavaImpl {
@Reference
protected RoutingWebResourceDownloadService routingService;
protected ResourceDownloadService routingService;
/**
* TODO better : local filename OK TEST, auth, reuse or overwrite OK TEST
......
......@@ -11,7 +11,7 @@ import org.osoa.sca.annotations.Property;
* @author jguillemotte
*
*/
public abstract class AbstractWebResourceDownloadService implements WebResourceDownloadService {
public abstract class AbstractWebResourceDownloadService implements UrlPatternWebResourceDownloadService {
// integer for execution order : FraSCAti doesn't allow to use component list in a specified order
@Property
......@@ -19,7 +19,7 @@ public abstract class AbstractWebResourceDownloadService implements WebResourceD
// Java regex pattern
@Property
protected String urlPattern;
protected String urlPattern;
/* (non-Javadoc)
* @see org.easysoa.registry.rest.integration.resources.WebResourceDownloadService#matchUrl(java.net.URL)
......
......@@ -10,6 +10,7 @@ import java.net.URL;
import java.net.URLConnection;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.osoa.sca.annotations.Reference;
import org.osoa.sca.annotations.Scope;
/**
......@@ -19,10 +20,13 @@ import org.osoa.sca.annotations.Scope;
@Scope("COMPOSITE")
public class DefaultUrlPatternWebResourceDownloadServiceImpl extends AbstractWebResourceDownloadService {
@Reference
protected WebResourceDownloadItf downloadService;
@Override
public String get(URL url) throws Exception {
String wsdlContent = "";
/*String wsdlContent = "";
if(url.toURI().toURL().toString().startsWith("file://")){
File file = new File(url.toURI());
......@@ -35,8 +39,11 @@ public class DefaultUrlPatternWebResourceDownloadServiceImpl extends AbstractWeb
StringWriter writer = new StringWriter();
IOUtils.copy(in, writer, "UTF-8");
wsdlContent = writer.toString();
}
return wsdlContent;
}*/
//return wsdlContent;
return downloadService.get(url.toString());
}
}
......@@ -9,10 +9,10 @@ import java.util.Comparator;
* @author jguillemotte
*
*/
public class DownloadServicesComparator implements Comparator<WebResourceDownloadService> {
public class DownloadServicesComparator implements Comparator<UrlPatternWebResourceDownloadService> {
@Override
public int compare(WebResourceDownloadService o1, WebResourceDownloadService o2) {
public int compare(UrlPatternWebResourceDownloadService o1, UrlPatternWebResourceDownloadService o2) {
if(o1.getExecutionOrder() > o2.getExecutionOrder()){
return 1;
......
/**
* EasySOA Proxy Copyright 2011-2013 Open Wide
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Contact : easysoa-dev@googlegroups.com
*/
package org.easysoa.registry.rest.integration.resources;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.jaxrs.client.Client;
import org.apache.cxf.jaxrs.client.WebClient;
import org.ow2.frascati.intent.cxf.AbstractBindingIntentHandler;
/**
*
* @author jguillemotte
*/
public class GenericDownloaderIntent extends AbstractBindingIntentHandler {
String login = "admin";
String password = "admin";
// Add authentification (eg : to get wsdl from Nuxeo registry)
/**
* Apply this binding intent on a proxy instance.
* @param proxy the proxy instance to configure.
* @see BindingIntentHandler#apply(Object)
*/
@Override
public final void apply(Object proxy) {
// Obtain the endpoint associated to the proxy instance.
Endpoint endpoint = null;
// Is the proxy a Apache CXF REST client ?
if (proxy instanceof Client) {
endpoint = WebClient.getConfig(proxy).getConduitSelector().getEndpoint();
}
if (endpoint == null) {
throw new IllegalArgumentException(proxy + " is not an Apache CXF REST client!");
}
// Add an interceptor on outgoing requests for the endpoint.
// Problem : how to pass URL and login/passwd params to the intent ???
// TODO : add a reference and pass it to the codeGenerator ???
endpoint.getOutInterceptors().add(new GenericDownloaderInterceptor());
super.apply(proxy);
}
}
/**
* EasySOA Proxy Copyright 2011-2013 Open Wide
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Contact : easysoa-dev@googlegroups.com
*/
package org.easysoa.registry.rest.integration.resources;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
/**
*
* @author jguillemotte
*/
public class GenericDownloaderInterceptor extends AbstractPhaseInterceptor<Message> {
//private String login;
//private String password;
public GenericDownloaderInterceptor() {
super(Phase.USER_LOGICAL);
}
@Override
public void handleMessage(Message message) {
// Replace the predifined address by the given address
String address = (String) message.get(Message.ENDPOINT_ADDRESS);
// Removing the base address configured in the binding rest (see the webResourceService composite)
// TODO : replace required here because the received message URL miss a /
// Find the reason why and remove the replace method call
address = address.substring(address.indexOf("http://localhost/")+17).replace("http:/","http://");
//message.put(Message.ENDPOINT_ADDRESS, "http://soap.amazon.com/schemas2/AmazonWebServices.wsdl");
message.put(Message.ENDPOINT_ADDRESS, address);
// TODO : how to pass dynamically the login/password for authentification ??
/*
// Build the authentification header value
StringBuilder authValue = new StringBuilder("basic ");
// Encode in base 64
authValue.append(encode64(login, password));
List<String> authValueList = new ArrayList<String>();
authValueList.add(authValue.toString());
// Get the existing headers
Map<String, List<String>> headers = (Map<String, List<String>>) message.get(Message.PROTOCOL_HEADERS);
// Add basic authentification
headers.put("Authorization", authValueList);
// Add HTTP headers to the web service request
//message.put(Message.PROTOCOL_HEADERS, headers);
*/
}
// TODO dummy method, replace or call a real base 64 encoding method
private String encode64(String login, String password){
return "";
}
}
......@@ -3,13 +3,7 @@
*/
package org.easysoa.registry.rest.integration.resources;
import java.io.File;
import java.net.URL;
import java.util.regex.PatternSyntaxException;
import javax.ws.rs.core.Response;
import org.osoa.sca.annotations.Property;
import org.osoa.sca.annotations.Reference;
import org.osoa.sca.annotations.Scope;
......@@ -20,8 +14,9 @@ import org.osoa.sca.annotations.Scope;
@Scope("COMPOSITE")
public class NuxeoUrlPatternWebResourceDownloadServiceImpl extends AbstractWebResourceDownloadService {
// Nuxeo download service reference
@Reference
protected NuxeoDownload downloadService;
protected WebResourceDownloadItf downloadService;
/* (non-Javadoc)
* @see org.easysoa.registry.rest.integration.resources.WebResourceDownloadService#get(java.net.URL)
......
......@@ -4,11 +4,14 @@ import java.io.File;
import java.net.URL;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import org.easysoa.api.PreferencesManagerItf;
public interface RoutingWebResourceDownloadService {
/**
*
* @author jguillemotte
*/
public interface ResourceDownloadService {
/**
* Get the file corresponding to the given URL
......
......@@ -22,10 +22,10 @@ import org.osoa.sca.annotations.Scope;
*
*/
@Scope("COMPOSITE")
public class RoutingWebResourceDownloadServiceImpl implements RoutingWebResourceDownloadService {
public class RoutingResourceDownloadServiceImpl implements ResourceDownloadService {
@Reference
protected List<WebResourceDownloadService> downloadServices;
protected List<UrlPatternWebResourceDownloadService> downloadServices;
/* (non-Javadoc)
* @see org.easysoa.registry.rest.integration.resources.RoutingWebResourceDownloadService#get(java.net.URL)
......@@ -39,7 +39,7 @@ public class RoutingWebResourceDownloadServiceImpl implements RoutingWebResource
// Need to be sorted manually because FraSCAti doesn't provide a native way to specify an execution order
Collections.sort(downloadServices, new DownloadServicesComparator());
for(WebResourceDownloadService service : downloadServices){
for(UrlPatternWebResourceDownloadService service : downloadServices){
if(service.matchUrl(url)){
// file type is always WSDL ??
String tempFolder = preferences.getWorkspacePath();
......
......@@ -10,7 +10,7 @@ import java.net.URL;
* @author jguillemotte
*
*/
public interface WebResourceDownloadService {
public interface UrlPatternWebResourceDownloadService {
/**
* Download a resource and store it locally
......
......@@ -4,7 +4,11 @@ import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
public interface NuxeoDownload {
/**
*
* @author jguillemotte
*/
public interface WebResourceDownloadItf {
//http://localhost:8080/nuxeo/nxfile/default/eb1dfac2-23f1-48a6-95e8-de742c0af7dc/blobholder:0/ContactSvc.asmx.wsdl
@GET
......
......@@ -103,13 +103,13 @@ TODO : Use an include tag with the easysoa.composite file instead of a raw copie
<wire source="ProxyWSTemplateAction/generators" target="CodeGeneratorWsdlToJava/codeGeneratorWsdlToJava" />
<wire source="ProxyWSLogTemplateAction/generators" target="CodeGeneratorWsdlToJava/codeGeneratorWsdlToJava" />
<!-- Routing web resources download component, referring to webResourcesService.composite -->
<component name="RoutingWebResourceServiceComponent">
<service name="routingWebResourceServiceService">
<interface.java interface="org.easysoa.registry.rest.integration.resources.RoutingWebResourceDownloadService" />
</service>
<implementation.composite name="webResourcesService.composite"/>
</component>
<!-- Routing web resources download component, referring to webResourcesService.composite -->
<component name="RoutingWebResourceServiceComponent">
<service name="routingWebResourceServiceService">
<interface.java interface="org.easysoa.registry.rest.integration.resources.ResourceDownloadService" />
</service>
<implementation.composite name="webResourcesService.composite"/>
</component>
<component name="Friends">
<implementation.java class="org.easysoa.impl.FriendsImpl" />
......
<?xml version="1.0" encoding="UTF-8"?>
<sca:composite xmlns:frascati="http://frascati.ow2.org/xmlns/sca/1.1"
xmlns:instance="http://www.w3.org/2004/08/wsdl-instance"
xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" name="genericResourceDownloadIntent">
<sca:service name="intent" promote="genericResourceIntent/intentService"/>
<sca:component name="genericResourceIntent">
<sca:service name="intentService">
<sca:interface.java interface="org.objectweb.fractal.bf.connectors.common.BindingIntentHandler"/>
</sca:service>
<sca:implementation.java class="org.easysoa.registry.rest.integration.resources.GenericDownloaderIntent"/>
</sca:component>
</sca:composite>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:frascati="http://frascati.ow2.org/xmlns/sca/1.1" xmlns:web="http://frascati.ow2.org/xmlns/web/1.0"
xmlns:sca="http://tuscany.apache.org/xmlns/sca/1.0" name="webResourcesService">
xmlns:frascati="http://frascati.ow2.org/xmlns/sca/1.1" xmlns:web="http://frascati.ow2.org/xmlns/web/1.0"
xmlns:sca="http://tuscany.apache.org/xmlns/sca/1.0" name="webResourcesService">
<!--<service name="webResourceRoutingService" promote="RoutingWebResourceService/routingWebResourceService">
<interface.java interface="org.easysoa.registry.rest.integration.resources.RoutingWebResourceDownloadService" />
<frascati:binding.rest uri="/webResourceRoutingService" />
</service>-->
<interface.java interface="org.easysoa.registry.rest.integration.resources.RoutingWebResourceDownloadService" />
<frascati:binding.rest uri="/webResourceRoutingService" />
</service>-->
<service name="routingWebResourceServiceService" promote="RoutingWebResourceService/routingWebResourceService">
<interface.java interface="org.easysoa.registry.rest.integration.resources.RoutingWebResourceDownloadService" />
<interface.java interface="org.easysoa.registry.rest.integration.resources.ResourceDownloadService" />
</service>
<!-- Routing service -->
<!-- Routing service -->
<component name="RoutingWebResourceService">
<implementation.java class="org.easysoa.registry.rest.integration.resources.RoutingWebResourceDownloadServiceImpl" />
<implementation.java class="org.easysoa.registry.rest.integration.resources.RoutingResourceDownloadServiceImpl" />
<service name="routingWebResourceService">
<interface.java interface="org.easysoa.registry.rest.integration.resources.RoutingWebResourceDownloadService" />
<interface.java interface="org.easysoa.registry.rest.integration.resources.ResourceDownloadService" />
</service>
<reference multiplicity="0..n" name="downloadServices">
<interface.java interface="org.easysoa.registry.rest.integration.resources.WebResourceDownloadService" />
<interface.java interface="org.easysoa.registry.rest.integration.resources.UrlPatternWebResourceDownloadService" />
</reference>
</component>
<!-- For EasySOA and Nuxeo resources -->
<!-- For EasySOA and Nuxeo resources -->
<component name="EasySOARegistryWebResourceDownload">
<implementation.java class="org.easysoa.registry.rest.integration.resources.NuxeoUrlPatternWebResourceDownloadServiceImpl" />
<service name="easySOARegistryWebResourceDownload">
<interface.java interface="org.easysoa.registry.rest.integration.resources.WebResourceDownloadService" />
<interface.java interface="org.easysoa.registry.rest.integration.resources.UrlPatternWebResourceDownloadService" />
</service>
<property name="urlPattern">(http|https)://(.*)/nuxeo(.+)</property>
<!-- Property executionOrder is used to define an execution order in case of multiple component references stored in a list -->
<!-- Required because FraSCAti doesn't provide a way to specify an execution order -->
<!-- Property executionOrder is used to define an execution order in case of multiple component references stored in a list -->
<!-- Required because FraSCAti doesn't provide a way to specify an execution order -->
<property name="executionOrder">1</property>
<reference name="downloadService">
<frascati:binding.rest uri="http://localhost:8080/nuxeo/nxfile/default/" requires="nuxeoAuthorization"/>
<frascati:binding.rest uri="http://localhost:8080/nuxeo/nxfile/default/" requires="nuxeoAuthorization"/>
<!--<interface.java interface="org.easysoa.registry.rest.integration.resources.WebResourceDownloadItf"></interface.java>-->
<!-- TODO interface -->
</reference>
</component>
<wire source="RoutingWebResourceService/downloadServices" target="EasySOARegistryWebResourceDownload/easySOARegistryWebResourceDownload" />
......@@ -52,25 +54,34 @@
-->
<!-- For all other resources -->
<!-- Prefix z because the list is explored by alphabetical order -->
<component name="DefaultWebResourceDownload">
<implementation.java class="org.easysoa.registry.rest.integration.resources.DefaultUrlPatternWebResourceDownloadServiceImpl" />
<service name="defaultWebResourceDownload">
<interface.java interface="org.easysoa.registry.rest.integration.resources.WebResourceDownloadService" />
<interface.java interface="org.easysoa.registry.rest.integration.resources.UrlPatternWebResourceDownloadService" />
</service>
<property name="urlPattern">.*</property>
<!-- Property executionOrder is used to define an execution order in case of multiple component references stored in a list -->
<!-- Required because FraSCAti doesn't provide a way to specify an execution order -->
<property name="executionOrder">2</property>
<property name="urlPattern">.*</property>
<!-- Property executionOrder is used to define an execution order in case of multiple component references stored in a list -->
<!-- Required because FraSCAti doesn't provide a way to specify an execution order -->
<property name="executionOrder">2</property>
<!-- Add a rest binding on / -->
<!-- Modify the address dynamilcaly with the genericDownloaderIntent -->
<!-- Add the same intent to add authentification -->
<!-- requires="nuxeoAuthorization" -->
<!-- requires="genericResourceDownloadIntent" -->
<reference name="downloadService" >
<frascati:binding.rest uri="http://localhost/" requires="genericResourceDownloadIntent"/>
<!--<interface.java interface="org.easysoa.registry.rest.integration.resources.WebResourceDownloadItf"></interface.java>-->
</reference>
</component>
<wire source="RoutingWebResourceService/downloadServices" target="DefaultWebResourceDownload/defaultWebResourceDownload" />
<!-- Nuxeo authentification -->
<component name="nuxeoAuthorization">
<implementation.composite name="BasicAuthorizationPolicyIntent"/>
<property name="UserName">${nuxeo.login}</property>
<property name="Password">${nuxeo.password}</property>
</component>
<component name="nuxeoAuthorization">
<implementation.composite name="BasicAuthorizationPolicyIntent"/>
<property name="UserName">${nuxeo.login}</property>
<property name="Password">${nuxeo.password}</property>
</component>
</composite>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment