Message Boards
how to do the remote access files
Ramalingaiah. D, modified 7 Years ago.
how to do the remote access files
Expert Posts: 486 Join Date: 8/16/14 Recent Posts
Hi,
http://localhost:8088/api/axis/Portlet_DL_DLAppService?wsdl
i have added above URL ---> api in web service ,
but Remote files not working
package com.ERPUploadFiles;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portlet.documentlibrary.service.http.DLAppServiceSoap;
import com.liferay.portlet.documentlibrary.service.http.DLAppServiceSoapServiceLocator;
public class UploadFiles {
public static void uploadFile(File file) throws ServiceException, RemoteException, IOException{
ServiceContext serviceContext=new ServiceContext();
DLAppServiceSoapServiceLocator locator= new DLAppServiceSoapServiceLocator();
DLAppServiceSoap service=locator.getPortlet_DL_DLAppService(getURL("Portlet_DL_DLAppService"));
//System.out.println("url>>>"+sb.toString());
service.addFileEntry(11505, 11586, file.getName(), "", file.getName(), file.getName(), "", getFileBytes(file), serviceContext);
}
private static URL getURL(String serviceName) throws MalformedURLException {
//String Url = "";
String url = "http://localhost:8088"; // ip address of liferay server ex. = http://45.76.28.19:8181
String screenName = "ram";
String password = "test";
int pos = url.indexOf("localhost:/C:/Dev/new.txt.txt");
String protocol = url.substring(0, pos + 3);
String host = url.substring(pos + 3, url.length());
StringBuilder sb = new StringBuilder();
sb.append(protocol);
sb.append(screenName);
sb.append(":");
sb.append(password);
sb.append("@");
sb.append(host);
sb.append("/api/axis/");
sb.append(serviceName);
//System.out.println("url>>>"+sb.toString());
return new URL(sb.toString());
}
private static byte[] getFileBytes(File file) throws IOException{
FileInputStream fileInputStream=null;
byte[] bFile = new byte[(int) file.length()];
//convert file into array of bytes
fileInputStream = new FileInputStream(file);
fileInputStream.read(bFile);
fileInputStream.close();
return bFile;
}
public static void main(String[] args) throws ServiceException, Exception {
File file = new File("C:\\Dev\\new.txt.txt");
LiferayUtil.uploadFile(file);
System.out.println("url>>>"+file.toString());
}
}
but Remote files not working
please suggest me,
Regards
Ram
http://localhost:8088/api/axis/Portlet_DL_DLAppService?wsdl
i have added above URL ---> api in web service ,
but Remote files not working
package com.ERPUploadFiles;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portlet.documentlibrary.service.http.DLAppServiceSoap;
import com.liferay.portlet.documentlibrary.service.http.DLAppServiceSoapServiceLocator;
public class UploadFiles {
public static void uploadFile(File file) throws ServiceException, RemoteException, IOException{
ServiceContext serviceContext=new ServiceContext();
DLAppServiceSoapServiceLocator locator= new DLAppServiceSoapServiceLocator();
DLAppServiceSoap service=locator.getPortlet_DL_DLAppService(getURL("Portlet_DL_DLAppService"));
//System.out.println("url>>>"+sb.toString());
service.addFileEntry(11505, 11586, file.getName(), "", file.getName(), file.getName(), "", getFileBytes(file), serviceContext);
}
private static URL getURL(String serviceName) throws MalformedURLException {
//String Url = "";
String url = "http://localhost:8088"; // ip address of liferay server ex. = http://45.76.28.19:8181
String screenName = "ram";
String password = "test";
int pos = url.indexOf("localhost:/C:/Dev/new.txt.txt");
String protocol = url.substring(0, pos + 3);
String host = url.substring(pos + 3, url.length());
StringBuilder sb = new StringBuilder();
sb.append(protocol);
sb.append(screenName);
sb.append(":");
sb.append(password);
sb.append("@");
sb.append(host);
sb.append("/api/axis/");
sb.append(serviceName);
//System.out.println("url>>>"+sb.toString());
return new URL(sb.toString());
}
private static byte[] getFileBytes(File file) throws IOException{
FileInputStream fileInputStream=null;
byte[] bFile = new byte[(int) file.length()];
//convert file into array of bytes
fileInputStream = new FileInputStream(file);
fileInputStream.read(bFile);
fileInputStream.close();
return bFile;
}
public static void main(String[] args) throws ServiceException, Exception {
File file = new File("C:\\Dev\\new.txt.txt");
LiferayUtil.uploadFile(file);
System.out.println("url>>>"+file.toString());
}
}
but Remote files not working
please suggest me,
Regards
Ram