PingbackMethodImpl implements Method { protected ServiceContext buildServiceContext( long companyId, long groupId, String urlTitle) throws Exception { ServiceContext serviceContext = new ServiceContext(); String pingbackUserName = LanguageUtil.get( LocaleUtil.getSiteDefault(), "pingback"); serviceContext.setAttribute("pingbackUserName", pingbackUserName); String portletId = getPortletId( BlogsEntry.class.getName(), PortletProvider.Action.VIEW); if (Validator.isNull(portletId)) { return serviceContext; } StringBundler sb = new StringBundler(5); String layoutFullURL = _portal.getLayoutFullURL(groupId, portletId); sb.append(layoutFullURL); sb.append(Portal.FRIENDLY_URL_SEPARATOR); Portlet portlet = _portletLocalService.getPortletById( companyId, portletId); sb.append(portlet.getFriendlyURLMapping()); sb.append(StringPool.SLASH); sb.append(urlTitle); serviceContext.setAttribute("redirect", sb.toString()); serviceContext.setLayoutFullURL(layoutFullURL); return serviceContext; }  @Override Response execute(long companyId); @Override String getMethodName(); @Override String getToken(); @Override boolean setArguments(Object[] arguments); void setInetAddressLookup(InetAddressLookup inetAddressLookup); void setPingbackProperties(PingbackProperties pingbackProperties); void setPortletIdLookup(PortletIdLookup portletIdLookup); static final int ACCESS_DENIED; static final int GENERIC_FAULT; static final int PINGBACK_ALREADY_REGISTERED; static final int SERVER_ERROR; static final int SOURCE_URI_DOES_NOT_EXIST; static final int SOURCE_URI_INVALID; static final int TARGET_URI_DOES_NOT_EXIST; static final int TARGET_URI_INVALID; }
@Test public void testBuildServiceContext() throws Exception { PingbackMethodImpl pingbackMethodImpl = getPingbackMethodImpl(); ServiceContext serviceContext = pingbackMethodImpl.buildServiceContext( _COMPANY_ID, _GROUP_ID, _URL_TITLE); Assert.assertEquals( _PINGBACK_USER_NAME, serviceContext.getAttribute("pingbackUserName")); Assert.assertEquals( StringBundler.concat( _LAYOUT_FULL_URL, "/-/", _FRIENDLY_URL_MAPPING, "/", _URL_TITLE), serviceContext.getAttribute("redirect")); Assert.assertEquals( _LAYOUT_FULL_URL, serviceContext.getLayoutFullURL()); }