Example usage for com.liferay.portal.kernel.util ReleaseInfo getServerInfo

List of usage examples for com.liferay.portal.kernel.util ReleaseInfo getServerInfo

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util ReleaseInfo getServerInfo.

Prototype

public static final String getServerInfo() 

Source Link

Usage

From source file:com.liferay.ide.server.core.support.ReleaseInfoGetServerInfo.java

License:Open Source License

@Override
void writeOutput(FileWriter writer) throws IOException {

    writer.write(ReleaseInfo.getServerInfo());
}

From source file:com.liferay.portlet.blogs.util.LinkbackProducerUtil.java

License:Open Source License

public static boolean sendTrackback(String trackback, Map<String, String> parts) throws Exception {

    if (_log.isInfoEnabled()) {
        _log.info("Pinging trackback " + trackback);
    }/*from www .j ava  2 s  . com*/

    Http.Options options = new Http.Options();

    options.addHeader(HttpHeaders.USER_AGENT, ReleaseInfo.getServerInfo());
    options.setLocation(trackback);
    options.setParts(parts);
    options.setPost(true);

    String xml = HttpUtil.URLtoString(options);

    if (_log.isDebugEnabled()) {
        _log.debug(xml);
    }

    String error = xml;

    XMLStreamReader xmlStreamReader = null;

    try {
        XMLInputFactory xmlInputFactory = StAXReaderUtil.getXMLInputFactory();

        xmlStreamReader = xmlInputFactory.createXMLStreamReader(new UnsyncStringReader(xml));

        xmlStreamReader.nextTag();
        xmlStreamReader.nextTag();

        String name = xmlStreamReader.getLocalName();

        if (name.equals("error")) {
            int status = GetterUtil.getInteger(xmlStreamReader.getElementText(), 1);

            if (status == 0) {
                if (_log.isInfoEnabled()) {
                    _log.info("Trackback accepted");
                }

                return true;
            }

            xmlStreamReader.nextTag();

            name = xmlStreamReader.getLocalName();

            if (name.equals("message")) {
                error = xmlStreamReader.getElementText();
            }
        }
    } finally {
        if (xmlStreamReader != null) {
            try {
                xmlStreamReader.close();
            } catch (Exception e) {
            }
        }
    }

    _log.error("Error while pinging trackback at " + trackback + ": " + error);

    return false;
}

From source file:com.liferay.portlet.blogs.util.LinkbackProducerUtil.java

License:Open Source License

private static String _discoverPingbackServer(String targetUri) {
    String serverUri = null;//from w  ww . j  a v a 2s.  c  o m

    try {
        Http.Options options = new Http.Options();

        options.addHeader(HttpHeaders.USER_AGENT, ReleaseInfo.getServerInfo());
        options.setLocation(targetUri);
        options.setHead(true);

        HttpUtil.URLtoByteArray(options);

        Http.Response response = options.getResponse();

        serverUri = response.getHeader("X-Pingback");
    } catch (Exception e) {
        _log.error("Unable to call HEAD of " + targetUri, e);
    }

    if (Validator.isNull(serverUri)) {
        try {
            Source clientSource = new Source(HttpUtil.URLtoString(targetUri));

            List<StartTag> startTags = clientSource.getAllStartTags("link");

            for (StartTag startTag : startTags) {
                String rel = startTag.getAttributeValue("rel");

                if (rel.equalsIgnoreCase("pingback")) {
                    String href = startTag.getAttributeValue("href");

                    serverUri = HtmlUtil.escape(href);

                    break;
                }
            }
        } catch (Exception e) {
            _log.error("Unable to call GET of " + targetUri, e);
        }
    }

    return serverUri;
}

From source file:com.liferay.wsrp.service.impl.WSRPConsumerLocalServiceImpl.java

License:Open Source License

protected RegistrationContext register(WSRPConsumer wsrpConsumer, String adminPortletId,
        UnicodeProperties registrationProperties) throws Exception {

    WSRPConsumerManager wsrpConsumerManager = WSRPConsumerManagerFactory.getWSRPConsumerManager(wsrpConsumer);

    WSRP_v2_Registration_PortType registrationService = wsrpConsumerManager.getRegistrationService();

    RegistrationContext registrationContext = wsrpConsumer.getRegistrationContext();

    Property[] properties = new Property[registrationProperties.size()];

    List<Map.Entry<String, String>> registrationPropertiesList = ListUtil
            .fromCollection(registrationProperties.entrySet());

    for (int i = 0; i < properties.length; i++) {
        Map.Entry<String, String> entry = registrationPropertiesList.get(i);

        String name = entry.getKey();
        String value = entry.getValue();

        PropertyDescription propertyDescription = wsrpConsumerManager.getPropertyDescription(name);

        QName qName = propertyDescription.getName();

        Property property = new Property();

        property.setName(qName);//from ww w.  ja  v  a  2s. c o m
        property.setStringValue(value);

        properties[i] = property;
    }

    Company company = CompanyLocalServiceUtil.getCompany(wsrpConsumer.getCompanyId());

    RegistrationData registrationData = new RegistrationData();

    registrationData.setConsumerAgent(ReleaseInfo.getServerInfo());
    registrationData.setConsumerName(company.getVirtualHostname());
    registrationData.setMethodGetSupported(true);
    registrationData.setRegistrationProperties(properties);

    if (registrationContext == null) {
        Register register = new Register();

        register.setRegistrationData(registrationData);

        registrationContext = registrationService.register(register);
    } else {
        ModifyRegistration modifyRegistration = new ModifyRegistration();

        modifyRegistration.setRegistrationContext(registrationContext);
        modifyRegistration.setRegistrationData(registrationData);

        RegistrationState registrationState = registrationService.modifyRegistration(modifyRegistration);

        byte[] registrationStateValue = registrationState.getRegistrationState();

        if (registrationStateValue != null) {
            registrationContext.setRegistrationState(registrationState.getRegistrationState());
        }

        Lifetime scheduledDestruction = registrationState.getScheduledDestruction();

        if (scheduledDestruction != null) {
            registrationContext.setScheduledDestruction(scheduledDestruction);
        }
    }

    wsrpConsumerManager.updateServiceDescription(registrationContext);

    return registrationContext;
}

From source file:org.dihedron.strutlets.containers.portlet.liferay.Liferay.java

License:Open Source License

/**
 * Returns a string describing the name and version of this Liferay instance.
 * /*ww w  . ja v  a 2s.com*/
 * @return
 *   a string describing the name and version of this Liferay instance.
 */
public String getServerInfo() {
    return ReleaseInfo.getServerInfo();
}

From source file:org.dihedron.strutlets.containers.portlet.liferay61x.Liferay61x.java

License:Open Source License

@Override
public String getName() {
    return ReleaseInfo.getServerInfo();
}