You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fx-dev@ws.apache.org by ja...@apache.org on 2005/07/08 08:55:02 UTC
cvs commit: ws-sandesha/test-resources client-config.wsdd
jaliya 2005/07/07 23:55:02
Added: src/org/apache/sandesha/client ClientHandlerUtil.java
ClientListener.java
src/org/apache/sandesha/server DelegateInvokeHandler.java
InvokeHandler.java InvokeStrategy.java
InvokerFactory.java RMInvokerWork.java
ThreadPoolInvokeStrategy.java
test-resources client-config.wsdd
Log:
Added some missing files, Yesterday have not added them to the cvs. Sorry
Revision Changes Path
1.1 ws-sandesha/src/org/apache/sandesha/client/ClientHandlerUtil.java
Index: ClientHandlerUtil.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.sandesha.client;
import java.util.Iterator;
import java.util.List;
import org.apache.axis.Handler;
import org.apache.axis.SimpleChain;
import org.apache.axis.components.logger.LogFactory;
import org.apache.commons.logging.Log;
/**
* This class is used to get a handler chain from a given
* array of handler names.
*
* @author Patrick Collins
*/
public class ClientHandlerUtil
{
private static final Log log = LogFactory.getLog(ClientHandlerUtil.class.getName());
public static SimpleChain getHandlerChain(List arr) {
SimpleChain reqHandlers = new SimpleChain();
Iterator it = arr.iterator();
boolean hasReqHandlers = false;
try {
while (it.hasNext()) {
hasReqHandlers = true;
String strClass = (String) it.next();
Class c = Class.forName(strClass);
Handler h = (Handler) c.newInstance();
reqHandlers.addHandler(h);
}
} catch (Exception e) {
log.error(e);
return null;
}
if (hasReqHandlers)
return reqHandlers;
else
return null;
}
}
1.1 ws-sandesha/src/org/apache/sandesha/client/ClientListener.java
Index: ClientListener.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.sandesha.client;
import java.io.IOException;
import java.net.ServerSocket;
import java.util.ArrayList;
import org.apache.axis.SimpleChain;
import org.apache.axis.configuration.SimpleProvider;
import org.apache.axis.description.JavaServiceDesc;
import org.apache.axis.handlers.soap.SOAPService;
import org.apache.axis.transport.http.SimpleAxisServer;
import org.apache.sandesha.Constants;
import org.apache.sandesha.util.PropertyLoader;
import org.apache.sandesha.ws.rm.providers.RMProvider;
/**
* This is the client side listener for Apache Sandesha.
* This will start with the RMService deployed to accept asynchronous responses or
* RM related messages such as Acknowledgements etc..
*
* @author Jaliya Ekanayake
* @author Patrick Collins
*
*/
public class ClientListener
{
public static final int NULL_PORT = -1;
private SimpleAxisServer sas;
private int listenerPort = NULL_PORT;
private boolean started;
public ClientListener( int aPort )
{
listenerPort = aPort;
}
public synchronized void start() throws IOException
{
if( !isStarted() ) {
initSimpleAxisServer();
configureClientService();
configureServerSocket();
startSimpleAxisServer();
}
}
public void stop()
{
getSas().stop();
}
protected void initSimpleAxisServer()
{
setSas( new SimpleAxisServer() );
getSas().setMyConfig( new SimpleProvider() );
}
protected void configureClientService()
{
SimpleChain reqHandlers = getListenerRequestChain();
SimpleChain resHandlers = getListenerResponseChain();
RMProvider rmp = new RMProvider();
rmp.setClient(true);
SOAPService rmService = new SOAPService(reqHandlers, rmp, resHandlers);
JavaServiceDesc desc = new JavaServiceDesc();
rmService.setOption(Constants.ClientProperties.CLASS_NAME,Constants.ClientProperties.RMSERVICE_CLASS);
rmService.setOption(Constants.ClientProperties.ALLOWED_METHODS, Constants.ASTERISK);
desc.setName(Constants.ClientProperties.RMSERVICE);
rmService.setServiceDescription(desc);
((SimpleProvider)getSas().getMyConfig()).deployService(Constants.ClientProperties.RMSERVICE, rmService);
}
protected void configureServerSocket() throws IOException
{
ServerSocket socket = new ServerSocket( getListenerPort() );
getSas().setServerSocket( socket );
}
protected void startSimpleAxisServer()
{
Thread serverThread = new Thread( getSas() );
serverThread.start();
}
protected SimpleChain getListenerRequestChain() {
ArrayList arr = PropertyLoader.getListenerRequestHandlerNames();
return ClientHandlerUtil.getHandlerChain(arr);
}
protected SimpleChain getListenerResponseChain() {
ArrayList arr = PropertyLoader.getListenerResponseHandlerNames();
return ClientHandlerUtil.getHandlerChain(arr);
}
protected SimpleAxisServer getSas()
{
return sas;
}
protected void setSas(SimpleAxisServer aSas)
{
sas = aSas;
}
protected int getListenerPort()
{
if( listenerPort == NULL_PORT )
{
listenerPort = PropertyLoader.getClientSideListenerPort();
}
return listenerPort;
}
protected boolean isStarted()
{
return started;
}
protected void setStarted(boolean aStarted)
{
started = aStarted;
}
}
1.1 ws-sandesha/src/org/apache/sandesha/server/DelegateInvokeHandler.java
Index: DelegateInvokeHandler.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.sandesha.server;
import java.util.Collections;
import java.util.Map;
import org.apache.axis.Handler;
import org.apache.axis.MessageContext;
import org.apache.axis.providers.java.RPCProvider;
import org.apache.sandesha.Constants;
/**
* Use the configured handler or <code>org.apache.axis.providers.java.RPCProvider</code>
* if none was explicitly set to execute the web service invoke.
* @author Patrick Collins
*/
public class DelegateInvokeHandler implements InvokeHandler
{
private Map params = Collections.EMPTY_MAP;
public boolean handleInvoke(MessageContext aMessageContext) throws Exception {
Handler handler = (Handler)Class.forName( getActualInvoker() ).newInstance();
handler.invoke( aMessageContext );
return aMessageContext.getOperation().getMethod().getReturnType() == Void.TYPE;
}
protected String getActualInvoker() {
String invoker = (String)getParms().get( Constants.INVOKER );
if( invoker == null || invoker.length() == 0 )
{
invoker = RPCProvider.class.getName();
}
return invoker;
}
protected Map getParms() {
return params;
}
public void addParams( Map aParams ) {
if( aParams != null ) {
params = aParams;
}
}
}
1.1 ws-sandesha/src/org/apache/sandesha/server/InvokeHandler.java
Index: InvokeHandler.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.sandesha.server;
import java.util.Map;
import org.apache.axis.MessageContext;
/**
* @author Patrick Collins
*/
public interface InvokeHandler
{
public boolean handleInvoke( MessageContext aMessageContext ) throws Exception;
public void addParams( Map aParams );
}
1.1 ws-sandesha/src/org/apache/sandesha/server/InvokeStrategy.java
Index: InvokeStrategy.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.sandesha.server;
import java.util.Map;
/**
* A strategy for handling (asynchronous) web service invocations.
* @author Patrick Collins
*/
public interface InvokeStrategy
{
/**
* Initialize the strategy.
*/
public void start();
public void stop();
public void addParams( Map aParams );
}
1.1 ws-sandesha/src/org/apache/sandesha/server/InvokerFactory.java
Index: InvokerFactory.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.sandesha.server;
import org.apache.sandesha.util.PropertyLoader;
/**
* Provides factory access to two main components of invoke layer.
*
* The <code>RMInvokerStrategy</code> impl defines a strategy for executing,
* most likely in an asynchronous manner, web service invokes. This allows
* custom strategies to be configured for different containers (ie threadpools,
* work managers, etc.).
*
* The <code>InvokeHandler</code> impl actually executes the web service
* invoke.
* @author Patrick Collins
*
*/
public class InvokerFactory
{
// singleton instance
private static final InvokerFactory INSTANCE = new InvokerFactory();
/**
* Getter for factory instance.
*/
public static InvokerFactory getInstance() {
return INSTANCE;
}
/**
* Create the <code>RMInvokerStrategy</code> impl.
*/
public InvokeStrategy createInvokerStrategy() throws Exception {
String strategyClassName = PropertyLoader.getInvokeStrategyClassName();
InvokeStrategy strategy = (InvokeStrategy)Class.forName( strategyClassName ).newInstance();
strategy.addParams( PropertyLoader.getInvokeStrategyParams() );
return strategy;
}
public InvokeHandler createInvokeHandler() throws Exception {
String handlerClassName = PropertyLoader.getInvokeHandlerClassName();
InvokeHandler handler = (InvokeHandler)Class.forName(handlerClassName).newInstance();
handler.addParams( PropertyLoader.getInvokeHandlerParams() );
return handler;
}
}
1.1 ws-sandesha/src/org/apache/sandesha/server/RMInvokerWork.java
Index: RMInvokerWork.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.sandesha.server;
import org.apache.axis.MessageContext;
import org.apache.axis.components.logger.LogFactory;
import org.apache.axis.components.uuid.UUIDGen;
import org.apache.axis.components.uuid.UUIDGenFactory;
import org.apache.axis.message.addressing.AddressingHeaders;
import org.apache.axis.providers.java.JavaProvider;
import org.apache.commons.logging.Log;
import org.apache.sandesha.Constants;
import org.apache.sandesha.IStorageManager;
import org.apache.sandesha.RMMessageContext;
import org.apache.sandesha.util.PropertyLoader;
import org.apache.sandesha.util.RMMessageCreator;
/**
* This is the worker class for the RMInvoker. RMInvoker instantiate several RMInvokerWorkers to
* keep on monitoring SandeshaQueue and invoke the web services. The run method is synchronized
* to get the IN-ORDER message invocation.
*/
public class RMInvokerWork {
private IStorageManager storageManager;
private static final Log log = LogFactory.getLog(RMInvokerWork.class.getName());
private static final UUIDGen uuidGen = UUIDGenFactory.getUUIDGen();
private InvokeHandler invoker = null;
public RMInvokerWork() {
setStorageManager(new ServerStorageManager());
getStorageManager().init();
}
protected boolean doRealInvoke(MessageContext aMessageContext) throws Exception {
if( invoker == null ) {
invoker = InvokerFactory.getInstance().createInvokeHandler();
}
return invoker.handleInvoke( aMessageContext );
}
public void executeInvoke() throws Exception{
Object seq = getStorageManager().getNextSeqToProcess();
if (seq!=null){
synchronized (seq) {
RMMessageContext rmMessageContext = getStorageManager().getNextMessageToProcess(seq);
doWork(rmMessageContext);
}
}
}
/**
* @param storageManager The storageManager to set.
*/
protected void setStorageManager(IStorageManager storageManager) {
this.storageManager = storageManager;
}
/**
* @return Returns the storageManager.
*/
protected IStorageManager getStorageManager() {
return storageManager;
}
protected void doWork(RMMessageContext rmMessageContext) throws Exception {
if (rmMessageContext != null) {
AddressingHeaders addrHeaders = rmMessageContext.getAddressingHeaders();
boolean isVoid = doRealInvoke(rmMessageContext.getMsgContext());
if (!isVoid) {
String oldAction = rmMessageContext.getAddressingHeaders().getAction()
.toString();
rmMessageContext.getAddressingHeaders().setAction(oldAction + Constants.RESPONSE);
if (rmMessageContext.isLastMessage()) {
//Insert Terminate Sequnce.
if (addrHeaders.getReplyTo() != null) {
String replyTo = addrHeaders.getReplyTo().getAddress().toString();
RMMessageContext terminateMsg = RMMessageCreator.createTerminateSeqMsg(rmMessageContext, Constants.SERVER);
terminateMsg.setOutGoingAddress(replyTo);
getStorageManager().insertTerminateSeqMessage(terminateMsg);
} else {
RMInvokerWork.log.error(Constants.ErrorMessages.CANNOT_SEND_THE_TERMINATE_SEQ);
}
}
//Store the message in the response queue. If there is an application
// response then that response is always sent using a new HTTP connection
// and the <replyTo> header is used in this case. This is done by the
// RMSender.
rmMessageContext.setMessageType(Constants.MSG_TYPE_SERVICE_RESPONSE);
boolean hasResponseSeq = getStorageManager().isResponseSequenceExist(rmMessageContext.getSequenceID());
boolean firstMsgOfResponseSeq = false;
if (!(hasResponseSeq && rmMessageContext.getRMHeaders().getSequence()
.getMessageNumber().getMessageNumber() == 1)) {
firstMsgOfResponseSeq = !hasResponseSeq;
}
rmMessageContext.setMsgNumber(getStorageManager().getNextMessageNumber(rmMessageContext.getSequenceID()));
getStorageManager().insertOutgoingMessage(rmMessageContext);
if (firstMsgOfResponseSeq) {
String msgIdStr = Constants.UUID + RMInvokerWork.uuidGen.nextUUID();
RMMessageContext csRMMsgCtx = RMMessageCreator.createCreateSeqMsg(rmMessageContext, Constants.SERVER, msgIdStr, null);
csRMMsgCtx.setOutGoingAddress(rmMessageContext.getAddressingHeaders()
.getReplyTo().getAddress().toString());
csRMMsgCtx.addToMsgIdList(msgIdStr);
csRMMsgCtx.setMessageID(msgIdStr);
getStorageManager().setTemporaryOutSequence(csRMMsgCtx.getSequenceID(),
msgIdStr);
getStorageManager().addCreateSequenceRequest(csRMMsgCtx);
}
}
}
}
}
1.1 ws-sandesha/src/org/apache/sandesha/server/ThreadPoolInvokeStrategy.java
Index: ThreadPoolInvokeStrategy.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.sandesha.server;
import java.util.Collections;
import java.util.Map;
import org.apache.axis.components.logger.LogFactory;
import org.apache.axis.components.threadpool.ThreadPool;
import org.apache.commons.logging.Log;
import org.apache.log4j.spi.LoggerFactory;
import org.apache.sandesha.Constants;
/**
* Use the Axis thread pool for handling web service invokes. Implementations
* of the <code>RMInvokerWork</code> are wrapped in a <code>Runnable</code>
* and passed into the pool.
*
* @author Patrick Collins
*/
public class ThreadPoolInvokeStrategy implements InvokeStrategy {
private static final Log log = LogFactory.getLog(ThreadPoolInvokeStrategy.class.getName());
private Map params = Collections.EMPTY_MAP;
private ThreadPool tPool;
/**
* Creates the axis thread pool.
* @see org.apache.sandesha.server.InvokeStrategy#start()
*/
public void start() {
final int numberOfThreads = getThreadPoolSize();
tPool = new ThreadPool(numberOfThreads);
for (int i = 0; i < numberOfThreads; i++) {
RMRunnableInvoker rmWorker = new RMRunnableInvoker( new RMInvokerWork() );
tPool.addWorker(rmWorker);
}
}
/**
* @see org.apache.sandesha.server.InvokeStrategy#stop()
*/
public void stop() {
tPool.shutdown();
}
/**
* Determine the size of the thread pool. Defaults to value defined
* in <code>Constants.INVOKER_THREADS</code> if none was explicitly set
* via config.
*/
protected int getThreadPoolSize() {
int threadSize = Constants.INVOKER_THREADS;
String value = (String) getParams().get( Constants.THREAD_POOL_SIZE );
if( value != null && value.length() > 0 ) {
try {
threadSize = Integer.parseInt(value);
} catch( NumberFormatException nfe ) {
// eat it
}
}
return threadSize;
}
/**
* @see org.apache.sandesha.server.InvokeStrategy#addParams(java.util.Map)
*/
public void addParams(Map aParams) {
params = aParams;
}
protected Map getParams() {
return params;
}
/**
* A <code>Runnable</code> wrapper for embedding <code>RMInvokerWork</code>
* objects in their own threads.
*/
protected class RMRunnableInvoker implements Runnable
{
private RMInvokerWork rmInvokerWork;
public RMRunnableInvoker( RMInvokerWork aRMInvokerWork ) {
rmInvokerWork = aRMInvokerWork;
}
public void run() {
while (true) {
try {
Thread.sleep(Constants.RMINVOKER_SLEEP_TIME);
getRMInvokerWorker().executeInvoke();
} catch( InterruptedException ex ) {
log.error( ex );
} catch( Exception e ) {
e.printStackTrace();
log.error( e );
}
}
}
/**
* @return Returns the rmInvokerWork.
*/
protected RMInvokerWork getRMInvokerWorker() {
return rmInvokerWork;
}
}
}
1.1 ws-sandesha/test-resources/client-config.wsdd
Index: client-config.wsdd
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!-- ======================================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*
*/
====================================================================================== -->
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<globalConfiguration>
<parameter name="adminPassword" value="admin"/>
<parameter name="disablePrettyXML" value="true"/>
<parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/>
<parameter name="sendXsiTypes" value="true"/>
<parameter name="sendMultiRefs" value="true"/>
<parameter name="sendXMLDeclaration" value="true"/>
</globalConfiguration>
<handler name="RMSender" type="java:org.apache.sandesha.client.RMSender"/>
<transport name="java" pivot="java:org.apache.axis.transport.java.JavaSender"/>
<transport name="http" pivot="java:org.apache.axis.transport.http.HTTPSender"/>
<transport name="local" pivot="java:org.apache.axis.transport.local.LocalSender"/>
<transport name="RMTransport" pivot="RMSender"/>
</deployment>
---------------------------------------------------------------------
To unsubscribe, e-mail: sandesha-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: sandesha-dev-help@ws.apache.org