Fórum

BlogsEntryService via Web Services

Clifton Best, modificado 13 Anos atrás.

BlogsEntryService via Web Services

New Member Mensagem: 1 Data de Entrada: 26/10/10 Postagens Recentes
Hello All,

I am in the process of importing blogs from the database of a legacy portal. I have used jdbc to read out all of the blog posts and comments and would like to populate Liferay with those blog posts from a standalone app using Web Services. I was successful in performing a similar operation with adding users remotely but I have not been successful in performing the blog insertions.

When I execute the code below it appears to work... I have stepped through its operation in debug mode and all code appears to execute correctly. I additionally validate that I can pull the data back from the portal and that does appear to work. When I log in to Liferay no additional blogs posts are visible. Should my ServiceContext variables be set to specific values in order for the newly created blogs to become visible within liferay? I would greatly appreciate it if anyone can provide any insight in to how I can get this to work.

VR/
Cliff



package com.logipense.blogInjection;

import java.net.URL;

import com.liferay.portal.model.PortletPreferencesIds;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portlet.blogs.service.http.BlogsEntryServiceSoap;
import com.liferay.portlet.blogs.service.http.BlogsEntryServiceSoapServiceLocator;
import com.liferay.portlet.blogs.model.BlogsEntrySoap;



public class BlogIngection {

/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub

String title = "Demo Blog Entry";
String content = "Utilizing Web Services is awesome. Its a programmers dream and I urge all to embrace it.";
int displayDateMonth = 10;
int displayDateDay = 25;
int displayDateYear = 2010;
int displayDateHour = 21;
int displayDateMinute = 59;
boolean allowPingbacks = true;
boolean allowTrackbacks = true;
String[] trackbacks = null;
ServiceContext serviceContext = new ServiceContext();
serviceContext.setScopeGroupId(0);
//ServiceContext serviceContext = ServiceContextFactory.getInstance(BlogsEntry.class.getName(), portletRequest);
String remoteUser = "10444";
String password = "password";

try{
BlogsEntryServiceSoapServiceLocator locatorUser = new BlogsEntryServiceSoapServiceLocator();
BlogsEntryServiceSoap soapBlog = locatorUser.getPortlet_Blogs_BlogsEntryService(_getURL(remoteUser, password, "Portlet_Blogs_BlogsEntryService"));
BlogsEntrySoap bsoap = soapBlog.addEntry(title, content, displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, allowPingbacks, allowTrackbacks, trackbacks, serviceContext);
long id = bsoap.getEntryId();
BlogsEntrySoap bsoap2 = soapBlog.getEntry(id);
System.out.println(bsoap2.getTitle()+" "+bsoap2.getContent() +" written and retreived");

}
catch(Exception e){e.printStackTrace();}
}

private static URL _getURL(String remoteUser, String password, String serviceName) throws Exception {
// Unathenticated url
// Unathenticated url
String url = "http://127.0.0.1:8080/tunnel-web/axis/" + serviceName;
// Authenticated url
if (true) {
url = "http://"+ remoteUser + ":" + password + "@127.0.0.1:8080/tunnel-web/secure/axis/" + serviceName+"?wsdl";
}
return new URL(url);
}

}