[Comsuite-svn] SF.net SVN: comsuite: [159] trunk/code/CSMiddleware/src/org/commsuite/sap
Brought to you by:
zduniak
|
From: <zd...@us...> - 2006-09-23 21:59:51
|
Revision: 159
http://svn.sourceforge.net/comsuite/?rev=159&view=rev
Author: zduniak
Date: 2006-09-23 14:59:40 -0700 (Sat, 23 Sep 2006)
Log Message:
-----------
Issue 0001350 resolved
Modified Paths:
--------------
trunk/code/CSMiddleware/src/org/commsuite/sap/JCoFunctionTranslator.java
trunk/code/CSMiddleware/src/org/commsuite/sap/SAPComm.java
Modified: trunk/code/CSMiddleware/src/org/commsuite/sap/JCoFunctionTranslator.java
===================================================================
--- trunk/code/CSMiddleware/src/org/commsuite/sap/JCoFunctionTranslator.java 2006-09-23 21:33:24 UTC (rev 158)
+++ trunk/code/CSMiddleware/src/org/commsuite/sap/JCoFunctionTranslator.java 2006-09-23 21:59:40 UTC (rev 159)
@@ -446,9 +446,10 @@
/**
* Converts JCO.Function objects into an array of
- * {@link org.commsuite.model.Message} objects. TODO: change println
- * statements to logger statements
+ * {@link org.commsuite.model.Message} objects.
*
+ * TODO: change println statements to logger statements
+ *
* @param function
* the {@link JCO.Function} object to convert
* @return the converted {@link org.commsuite.model.Message}
@@ -511,14 +512,14 @@
msg.setSapID(receiveInfoStructure.getString("COMM_ID"));
msg.setSender(receiveInfoStructure.getString("SENDER"));
final String format = receiveInfoStructure.getString("ADR_TYPE");
- if (format.equals("FAX")) {
+ if ("FAX".equals(format)) {
msg.setFormatType(FormatType.FAX);
}
- if (format.equals("INT")) {
+ if ("INT".equals(format)) {
msg.setFormatType(FormatType.EMAIL);
}
- if (format.equals("PAG")) {
+ if ("PAG".equals(format)) {
msg.setFormatType(FormatType.SMS);
}
@@ -564,13 +565,10 @@
* DOCUMENT_DATA structure
*/
// msg.setObjectName(documentDataStructure.getString("OBJ_NAME"));
- msg.setDescription(documentDataStructure.getString("OBJ_DESCR")/*
- * ,
- * partnerCharset
- */);
+ msg.setDescription(documentDataStructure.getString("OBJ_DESCR"));
msg.setPriority(Priority.LEVEL_4); // default
- Integer priority = new Integer(4);
+ Integer priority = 4;
try {
priority = (Integer) getOptionalVal("PRIORITY", TYPE_INT,
documentDataStructure);
@@ -583,25 +581,25 @@
}
// REFACTOR same thing with enum can be done here..[SK]
if (null != priority) {
- if (priority.equals(new Integer(0))) {
+ if (priority.equals(0)) {
msg.setPriority(Priority.LEVEL_0);
- } else if (priority.equals(new Integer(1))) {
+ } else if (priority.equals(1)) {
msg.setPriority(Priority.LEVEL_1);
- } else if (priority.equals(new Integer(2))) {
+ } else if (priority.equals(2)) {
msg.setPriority(Priority.LEVEL_2);
- } else if (priority.equals(new Integer(3))) {
+ } else if (priority.equals(3)) {
msg.setPriority(Priority.LEVEL_3);
- } else if (priority.equals(new Integer(4))) {
+ } else if (priority.equals(4)) {
msg.setPriority(Priority.LEVEL_4);
- } else if (priority.equals(new Integer(5))) {
+ } else if (priority.equals(5)) {
msg.setPriority(Priority.LEVEL_5);
- } else if (priority.equals(new Integer(6))) {
+ } else if (priority.equals(6)) {
msg.setPriority(Priority.LEVEL_6);
- } else if (priority.equals(new Integer(7))) {
+ } else if (priority.equals(7)) {
msg.setPriority(Priority.LEVEL_7);
- } else if (priority.equals(new Integer(8))) {
+ } else if (priority.equals(8)) {
msg.setPriority(Priority.LEVEL_8);
- } else if (priority.equals(new Integer(9))) {
+ } else if (priority.equals(9)) {
msg.setPriority(Priority.LEVEL_9);
}
}
Modified: trunk/code/CSMiddleware/src/org/commsuite/sap/SAPComm.java
===================================================================
--- trunk/code/CSMiddleware/src/org/commsuite/sap/SAPComm.java 2006-09-23 21:33:24 UTC (rev 158)
+++ trunk/code/CSMiddleware/src/org/commsuite/sap/SAPComm.java 2006-09-23 21:59:40 UTC (rev 159)
@@ -41,8 +41,8 @@
import com.sap.mw.jco.JCO.Function;
/**
- * Module responsible for initiationg server-side and client-side communication with the external
- * SAP R/3 system.
+ * Module responsible for initiationg server-side and client-side communication
+ * with the external SAP R/3 system.
*
* TODO: [MZ] Complete comments. REVIEW: [SK] ENCAPSULATION !!!
*
@@ -53,552 +53,595 @@
* @author Agnieszka Wiśniewska
*/
public class SAPComm implements ISAPComm {
-
+
private MessageManager msgManager;
-
+
private JMSMessageManager jmsManager;
- private long SX_OBJECT_RECEIVE_functionsNumber;
+ private long SX_OBJECT_RECEIVE_functionsNumber;
- private long SX_OBJECT_STATUS_RECEIVE_functionsNumber;
+ private long SX_OBJECT_STATUS_RECEIVE_functionsNumber;
- private long unrecognizedFunctionsNumber;
+ private long unrecognizedFunctionsNumber;
- private long errorsWhileHandlingFunctions;
+ private long errorsWhileHandlingFunctions;
- private final static Logger logger = Logger.getLogger(SAPComm.class);
+ private final static Logger logger = Logger.getLogger(SAPComm.class);
- private static final String JCO_CONNECTIONS_POOL_PREFIX = "CSPool_";
+ private static final String JCO_CONNECTIONS_POOL_PREFIX = "CSPool_";
- private static final String JCO_REPOSITORY_PREFIX = "CSRepo_";
+ private static final String JCO_REPOSITORY_PREFIX = "CSRepo_";
- // TODO: przeniesc wlanczanie/ wylanczanie trace'a do pliku local.properties
- private static final boolean TRACE_ENABLED = true;
+ // TODO: przeniesc wlanczanie/ wylanczanie trace'a do pliku local.properties
+ private static final boolean TRACE_ENABLED = true;
- /**
- * Definition of the logging parameters.
- */
- private SAPInstanceDef instanceDef;
+ /**
+ * Definition of the logging parameters.
+ */
+ private SAPInstanceDef instanceDef;
- /**
- * Indicate whther module has been corectly initiated.
- */
- private boolean initiated;
+ /**
+ * Indicate whther module has been corectly initiated.
+ */
+ private boolean initiated;
- /**
- * Remote repository of the associated SAP R/3 system.
- */
- private IRepository repository;
+ /**
+ * Remote repository of the associated SAP R/3 system.
+ */
+ private IRepository repository;
- /**
- * Inner instance of runnig server that registers itself on the remote SAP R/3 server.
- */
- private IJCOServer server;
+ /**
+ * Inner instance of runnig server that registers itself on the remote SAP
+ * R/3 server.
+ */
+ private IJCOServer server;
- private boolean handlingRequest;
+ private boolean handlingRequest;
- /**
- * Inner definition of JCO-based server.
- */
- /* package scope */class JCOServer extends JCO.Server implements IJCOServer, UncaughtExceptionHandler {
+ /**
+ * Inner definition of JCO-based server.
+ */
+ /* package scope */class JCOServer extends JCO.Server implements
+ IJCOServer, UncaughtExceptionHandler {
- private final Logger logger = Logger.getLogger(SAPComm.JCOServer.class);
+ private final Logger logger = Logger.getLogger(SAPComm.JCOServer.class);
- private final String PARTNER_CHARSET;
+ private final String PARTNER_CHARSET;
- /* package scope */JCOServer() {
- super(SAPComm.this.getLogonProperties(), SAPComm.this.repository);
- logger.info("Server registering properties: " + SAPComm.this.getLogonProperties());
- super.getThread().setUncaughtExceptionHandler(this);
- JCO.Client client = null;
- try {
- client = SAPComm.this.getJCOClient();
- PARTNER_CHARSET = client.getAttributes().getPartnerCharset();
- } finally {
- if (null != client) {
- releaseJCOClient(client);
- }
- }
- logger.info("JCO.Server created");
- }
+ /* package scope */JCOServer() {
+ super(SAPComm.this.getLogonProperties(), SAPComm.this.repository);
+ logger.info("Server registering properties: "
+ + SAPComm.this.getLogonProperties());
+ super.getThread().setUncaughtExceptionHandler(this);
+ JCO.Client client = null;
+ try {
+ client = SAPComm.this.getJCOClient();
+ PARTNER_CHARSET = client.getAttributes().getPartnerCharset();
+ } finally {
+ if (null != client) {
+ releaseJCOClient(client);
+ }
+ }
+ logger.info("JCO.Server created");
+ }
- @Override
- protected void handleRequest(final JCO.Function function) {
- handlingRequest = true;
- // TODO: rozwazyc czy nie lepiej obslugiwac zgloszenie od klientow w osobnych watkach.
- // strona: http://eclipsesap2java.sourceforge.net/Tips.htm pkt. 2 wskazuje ze
- // implementacja
- // SAP JCo pozwala tylko na jednego zdalnego uzytkownik (jeden SAP R/3) na jedna
- // instancje
- // Server JCo (tzn. nie jest ta implementacja analogiczna do specyfikacji Servletow,
- // gdzie
- // na jedna instance Servletu teoretycznie moze przypadac dowolna liczba zdalnych
- // uzytkownikow)
- handleJCORequest(function, PARTNER_CHARSET);
- handlingRequest = false;
- }
+ @Override
+ protected void handleRequest(final JCO.Function function) {
+ handlingRequest = true;
+ // TODO: rozwazyc czy nie lepiej obslugiwac zgloszenie od klientow w
+ // osobnych watkach.
+ // strona: http://eclipsesap2java.sourceforge.net/Tips.htm pkt. 2
+ // wskazuje ze
+ // implementacja
+ // SAP JCo pozwala tylko na jednego zdalnego uzytkownik (jeden SAP
+ // R/3) na jedna
+ // instancje
+ // Server JCo (tzn. nie jest ta implementacja analogiczna do
+ // specyfikacji Servletow,
+ // gdzie
+ // na jedna instance Servletu teoretycznie moze przypadac dowolna
+ // liczba zdalnych
+ // uzytkownikow)
+ handleJCORequest(function, PARTNER_CHARSET);
+ handlingRequest = false;
+ }
- public void serverExceptionOccurred(JCO.Server server, Exception ex) {
- logger.fatal("Exception in server: " + SAPComm.this.instanceDef.getName() + "[ProgID: "
- + server.getProgID() + "]", ex);
- }
+ public void serverExceptionOccurred(JCO.Server server, Exception ex) {
+ logger.fatal("Exception in server: "
+ + SAPComm.this.instanceDef.getName() + "[ProgID: "
+ + server.getProgID() + "]", ex);
+ }
- public void serverStateChangeOccurred(JCO.Server server, int oldState, int newState) {
- if (logger.isInfoEnabled()) {
- final TextBuilder sb = new TextBuilder();
- sb.append("Server: ").append(SAPComm.this.instanceDef.getName())
- .append("[ProgID: ").append(server.getProgID()).append("]").append(
- " changed state from [");
- // REFACTOR duplicated code here
- if ((oldState & JCO.STATE_STOPPED) != 0)
- sb.append(" STOPPED ");
- if ((oldState & JCO.STATE_STARTED) != 0)
- sb.append(" STARTED ");
- if ((oldState & JCO.STATE_LISTENING) != 0)
- sb.append(" LISTENING ");
- if ((oldState & JCO.STATE_TRANSACTION) != 0)
- sb.append(" TRANSACTION ");
- if ((oldState & JCO.STATE_BUSY) != 0)
- sb.append(" BUSY ");
+ public void serverStateChangeOccurred(JCO.Server server, int oldState,
+ int newState) {
+ if (logger.isInfoEnabled()) {
+ final TextBuilder sb = new TextBuilder();
+ sb.append("Server: ")
+ .append(SAPComm.this.instanceDef.getName()).append(
+ "[ProgID: ").append(server.getProgID()).append(
+ "]").append(" changed state from [");
+ // REFACTOR duplicated code here
+ if ((oldState & JCO.STATE_STOPPED) != 0)
+ sb.append(" STOPPED ");
+ if ((oldState & JCO.STATE_STARTED) != 0)
+ sb.append(" STARTED ");
+ if ((oldState & JCO.STATE_LISTENING) != 0)
+ sb.append(" LISTENING ");
+ if ((oldState & JCO.STATE_TRANSACTION) != 0)
+ sb.append(" TRANSACTION ");
+ if ((oldState & JCO.STATE_BUSY) != 0)
+ sb.append(" BUSY ");
- sb.append("] to [");
+ sb.append("] to [");
- if ((newState & JCO.STATE_STOPPED) != 0)
- sb.append(" STOPPED ");
- if ((newState & JCO.STATE_STARTED) != 0)
- sb.append(" STARTED ");
- if ((newState & JCO.STATE_LISTENING) != 0)
- sb.append(" LISTENING ");
- if ((newState & JCO.STATE_TRANSACTION) != 0)
- sb.append(" TRANSACTION ");
- if ((newState & JCO.STATE_BUSY) != 0)
- sb.append(" BUSY ");
+ if ((newState & JCO.STATE_STOPPED) != 0)
+ sb.append(" STOPPED ");
+ if ((newState & JCO.STATE_STARTED) != 0)
+ sb.append(" STARTED ");
+ if ((newState & JCO.STATE_LISTENING) != 0)
+ sb.append(" LISTENING ");
+ if ((newState & JCO.STATE_TRANSACTION) != 0)
+ sb.append(" TRANSACTION ");
+ if ((newState & JCO.STATE_BUSY) != 0)
+ sb.append(" BUSY ");
- sb.append("]");
+ sb.append("]");
- logger.info(sb.toString());
- }
- }
+ logger.info(sb.toString());
+ }
+ }
- public void serverErrorOccurred(JCO.Server server, Error error) {
- logger.fatal("Error in server: " + SAPComm.this.instanceDef.getName() + "[ProgID: "
- + server.getProgID() + "]", error);
-
- // TODO: consider stopping SAP server in exceptional situation:
- // stopServer();
- }
-
- public void uncaughtException(Thread t, Throwable e) {
- logger.fatal("UncaughtException in server: " + SAPComm.this.instanceDef.getName(), e);
-
- // TODO: consider stopping SAP server in exceptional situation:
- // stopServer();
- }
- }
+ public void serverErrorOccurred(JCO.Server server, Error error) {
+ logger.fatal("Error in server: "
+ + SAPComm.this.instanceDef.getName() + "[ProgID: "
+ + server.getProgID() + "]", error);
- public IJCOServer getServer() {
+ // TODO: consider stopping SAP server in exceptional situation:
+ // stopServer();
+ }
+
+ public void uncaughtException(Thread t, Throwable e) {
+ logger.fatal("UncaughtException in server: "
+ + SAPComm.this.instanceDef.getName(), e);
+
+ // TODO: consider stopping SAP server in exceptional situation:
+ // stopServer();
+ }
+ }
+
+ public IJCOServer getServer() {
return server;
}
public void handleJCORequest(final JCO.Function function, String charset) {
- try {
- logger.info("Handling request for function: " + function.getName());
- if (JCoFunctionTranslator.SX_OBJECT_RECEIVE.equals(function.getName())) {
- final Message[] messages = JCoFunctionTranslator.getMessagesFromJCOFunction(
- function, charset);
+ try {
+ logger.info("Handling request for function: " + function.getName());
+ if (JCoFunctionTranslator.SX_OBJECT_RECEIVE.equals(function
+ .getName())) {
+ final Message[] messages = JCoFunctionTranslator
+ .getMessagesFromJCOFunction(function, charset);
- if (null == msgManager) {
- msgManager = SpringMiddlewareContext.getMessageManager();
- }
-
- if (null == jmsManager) {
- jmsManager = SpringMiddlewareContext.getJMSManager();
- }
+ if (null != messages && messages.length > 0
+ && 0 == messages[0].getSentContents().size()) {
+ throw new JCO.AbapException("INTERNAL",
+ "Message without any content is not supported");
+ }
- final Date currentDate = new Date();
- for (Message msg : messages) {
- msg.setSAPInstanceDefOwner(instanceDef);
- if (null == msg.getSendDate()) {
- msg.setSendDate(currentDate);
- }
- msg = msgManager.saveMessage(msg);
- jmsManager.sendMessage(SpringMiddlewareBeansConstants.M_OUT_ROUTER_QUEUE_NAME,
- msg);
- }
+ if (null == msgManager) {
+ msgManager = SpringMiddlewareContext.getMessageManager();
+ }
- SX_OBJECT_RECEIVE_functionsNumber++;
- } else if (JCoFunctionTranslator.SX_OBJECT_STATUS_RECEIVE.equals(function.getName())) {
- // TODO: implement receiving status information
- final Message messageToUpdate = SpringMiddlewareContext.getMessageManager()
- .getMessageBySapIdAndSAPInstanceDef("TODO:someId", this.instanceDef);
+ if (null == jmsManager) {
+ jmsManager = SpringMiddlewareContext.getJMSManager();
+ }
- SX_OBJECT_STATUS_RECEIVE_functionsNumber++;
- } else {
- if (false == JCOFunctionsImplementation.serveFunction(function, charset)) {
- logger.warn("SAP JCO function: " + function.getName() + " not supported.");
- this.unrecognizedFunctionsNumber++;
- throw new JCO.AbapException("INTERNAL", "Function " + function.getName()
- + " not supported.");
- }
- }
- } catch (JCO.AbapException ex) {
- logger.fatal("AbapException during handlig request", ex);
- errorsWhileHandlingFunctions++;
- throw ex;
- } catch (Throwable t) {
- logger.fatal("Unrecognized exception during handlig request", t);
- errorsWhileHandlingFunctions++;
- throw new JCO.AbapException("SYSTEM_FAILURE", t.getMessage());
- }
- }
+ final Date currentDate = new Date();
+ for (Message msg : messages) {
+ msg.setSAPInstanceDefOwner(instanceDef);
+ if (null == msg.getSendDate()) {
+ msg.setSendDate(currentDate);
+ }
+ msg = msgManager.saveMessage(msg);
+ jmsManager
+ .sendMessage(
+ SpringMiddlewareBeansConstants.M_OUT_ROUTER_QUEUE_NAME,
+ msg);
+ }
- /**
- * REVIEW: public ? what for ? i dont think that this method is necessary at all.
- *
- * @param server
- * The server to set.
- */
- public void setServer(IJCOServer server) {
- this.server = server;
- }
+ SX_OBJECT_RECEIVE_functionsNumber++;
+ } else if (JCoFunctionTranslator.SX_OBJECT_STATUS_RECEIVE
+ .equals(function.getName())) {
+ // TODO: implement receiving status information
+ final Message messageToUpdate = SpringMiddlewareContext
+ .getMessageManager()
+ .getMessageBySapIdAndSAPInstanceDef("TODO:someId",
+ this.instanceDef);
- /**
- * @return Returns whether initiated
- */
- public boolean isInitiated() {
- return initiated;
- }
+ SX_OBJECT_STATUS_RECEIVE_functionsNumber++;
+ } else {
+ if (false == JCOFunctionsImplementation.serveFunction(function,
+ charset)) {
+ logger.warn("SAP JCO function: " + function.getName()
+ + " not supported.");
+ this.unrecognizedFunctionsNumber++;
+ throw new JCO.AbapException("INTERNAL", "Function "
+ + function.getName() + " not supported.");
+ }
+ }
+ } catch (JCO.AbapException ex) {
+ logger.fatal("AbapException during handlig request", ex);
+ errorsWhileHandlingFunctions++;
+ throw ex;
+ } catch (Throwable t) {
+ logger.fatal("Unrecognized exception during handlig request", t);
+ errorsWhileHandlingFunctions++;
+ throw new JCO.AbapException("SYSTEM_FAILURE", t.getMessage());
+ }
+ }
- /**
- * @param initiated
- * The initiated to set.
- */
- /* package scope */void setInitiated(boolean initiated) {
- this.initiated = initiated;
- }
+ /**
+ * REVIEW: public ? what for ? i dont think that this method is necessary at
+ * all.
+ *
+ * @param server
+ * The server to set.
+ */
+ public void setServer(IJCOServer server) {
+ this.server = server;
+ }
- /**
- * Default public constructor.
- */
- public SAPComm() {
- super();
- }
+ /**
+ * @return Returns whether initiated
+ */
+ public boolean isInitiated() {
+ return initiated;
+ }
- /**
- * @return Returns the instanceDef.
- */
- public SAPInstanceDef getInstanceDef() {
- return instanceDef;
- }
+ /**
+ * @param initiated
+ * The initiated to set.
+ */
+ /* package scope */void setInitiated(boolean initiated) {
+ this.initiated = initiated;
+ }
- /**
- * @param instanceDef
- * The instanceDef to set.
- */
- /* package scope */void setInstanceDef(SAPInstanceDef instanceDef) {
- this.instanceDef = instanceDef;
- }
+ /**
+ * Default public constructor.
+ */
+ public SAPComm() {
+ super();
+ }
- /**
- * @param instanceDef
- * Definition of the logging parameters
- * @throws IllegalArgumentException
- */
- public void init(SAPInstanceDef instanceDef) {
- if (null == instanceDef) {
- throw new IllegalArgumentException("Given instanceDef parameter can not be null.");
- }
- if (initiated) {
- destroy();
- }
- this.instanceDef = instanceDef;
- initSAPConnections();
- initRepository();
- initiated = true;
- }
+ /**
+ * @return Returns the instanceDef.
+ */
+ public SAPInstanceDef getInstanceDef() {
+ return instanceDef;
+ }
- private void initRepository() {
- repository = JCO.createRepository(getRepositoryName(), getPoolName());
- }
+ /**
+ * @param instanceDef
+ * The instanceDef to set.
+ */
+ /* package scope */void setInstanceDef(SAPInstanceDef instanceDef) {
+ this.instanceDef = instanceDef;
+ }
- private void initSAPConnections() {
- releaseSAPConnections();
+ /**
+ * @param instanceDef
+ * Definition of the logging parameters
+ * @throws IllegalArgumentException
+ */
+ public void init(SAPInstanceDef instanceDef) {
+ if (null == instanceDef) {
+ throw new IllegalArgumentException(
+ "Given instanceDef parameter can not be null.");
+ }
+ if (initiated) {
+ destroy();
+ }
+ this.instanceDef = instanceDef;
+ initSAPConnections();
+ initRepository();
+ initiated = true;
+ }
- // creating a new connection pool
- final String poolName = getPoolName();
- JCO.addClientPool(poolName, instanceDef.getMaxConnectionsInPool(), getLogonProperties());
- final JCO.Pool pool = JCO.getClientPoolManager().getPool(poolName);
- pool.setMaxConnections(2 * instanceDef.getMaxConnectionsInPool());
- pool.setTrace(TRACE_ENABLED);
- }
+ private void initRepository() {
+ repository = JCO.createRepository(getRepositoryName(), getPoolName());
+ }
- /* package scope */Properties getLogonProperties() {
- final String JCO_CLIENT_PREFIX = "jco.client.";
- final String JCO_SERVER_PREFIX = "jco.server.";
- final Properties props = new Properties();
+ private void initSAPConnections() {
+ releaseSAPConnections();
- // client properties:
- props.put(JCO_CLIENT_PREFIX + "client", instanceDef.getClient());
- props.put(JCO_CLIENT_PREFIX + "user", instanceDef.getUser());
- props.put(JCO_CLIENT_PREFIX + "passwd", instanceDef.getPassword());
+ // creating a new connection pool
+ final String poolName = getPoolName();
+ JCO.addClientPool(poolName, instanceDef.getMaxConnectionsInPool(),
+ getLogonProperties());
+ final JCO.Pool pool = JCO.getClientPoolManager().getPool(poolName);
+ pool.setMaxConnections(2 * instanceDef.getMaxConnectionsInPool());
+ pool.setTrace(TRACE_ENABLED);
+ }
- // if (null != instanceDef.getLanguage()) {
- // props.put(JCO_CLIENT_PREFIX + "lang", instanceDef.getLanguage());
- // }
+ /* package scope */Properties getLogonProperties() {
+ final String JCO_CLIENT_PREFIX = "jco.client.";
+ final String JCO_SERVER_PREFIX = "jco.server.";
+ final Properties props = new Properties();
- if (instanceDef.isLoadBalancing()) {
- props.put(JCO_CLIENT_PREFIX + "r3name", instanceDef.getR3name());
- props.put(JCO_CLIENT_PREFIX + "group", instanceDef.getGroup());
- props.put(JCO_CLIENT_PREFIX + "mshost", instanceDef.getHost());
+ // client properties:
+ props.put(JCO_CLIENT_PREFIX + "client", instanceDef.getClient());
+ props.put(JCO_CLIENT_PREFIX + "user", instanceDef.getUser());
+ props.put(JCO_CLIENT_PREFIX + "passwd", instanceDef.getPassword());
- } else {
- props.put(JCO_CLIENT_PREFIX + "sysnr", instanceDef.getSystemNumber());
- props.put(JCO_CLIENT_PREFIX + "ashost", instanceDef.getHost());
- }
+ // if (null != instanceDef.getLanguage()) {
+ // props.put(JCO_CLIENT_PREFIX + "lang", instanceDef.getLanguage());
+ // }
- props.put(JCO_CLIENT_PREFIX + "trace", TRACE_ENABLED ? "1" : "0");
- props.put(JCO_CLIENT_PREFIX + "lcheck", "1");
+ if (instanceDef.isLoadBalancing()) {
+ props.put(JCO_CLIENT_PREFIX + "r3name", instanceDef.getR3name());
+ props.put(JCO_CLIENT_PREFIX + "group", instanceDef.getGroup());
+ props.put(JCO_CLIENT_PREFIX + "mshost", instanceDef.getHost());
- // server properties:
- props.put(JCO_SERVER_PREFIX + "gwhost", instanceDef.getGwhost());
- props.put(JCO_SERVER_PREFIX + "gwserv", instanceDef.getGwserv());
- props.put(JCO_SERVER_PREFIX + "progid", instanceDef.getProgid());
- props.put(JCO_SERVER_PREFIX + "unicode", instanceDef.isUnicode() ? "1" : "0");
+ } else {
+ props.put(JCO_CLIENT_PREFIX + "sysnr", instanceDef
+ .getSystemNumber());
+ props.put(JCO_CLIENT_PREFIX + "ashost", instanceDef.getHost());
+ }
- return props;
- }
+ props.put(JCO_CLIENT_PREFIX + "trace", TRACE_ENABLED ? "1" : "0");
+ props.put(JCO_CLIENT_PREFIX + "lcheck", "1");
- private void releaseSAPConnections() {
- // testing whether connection pool already exists:
- final JCO.Pool pool = JCO.getClientPoolManager().getPool(getPoolName());
- if (null != pool) {
- // pool already exists, so we remove it
- JCO.getClientPoolManager().removePool(getPoolName());
- }
- }
+ // server properties:
+ props.put(JCO_SERVER_PREFIX + "gwhost", instanceDef.getGwhost());
+ props.put(JCO_SERVER_PREFIX + "gwserv", instanceDef.getGwserv());
+ props.put(JCO_SERVER_PREFIX + "progid", instanceDef.getProgid());
+ props.put(JCO_SERVER_PREFIX + "unicode", instanceDef.isUnicode() ? "1"
+ : "0");
- private String getPoolName() {
- return JCO_CONNECTIONS_POOL_PREFIX + instanceDef.getName();
- }
+ return props;
+ }
- private String getRepositoryName() {
- return JCO_REPOSITORY_PREFIX + instanceDef.getName();
- }
+ private void releaseSAPConnections() {
+ // testing whether connection pool already exists:
+ final JCO.Pool pool = JCO.getClientPoolManager().getPool(getPoolName());
+ if (null != pool) {
+ // pool already exists, so we remove it
+ JCO.getClientPoolManager().removePool(getPoolName());
+ }
+ }
- /* package scope */JCO.Client getJCOClient() {
- return JCO.getClient(getPoolName());
- }
+ private String getPoolName() {
+ return JCO_CONNECTIONS_POOL_PREFIX + instanceDef.getName();
+ }
- private void releaseJCOClient(JCO.Client client) {
- JCO.releaseClient(client);
- }
+ private String getRepositoryName() {
+ return JCO_REPOSITORY_PREFIX + instanceDef.getName();
+ }
- public void destroy() {
- stopServer();
- releaseSAPConnections();
- instanceDef = null;
- initiated = false;
- }
+ /* package scope */JCO.Client getJCOClient() {
+ return JCO.getClient(getPoolName());
+ }
- public void stopServer() {
- if (null != server && server.isAlive()) {
- logger.debug("Stopping SAP server");
- server.stop();
- server.abort("Connection aborted by administrator.");
- } else {
- logger.debug("SAP server already stopped");
- }
- server = null;
- logger.debug("SAP server STOPPED");
- }
+ private void releaseJCOClient(JCO.Client client) {
+ JCO.releaseClient(client);
+ }
- /**
- * this method was created only to be override in tests
- *
- * @return new {@link SAPComm.JCOServer} instance
- */
- /* package scope */IJCOServer getNewJCOServer() {
- return this.new JCOServer();
- }
+ public void destroy() {
+ stopServer();
+ releaseSAPConnections();
+ instanceDef = null;
+ initiated = false;
+ }
- public void startServer() {
- if (!isRemoteSystemWorking()) {
- logger.error("Remote system is not working: " + getName());
- return;
- }
- stopServer();
- server = getNewJCOServer();
- server.setTrace(TRACE_ENABLED);
- JCO.addServerExceptionListener(server);
- JCO.addServerStateChangedListener(server);
- JCO.addServerErrorListener(server);
- server.start();
- }
+ public void stopServer() {
+ if (null != server && server.isAlive()) {
+ logger.debug("Stopping SAP server");
+ server.stop();
+ server.abort("Connection aborted by administrator.");
+ } else {
+ logger.debug("SAP server already stopped");
+ }
+ server = null;
+ logger.debug("SAP server STOPPED");
+ }
- /**
- * @return true if message was sent, false if sending failed
- */
- public boolean sendMessage(Message message) {
- logger.debug("Sending message: " + message.toString());
+ /**
+ * this method was created only to be override in tests
+ *
+ * @return new {@link SAPComm.JCOServer} instance
+ */
+ /* package scope */IJCOServer getNewJCOServer() {
+ return this.new JCOServer();
+ }
- JCO.Client client = null;
- try {
- // setting correct receiver:
- message.setReceiver(instanceDef.getAdminEmail());
+ public void startServer() {
+ if (!isRemoteSystemWorking()) {
+ logger.error("Remote system is not working: " + getName());
+ return;
+ }
+ stopServer();
+ server = getNewJCOServer();
+ server.setTrace(TRACE_ENABLED);
+ JCO.addServerExceptionListener(server);
+ JCO.addServerStateChangedListener(server);
+ JCO.addServerErrorListener(server);
+ server.start();
+ }
- // converting message to JCO.Function:
- final JCO.Function f = JCoFunctionTranslator.getJCOFunctionFromMessage(message,
- repository);
+ /**
+ * @return true if message was sent, false if sending failed
+ */
+ public boolean sendMessage(Message message) {
+ logger.debug("Sending message: " + message.toString());
- // REVIEW: is below synchronization necessary ?
- // synchronized (this) {
- client = getJCOClient();
- client.execute(f);
- // }
- final boolean send = checkFunctionReturn(f);
- logger.debug("Message to [" + message.getReceiver() + "] sent status: " + send);
- return send;
- } catch (Throwable t) {
- logger.fatal("Exception during sending the message to SAP server", t);
- return false;
- } finally {
- if (null != client) {
- releaseJCOClient(client);
- }
- }
- }
+ JCO.Client client = null;
+ try {
+ // setting correct receiver:
+ message.setReceiver(instanceDef.getAdminEmail());
- private boolean checkFunctionReturn(final Function f) {
- // testing return state:
- final JCO.Table receivers = f.getTableParameterList().getTable("RECEIVERS");
- receivers.setRow(0);
- final String code = receivers.getString("CODE");
+ // converting message to JCO.Function:
+ final JCO.Function f = JCoFunctionTranslator
+ .getJCOFunctionFromMessage(message, repository);
- if (logger.isDebugEnabled()) {
- logger.debug("Answer: " + code);
- logger.debug("MSGV1: " + receivers.getString("MSGV1"));
- logger.debug("MSGV2: " + receivers.getString("MSGV2"));
- logger.debug("MSGV3: " + receivers.getString("MSGV3"));
- logger.debug("MSGV4: " + receivers.getString("MSGV4"));
- }
+ // REVIEW: is below synchronization necessary ?
+ // synchronized (this) {
+ client = getJCOClient();
+ client.execute(f);
+ // }
+ final boolean send = checkFunctionReturn(f);
+ logger.debug("Message to [" + message.getReceiver()
+ + "] sent status: " + send);
+ return send;
+ } catch (Throwable t) {
+ logger.fatal("Exception during sending the message to SAP server",
+ t);
+ return false;
+ } finally {
+ if (null != client) {
+ releaseJCOClient(client);
+ }
+ }
+ }
- // TODO: ustawianie odpowiednich pol w message w zaleznosci od zwroconego 'CODE'
- // i powyzszych dodatkowych parametrow MSGV1..4
+ private boolean checkFunctionReturn(final Function f) {
+ // testing return state:
+ final JCO.Table receivers = f.getTableParameterList().getTable(
+ "RECEIVERS");
+ receivers.setRow(0);
+ final String code = receivers.getString("CODE");
- return SAPStatusCodeConstants.DELIVERED_SUCCESSFULLY_701.equals(code);
- }
+ if (logger.isDebugEnabled()) {
+ logger.debug("Answer: " + code);
+ logger.debug("MSGV1: " + receivers.getString("MSGV1"));
+ logger.debug("MSGV2: " + receivers.getString("MSGV2"));
+ logger.debug("MSGV3: " + receivers.getString("MSGV3"));
+ logger.debug("MSGV4: " + receivers.getString("MSGV4"));
+ }
- public boolean sendNotification(Notification notification) {
- logger.debug("Sending notification: " + notification.toString());
+ // TODO: ustawianie odpowiednich pol w message w zaleznosci od
+ // zwroconego 'CODE'
+ // i powyzszych dodatkowych parametrow MSGV1..4
- JCO.Client client = null;
- try {
- // converting notification message to JCO.Function:
- final JCO.Function f = JCoFunctionTranslator.getJCOFunctionFromNotification(
- notification, repository);
+ return SAPStatusCodeConstants.DELIVERED_SUCCESSFULLY_701.equals(code);
+ }
- // REVIEW: is below synchronization necessary ?
- // synchronized (this) {
- client = getJCOClient();
- client.execute(f);
- // }
- final boolean send = checkFunctionReturn(f);
- logger.debug("Notification message to [" + notification.getMessage().getSender()
- + "] delivered with sent status: " + notification.getState().name());
- return send;
- } catch (Throwable t) {
- logger.fatal("Exception during sending the notification message to SAP server", t);
- return false;
- } finally {
- if (null != client) {
- releaseJCOClient(client);
- }
- }
- }
+ public boolean sendNotification(Notification notification) {
+ logger.debug("Sending notification: " + notification.toString());
- public boolean isRemoteSystemWorking() {
- // TODO: [MZ] i'm not sure whether this implementation is correct
- JCO.Client client = null;
- try {
- client = getJCOClient();
-
- if (null == client) {
- logger
- .warn("Cannot obtain JCO.Client object from pool during testing SAP server's state.");
- return false;
- }
-
- // Send a ping to the server
- client.ping();
+ JCO.Client client = null;
+ try {
+ // converting notification message to JCO.Function:
+ final JCO.Function f = JCoFunctionTranslator
+ .getJCOFunctionFromNotification(notification, repository);
-// final JCO.Attributes attr = client.getAttributes();
-// final String partnerRelease = attr.getPartnerRelease();
-// logger.debug("Partner release: " + partnerRelease);
-// return (null != partnerRelease) && (partnerRelease.length() > 0);
-
- return true;
- } catch (Throwable t) {
- logger.error("Exception during testing SAP server's state", t);
- return false;
- } finally {
- if (null != client) {
- releaseJCOClient(client);
- }
- }
- }
+ // REVIEW: is below synchronization necessary ?
+ // synchronized (this) {
+ client = getJCOClient();
+ client.execute(f);
+ // }
+ final boolean send = checkFunctionReturn(f);
+ logger.debug("Notification message to ["
+ + notification.getMessage().getSender()
+ + "] delivered with sent status: "
+ + notification.getState().name());
+ return send;
+ } catch (Throwable t) {
+ logger
+ .fatal(
+ "Exception during sending the notification message to SAP server",
+ t);
+ return false;
+ } finally {
+ if (null != client) {
+ releaseJCOClient(client);
+ }
+ }
+ }
- public boolean isDefault() {
- return instanceDef.isDefaultInstance();
- }
+ public boolean isRemoteSystemWorking() {
+ // TODO: [MZ] i'm not sure whether this implementation is correct
+ JCO.Client client = null;
+ try {
+ client = getJCOClient();
- public String getName() {
- return instanceDef.getName();
- }
+ if (null == client) {
+ logger
+ .warn("Cannot obtain JCO.Client object from pool during testing SAP server's state.");
+ return false;
+ }
- @Override
- public boolean equals(final Object o) {
- // REVIEW: is this correct ?
- if (null == o) {
- return false;
- }
- if (!(o instanceof SAPComm)) {
- return false;
- }
- if (o == this) {
- return true;
- }
+ // Send a ping to the server
+ client.ping();
- final SAPComm s = (SAPComm) o;
- return s.getName().equals(this.getName());
- }
+ // final JCO.Attributes attr = client.getAttributes();
+ // final String partnerRelease = attr.getPartnerRelease();
+ // logger.debug("Partner release: " + partnerRelease);
+ // return (null != partnerRelease) && (partnerRelease.length() > 0);
- @Override
- public int hashCode() {
- return getName().hashCode();
- // TODO: implement
- }
+ return true;
+ } catch (Throwable t) {
+ logger.error("Exception during testing SAP server's state", t);
+ return false;
+ } finally {
+ if (null != client) {
+ releaseJCOClient(client);
+ }
+ }
+ }
- /**
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return new ToStringBuilder(this).append("name", this.getName()).append(" initiated",
- this.initiated).append(" default", this.isDefault()).append(
- " SX_OBJECT_RECEIVE functions number", this.SX_OBJECT_RECEIVE_functionsNumber)
- .append(" SX_OBJECT_STATUS_RECEIVE_functionsNumber",
- this.SX_OBJECT_STATUS_RECEIVE_functionsNumber).append(
- " Unrecognized functions number", this.unrecognizedFunctionsNumber).append(
- " Errors while handling functions", this.errorsWhileHandlingFunctions)
- .toString();
- }
+ public boolean isDefault() {
+ return instanceDef.isDefaultInstance();
+ }
- public boolean isHandlingRequest() {
- return handlingRequest;
- }
-
- public boolean isActiveInstance() {
- return this.instanceDef.isActiveInstance();
- }
+ public String getName() {
+ return instanceDef.getName();
+ }
+ @Override
+ public boolean equals(final Object o) {
+ // REVIEW: is this correct ?
+ if (null == o) {
+ return false;
+ }
+ if (!(o instanceof SAPComm)) {
+ return false;
+ }
+ if (o == this) {
+ return true;
+ }
+
+ final SAPComm s = (SAPComm) o;
+ return s.getName().equals(this.getName());
+ }
+
+ @Override
+ public int hashCode() {
+ return getName().hashCode();
+ // TODO: implement
+ }
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this).append("name", this.getName()).append(
+ " initiated", this.initiated).append(" default",
+ this.isDefault()).append(" SX_OBJECT_RECEIVE functions number",
+ this.SX_OBJECT_RECEIVE_functionsNumber).append(
+ " SX_OBJECT_STATUS_RECEIVE_functionsNumber",
+ this.SX_OBJECT_STATUS_RECEIVE_functionsNumber).append(
+ " Unrecognized functions number",
+ this.unrecognizedFunctionsNumber).append(
+ " Errors while handling functions",
+ this.errorsWhileHandlingFunctions).toString();
+ }
+
+ public boolean isHandlingRequest() {
+ return handlingRequest;
+ }
+
+ public boolean isActiveInstance() {
+ return this.instanceDef.isActiveInstance();
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|