civca
Returning Observer

How to get server host name and port from content creator

I created workflow that will run script from wich I try to create connection and login ticket for certain user and send that trough email to that user.

Main line is this:

Connection connectionForExternalUser = ConnectionManager.getConnection("host name", 8443, ConnectionManager.HTTP_MODE, "user name", "user pass");

When i hardcode "host name" and "port" everything works fine from SA and from CC also. But when I try to get host name trough API, one of the next examples:

  host0 = context.getConnection().getHost();

  host1 = context.getScript().getProject().getUserService().getConnection().getHost();

  host2 = context.getUserService().getConnection().getHost();

  host3 = context.getProject().getConnection().getHost();

  host4 = context.getProject().getUserService().getConnection().getHost();

  host5 = context.getElement().getProject().getConnection().getHost();

then it works from SA (it returns server host name) but not from CC (returns empty string for every case). And I found that from CC I am getting diferent context and connection object then from SA.

SA:

workflow script context: class de.espirit.firstspirit.impl.access.store.templatestore.WorkflowScriptContextImpl

workflow context: class de.espirit.firstspirit.client.gui.workflow.GuiHostWorkflowContext

connection: class de.espirit.firstspirit.client.io.ConnectionImpl

CC:

workflow script context: class de.espirit.firstspirit.webedit.server.workflow.WebeditWorkflowScriptContextImpl

workflow context: class de.espirit.firstspirit.webedit.server.workflow.WebeditWorkflowContext

connection: class de.espirit.firstspirit.webedit.server.io.WebeditConnection

So, do you have any idea how I can get server host name and server port trough workflow-script from CC?

0 Kudos
2 Replies
mbergmann
Crownpeak employee

Hello Milos,

please have a look at the ServerConfigurationAgent - I think that can help.

A small example:

import de.espirit.firstspirit.agency.ServerConfigurationAgent;

import de.espirit.firstspirit.server.configuration.ServerProperties;

ServerConfigurationAgent sca = context.requireSpecialist(ServerConfigurationAgent.TYPE);

String hostname = sca.getServerProperty(ServerProperties.HOST).get();

int port = sca.getServerProperty(ServerProperties.HTTP_PORT).get();

You can find a list of more accessible properties here ​.

Michael

0 Kudos
civca
Returning Observer

Hello Michael,

Thank you for your suggestion. I did not get proper information trough ServerProperties.HOST and ServerProperties.PORT. (it returns localhost and 8000).

But I found ServerProperties.URL from where I get java.net.URL object and then request getHost() and getPort().

Best

0 Kudos