You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2005/12/16 18:18:08 UTC
svn commit: r357187 [2/25] - in
/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2: ./
addressing/ client/ client/async/ context/ deployment/ deployment/listener/
deployment/repository/util/ deployment/scheduler/ deployment/util/
descripti...
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/Call.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/Call.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/Call.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/Call.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
/*
- * Copyright 2004,2005 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.
- */
+* Copyright 2004,2005 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.axis2.client;
@@ -37,20 +38,26 @@
* class to work with INOUT MEP.
*/
public class Call extends InOutMEPClient {
-
protected AxisOperation axisOperationTemplate;
protected MessageContext lastResponseMsgCtx;
/**
* @throws AxisFault
*/
-
public Call() throws AxisFault {
super(null);
assumeServiceContext(null);
}
/**
+ * @param service
+ * @see InOutMEPClient constructer
+ */
+ public Call(ServiceContext service) {
+ super(service);
+ }
+
+ /**
* This is used to create call object with client home.
*
* @param clientHome
@@ -61,12 +68,50 @@
assumeServiceContext(clientHome);
}
+ protected void assumeServiceContext(String clientHome) throws AxisFault {
+ super.assumeServiceContext(clientHome);
+
+ AxisService axisService = serviceContext.getAxisService();
+
+ axisOperationTemplate = new OutInAxisOperation();
+ axisOperationTemplate.setName(new QName("TemplateOperation"));
+
+ AxisConfiguration axisConfiguration =
+ serviceContext.getConfigurationContext().getAxisConfiguration();
+ PhasesInfo info = axisConfiguration.getPhasesInfo();
+
+ // to set the operation flows
+ if (info != null) {
+ info.setOperationPhases(axisOperationTemplate);
+ }
+
+ axisService.addOperation(axisOperationTemplate);
+ }
+
/**
- * @param service
- * @see InOutMEPClient constructer
+ * Creates an operation description if it is null and copies the flows from
+ * the template operation.
+ *
+ * @param opDesc
+ * @param axisOp
*/
- public Call(ServiceContext service) {
- super(service);
+ protected AxisOperation createOpDescAndFillInFlowInformation(AxisOperation opDesc,
+ String axisOp, int mepURL)
+ throws AxisFault {
+ if (opDesc == null) {
+
+ // if the operation is not already defined we will copy the
+ // created Phases from the template operation to this Operation
+ opDesc = AxisOperationFactory.getAxisOperation(mepURL);
+ opDesc.setName(new QName(axisOp));
+ opDesc.setRemainingPhasesInFlow(axisOperationTemplate.getRemainingPhasesInFlow());
+ opDesc.setPhasesOutFlow(axisOperationTemplate.getPhasesOutFlow());
+ opDesc.setPhasesInFaultFlow(axisOperationTemplate.getPhasesInFaultFlow());
+ opDesc.setPhasesOutFaultFlow(axisOperationTemplate.getPhasesOutFaultFlow());
+ serviceContext.getAxisService().addOperation(opDesc);
+ }
+
+ return opDesc;
}
/**
@@ -78,18 +123,19 @@
* @return
* @throws AxisFault
*/
+ public OMElement invokeBlocking(String axisop, OMElement toSend) throws AxisFault {
+ AxisOperation opDesc = serviceContext.getAxisService().getOperation(new QName(axisop));
- public OMElement invokeBlocking(String axisop, OMElement toSend)
- throws AxisFault {
-
- AxisOperation opDesc =
- serviceContext.getAxisService().getOperation(new QName(axisop));
- opDesc = createOpDescAndFillInFlowInformation(opDesc, axisop, WSDLConstants.MEP_CONSTANT_OUT_IN);
+ opDesc = createOpDescAndFillInFlowInformation(opDesc, axisop,
+ WSDLConstants.MEP_CONSTANT_OUT_IN);
opDesc.setParent(serviceContext.getAxisService());
+
MessageContext msgctx = prepareTheSOAPEnvelope(toSend);
this.lastResponseMsgCtx = super.invokeBlocking(opDesc, msgctx);
+
SOAPEnvelope resEnvelope = lastResponseMsgCtx.getEnvelope();
+
return resEnvelope.getBody().getFirstElement();
}
@@ -101,20 +147,21 @@
* @return
* @throws AxisFault
*/
- public SOAPEnvelope invokeBlocking(String axisop, SOAPEnvelope envelope)
- throws AxisFault {
+ public SOAPEnvelope invokeBlocking(String axisop, SOAPEnvelope envelope) throws AxisFault {
+ AxisOperation opDesc = serviceContext.getAxisService().getOperation(new QName(axisop));
- AxisOperation opDesc =
- serviceContext.getAxisService().getOperation(new QName(axisop));
- opDesc = createOpDescAndFillInFlowInformation(opDesc, axisop, WSDLConstants.MEP_CONSTANT_OUT_IN);
+ opDesc = createOpDescAndFillInFlowInformation(opDesc, axisop,
+ WSDLConstants.MEP_CONSTANT_OUT_IN);
MessageContext msgctx = new MessageContext(serviceContext.getConfigurationContext());
- if (envelope == null || envelope.getBody() == null) {
+
+ if ((envelope == null) || (envelope.getBody() == null)) {
throw new AxisFault("SOAP envelope or SOAP Body can not be null");
}
- msgctx.setEnvelope(envelope);
+ msgctx.setEnvelope(envelope);
this.lastResponseMsgCtx = super.invokeBlocking(opDesc, msgctx);
+
return lastResponseMsgCtx.getEnvelope();
}
@@ -126,17 +173,16 @@
* @param callback
* @throws AxisFault
*/
-
- public void invokeNonBlocking(
- String axisop,
- OMElement toSend,
- Callback callback)
+ public void invokeNonBlocking(String axisop, OMElement toSend, Callback callback)
throws AxisFault {
- AxisOperation opDesc =
- serviceContext.getAxisService().getOperation(new QName(axisop));
- opDesc = createOpDescAndFillInFlowInformation(opDesc, axisop, WSDLConstants.MEP_CONSTANT_OUT_IN);
+ AxisOperation opDesc = serviceContext.getAxisService().getOperation(new QName(axisop));
+
+ opDesc = createOpDescAndFillInFlowInformation(opDesc, axisop,
+ WSDLConstants.MEP_CONSTANT_OUT_IN);
+
MessageContext msgctx = prepareTheSOAPEnvelope(toSend);
- //call the underline implementation
+
+ // call the underline implementation
super.invokeNonBlocking(opDesc, msgctx, callback);
}
@@ -148,68 +194,23 @@
* @param callback
* @throws AxisFault
*/
-
- public void invokeNonBlocking(
- String axisop,
- SOAPEnvelope envelope,
- Callback callback)
+ public void invokeNonBlocking(String axisop, SOAPEnvelope envelope, Callback callback)
throws AxisFault {
- AxisOperation opDesc =
- serviceContext.getAxisService().getOperation(new QName(axisop));
- opDesc = createOpDescAndFillInFlowInformation(opDesc, axisop, WSDLConstants.MEP_CONSTANT_OUT_IN);
+ AxisOperation opDesc = serviceContext.getAxisService().getOperation(new QName(axisop));
- MessageContext msgctx = new MessageContext(serviceContext.getConfigurationContext());
- if (envelope == null || envelope.getBody() == null) {
- throw new AxisFault("SOAP envelope or SOAP Body can not be null");
- }
- msgctx.setEnvelope(envelope);
- //call the underline implementation
- super.invokeNonBlocking(opDesc, msgctx, callback);
- }
+ opDesc = createOpDescAndFillInFlowInformation(opDesc, axisop,
+ WSDLConstants.MEP_CONSTANT_OUT_IN);
- protected void assumeServiceContext(String clientHome)
- throws AxisFault {
-
- super.assumeServiceContext(clientHome);
- AxisService axisService = serviceContext.getAxisService();
- axisOperationTemplate = new OutInAxisOperation();
- axisOperationTemplate.setName(new QName("TemplateOperation"));
+ MessageContext msgctx = new MessageContext(serviceContext.getConfigurationContext());
- AxisConfiguration axisConfiguration = serviceContext.getConfigurationContext().getAxisConfiguration();
- PhasesInfo info = axisConfiguration.getPhasesInfo();
- //to set the operation flows
- if (info != null) {
- info.setOperationPhases(axisOperationTemplate);
+ if ((envelope == null) || (envelope.getBody() == null)) {
+ throw new AxisFault("SOAP envelope or SOAP Body can not be null");
}
- axisService.addOperation(axisOperationTemplate);
- }
- /**
- * Creates an operation description if it is null and copies the flows from
- * the template operation.
- *
- * @param opDesc
- * @param axisOp
- */
- protected AxisOperation createOpDescAndFillInFlowInformation(
- AxisOperation opDesc,
- String axisOp, int mepURL) throws AxisFault {
- if (opDesc == null) {
- //if the operation is not already defined we will copy the
- //created Phases from the template operation to this Operation
+ msgctx.setEnvelope(envelope);
- opDesc = AxisOperationFactory.getAxisOperation(mepURL);
- opDesc.setName(new QName(axisOp));
- opDesc.setRemainingPhasesInFlow(
- axisOperationTemplate.getRemainingPhasesInFlow());
- opDesc.setPhasesOutFlow(axisOperationTemplate.getPhasesOutFlow());
- opDesc.setPhasesInFaultFlow(
- axisOperationTemplate.getPhasesInFaultFlow());
- opDesc.setPhasesOutFaultFlow(
- axisOperationTemplate.getPhasesOutFaultFlow());
- serviceContext.getAxisService().addOperation(opDesc);
- }
- return opDesc;
+ // call the underline implementation
+ super.invokeNonBlocking(opDesc, msgctx, callback);
}
/**
@@ -220,5 +221,4 @@
public MessageContext getResponseMessageContext() {
return lastResponseMsgCtx;
}
-
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/InOnlyMEPClient.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/InOnlyMEPClient.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/InOnlyMEPClient.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/InOnlyMEPClient.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
/*
- * Copyright 2004,2005 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.
- */
+* Copyright 2004,2005 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.axis2.client;
@@ -31,11 +32,14 @@
* This class handles In-Only (fire and forget) MEP
*/
public class InOnlyMEPClient extends MEPClient {
-
public InOnlyMEPClient(ServiceContext service) {
super(service, WSDLConstants.MEP_URI_IN_ONLY);
}
+ protected void configureTransportInformation(MessageContext msgCtx) throws AxisFault {
+ inferTransportOutDescription(msgCtx);
+ }
+
/**
* Sends the SOAP Message and forgets about it. This is one way
*
@@ -45,31 +49,33 @@
*/
public void send(AxisOperation axisop, final MessageContext msgctx) throws AxisFault {
prepareInvocation(axisop, msgctx);
+
if (msgctx.getMessageID() == null) {
String messageID = String.valueOf("uuid:" + UUIDGenerator.getUUID());
+
msgctx.setMessageID(messageID);
}
+
msgctx.setServiceContext(serviceContext);
- //if the transport to use for sending is not specified, try to find it from the URL
+ // if the transport to use for sending is not specified, try to find it from the URL
TransportOutDescription senderTransport = clientOptions.getSenderTransport();
+
if (senderTransport == null) {
- senderTransport =
- inferTransport(msgctx.getTo());
+ senderTransport = inferTransport(msgctx.getTo());
}
+
msgctx.setTransportOut(senderTransport);
- //initialize and set the Operation Context
+ // initialize and set the Operation Context
ConfigurationContext sysContext = serviceContext.getConfigurationContext();
OperationContext operationContext = axisop.findOperationContext(msgctx, serviceContext);
+
msgctx.setOperationContext(operationContext);
operationContext.setProperties(clientOptions.getProperties());
AxisEngine engine = new AxisEngine(sysContext);
- engine.send(msgctx);
- }
- protected void configureTransportInformation(MessageContext msgCtx) throws AxisFault {
- inferTransportOutDescription(msgCtx);
+ engine.send(msgctx);
}
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/InOutMEPClient.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/InOutMEPClient.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/InOutMEPClient.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/InOutMEPClient.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
/*
- * Copyright 2004,2005 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.
- */
+* Copyright 2004,2005 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.axis2.client;
@@ -48,7 +49,6 @@
*/
public class InOutMEPClient extends MEPClient {
-
/**
* This is used for the receiving the asynchronous messages.
*/
@@ -76,13 +76,87 @@
*
* @param serviceContext
*/
-
public InOutMEPClient(ServiceContext serviceContext) {
super(serviceContext, WSDLConstants.MEP_URI_OUT_IN);
- //service context has the engine context set in to it !
+
+ // service context has the engine context set in to it !
callbackReceiver = new CallbackReceiver();
}
+ /**
+ * Checks if the transports are identified correctly.
+ *
+ * @param msgctx
+ * @throws AxisFault
+ */
+ private void checkTransport(MessageContext msgctx) throws AxisFault {
+ if (clientOptions.getSenderTransport() == null) {
+ clientOptions.setSenderTransport(inferTransport(msgctx.getTo()));
+ }
+
+ if (clientOptions.isUseSeparateListener()) {
+ if (clientOptions.getListenerTransport() == null) {
+ clientOptions.setListenerTransport(
+ serviceContext.getConfigurationContext().getAxisConfiguration().getTransportIn(
+ clientOptions.getSenderTransport().getName()));
+ }
+ }
+
+ if (msgctx.getTransportIn() == null) {
+ msgctx.setTransportIn(clientOptions.getListenerTransport());
+ }
+
+ if (msgctx.getTransportOut() == null) {
+ msgctx.setTransportOut(clientOptions.getSenderTransport());
+ }
+ }
+
+ /**
+ * Closes the call initiated to the Transport Listeners. If there are multiple
+ * requests sent, the call should be closed only when all are are done.
+ */
+ public void close() throws AxisFault {
+ if (clientOptions.isUseSeparateListener()) {
+ ListenerManager.stop(serviceContext.getConfigurationContext(),
+ clientOptions.getListenerTransport().getName().getLocalPart());
+ }
+ }
+
+ protected void configureTransportInformation(MessageContext msgCtx) throws AxisFault {
+ AxisConfiguration axisConfig =
+ this.serviceContext.getConfigurationContext().getAxisConfiguration();
+ String listenerTransportProtocol = clientOptions.getListenerTransportProtocol();
+
+ if (axisConfig != null) {
+ if (clientOptions.isUseSeparateListener()) {
+ if ((listenerTransportProtocol != null) && !"".equals(listenerTransportProtocol)) {
+ TransportInDescription transportIn =
+ axisConfig.getTransportIn(new QName(listenerTransportProtocol));
+
+ if (transportIn == null) {
+ throw new AxisFault(Messages.getMessage("unknownTransport",
+ listenerTransportProtocol));
+ }
+
+ clientOptions.setListenerTransport(transportIn);
+ }
+ }
+
+ inferTransportOutDescription(msgCtx);
+ }
+
+ if (clientOptions.isUseSeparateListener()) {
+
+ // if separate transport is used, start the required listeners
+ if (!serviceContext.getConfigurationContext().getAxisConfiguration().isEngaged(
+ new QName(Constants.MODULE_ADDRESSING))) {
+ throw new AxisFault(Messages.getMessage("2channelNeedAddressing"));
+ }
+
+ ListenerManager.makeSureStarted(clientOptions.getListenerTransportProtocol(),
+ serviceContext.getConfigurationContext());
+ }
+ }
/**
* This method is used to make blocking calls. This is independent of the transport.
@@ -93,25 +167,27 @@
* <li>send request via an email smtp and receive the response via an email.</li>
* </ol>
*/
-
- public MessageContext invokeBlocking(AxisOperation axisop,
- final MessageContext msgctx)
+ public MessageContext invokeBlocking(AxisOperation axisop, final MessageContext msgctx)
throws AxisFault {
// The message ID is sent all the time
String messageID = String.valueOf("uuid:" + UUIDGenerator.getUUID());
+
msgctx.setMessageID(messageID);
+
//
if (clientOptions.isUseSeparateListener()) {
- //This mean doing a Request-Response invocation using two channel. If the
- //transport is two way transport (e.g. http) Only one channel is used (e.g. in http cases
- //202 OK is sent to say no repsone avalible). Axis2 get blocked return when the response is avalible.
-
+ // This mean doing a Request-Response invocation using two channel. If the
+ // transport is two way transport (e.g. http) Only one channel is used (e.g. in http cases
+ // 202 OK is sent to say no repsone avalible). Axis2 get blocked return when the response is avalible.
SyncCallBack callback = new SyncCallBack();
- //this method call two channel non blocking method to do the work and wait on the callbck
+
+ // this method call two channel non blocking method to do the work and wait on the callbck
invokeNonBlocking(axisop, msgctx, callback);
+
long timeout = clientOptions.getTimeOutInMilliSeconds();
+
if (timeout < 0) {
while (!callback.isComplete()) {
try {
@@ -122,8 +198,10 @@
}
} else {
long index = timeout / 100;
+
while (!callback.isComplete()) {
- //wait till the reponse arrives
+
+ // wait till the reponse arrives
if (index-- >= 0) {
try {
Thread.sleep(100);
@@ -135,15 +213,18 @@
}
}
}
- //process the resule of the invocation
+
+ // process the resule of the invocation
if (callback.envelope != null) {
MessageContext resMsgctx =
new MessageContext(serviceContext.getConfigurationContext());
+
resMsgctx.setEnvelope(callback.envelope);
+
return resMsgctx;
} else {
if (callback.error instanceof AxisFault) {
- throw (AxisFault) callback.error;
+ throw(AxisFault) callback.error;
} else {
throw new AxisFault(callback.error);
}
@@ -151,41 +232,54 @@
} else {
msgctx.setServiceContext(serviceContext);
prepareInvocation(axisop, msgctx);
- //This is the Usual Request-Response Sync implemetation
+
+ // This is the Usual Request-Response Sync implemetation
ConfigurationContext syscontext = serviceContext.getConfigurationContext();
- msgctx.setConfigurationContext(syscontext);
+ msgctx.setConfigurationContext(syscontext);
checkTransport(msgctx);
OperationContext operationContext = new OperationContext(axisop, serviceContext);
+
axisop.registerOperationContext(msgctx, operationContext);
operationContext.setProperties(clientOptions.getProperties());
- //Send the SOAP Message and receive a response
- MessageContext response =
- send(msgctx, clientOptions.getListenerTransport());
+ // Send the SOAP Message and receive a response
+ MessageContext response = send(msgctx, clientOptions.getListenerTransport());
- //check for a fault and return the result
+ // check for a fault and return the result
SOAPEnvelope resenvelope = response.getEnvelope();
+
if (resenvelope.getBody().hasFault()) {
SOAPFault soapFault = resenvelope.getBody().getFault();
Exception ex = soapFault.getException();
if (clientOptions.isExceptionToBeThrownOnSOAPFault()) {
- //does the SOAPFault has a detail element for Excpetion
+
+ // does the SOAPFault has a detail element for Excpetion
if (ex != null) {
throw new AxisFault(ex);
} else {
- //if detail element not present create a new Exception from the detail
+
+ // if detail element not present create a new Exception from the detail
String message = "";
- message = message + "Code =" + soapFault.getCode() == null ? "" :
- soapFault.getCode().getValue() == null ? "" : soapFault.getCode().getValue().getText();
- message = message + "Reason =" + soapFault.getReason() == null ? "" :
- soapFault.getReason().getSOAPText() == null ? "" : soapFault.getReason().getSOAPText().getText();
+
+ message = (message + "Code =" + soapFault.getCode() == null)
+ ? ""
+ : (soapFault.getCode().getValue() == null)
+ ? ""
+ : soapFault.getCode().getValue().getText();
+ message = (message + "Reason =" + soapFault.getReason() == null)
+ ? ""
+ : (soapFault.getReason().getSOAPText() == null)
+ ? ""
+ : soapFault.getReason().getSOAPText().getText();
+
throw new AxisFault(message);
}
}
}
+
return response;
}
}
@@ -199,37 +293,38 @@
* <li>send request via an email smtp and receive the response via an email.</li>
* </ol>
*/
- public void invokeNonBlocking(final AxisOperation axisop,
- final MessageContext msgctx,
+ public void invokeNonBlocking(final AxisOperation axisop, final MessageContext msgctx,
final Callback callback)
throws AxisFault {
prepareInvocation(axisop, msgctx);
try {
- final ConfigurationContext syscontext =
- serviceContext.getConfigurationContext();
-
+ final ConfigurationContext syscontext = serviceContext.getConfigurationContext();
AxisEngine engine = new AxisEngine(syscontext);
+
checkTransport(msgctx);
- //Use message id all the time!
+
+ // Use message id all the time!
String messageID = String.valueOf("uuid:" + UUIDGenerator.getUUID());
+
msgctx.setMessageID(messageID);
- ////
+
+ // //
if (clientOptions.isUseSeparateListener()) {
- //the invocation happen via a separate Channel, so we should set up the
- //information need to correlated the response message and invoke the call back
+ // the invocation happen via a separate Channel, so we should set up the
+ // information need to correlated the response message and invoke the call back
axisop.setMessageReceiver(callbackReceiver);
callbackReceiver.addCallback(messageID, callback);
- //set the replyto such that the response will arrive at the transport listener started
+ // set the replyto such that the response will arrive at the transport listener started
// Note that this will only change the replyTo Address property in the replyTo EPR
- EndpointReference replyToFromTransport = ListenerManager.replyToEPR(
- serviceContext.getConfigurationContext(),
- serviceContext.getAxisService().getName()
- + "/"
- + axisop.getName().getLocalPart(),
- clientOptions.getListenerTransport().getName().getLocalPart());
+ EndpointReference replyToFromTransport =
+ ListenerManager
+ .replyToEPR(serviceContext.getConfigurationContext(),
+ serviceContext.getAxisService().getName() + "/"
+ + axisop.getName().getLocalPart(), clientOptions
+ .getListenerTransport().getName().getLocalPart());
if (msgctx.getReplyTo() == null) {
msgctx.setReplyTo(replyToFromTransport);
@@ -237,115 +332,73 @@
msgctx.getReplyTo().setAddress(replyToFromTransport.getAddress());
}
- //create and set the Operation context
+ // create and set the Operation context
msgctx.setOperationContext(axisop.findOperationContext(msgctx, serviceContext));
msgctx.setServiceContext(serviceContext);
msgctx.getOperationContext().setProperties(clientOptions.getProperties());
- //send the message
+ // send the message
engine.send(msgctx);
} else {
+
// here a bloking invocation happens in a new thread, so the
// progamming model is non blocking
OperationContext opcontxt = new OperationContext(axisop, serviceContext);
+
msgctx.setOperationContext(opcontxt);
msgctx.setServiceContext(serviceContext);
opcontxt.setProperties(clientOptions.getProperties());
- serviceContext.getConfigurationContext().getThreadPool().execute(new NonBlockingInvocationWorker(callback, axisop, msgctx));
+ serviceContext.getConfigurationContext().getThreadPool().execute(
+ new NonBlockingInvocationWorker(callback, axisop, msgctx));
}
-
} catch (OMException e) {
throw new AxisFault(e.getMessage(), e);
} catch (Exception e) {
throw new AxisFault(e.getMessage(), e);
}
-
- }
-
-
-
- protected void configureTransportInformation(MessageContext msgCtx) throws AxisFault {
- AxisConfiguration axisConfig = this.serviceContext.getConfigurationContext().getAxisConfiguration();
- String listenerTransportProtocol = clientOptions.getListenerTransportProtocol();
- if (axisConfig != null) {
- if (clientOptions.isUseSeparateListener()) {
- if (listenerTransportProtocol != null && !"".equals(listenerTransportProtocol)) {
- TransportInDescription transportIn = axisConfig.getTransportIn(new QName(listenerTransportProtocol));
- if (transportIn == null) {
- throw new AxisFault(Messages.getMessage("unknownTransport", listenerTransportProtocol));
- }
- clientOptions.setListenerTransport(transportIn);
- }
- }
-
- inferTransportOutDescription(msgCtx);
- }
-
- if (clientOptions.isUseSeparateListener()) {
- //if separate transport is used, start the required listeners
- if (!serviceContext
- .getConfigurationContext()
- .getAxisConfiguration()
- .isEngaged(new QName(Constants.MODULE_ADDRESSING))) {
- throw new AxisFault(Messages.getMessage("2channelNeedAddressing"));
- }
- ListenerManager.makeSureStarted(clientOptions.getListenerTransportProtocol(),
- serviceContext.getConfigurationContext());
- }
}
-
/**
- * Checks if the transports are identified correctly.
+ * Sends the message using a two way transport and waits for a response
*
* @param msgctx
+ * @param transportIn
+ * @return
* @throws AxisFault
*/
- private void checkTransport(MessageContext msgctx) throws AxisFault {
- if (clientOptions.getSenderTransport() == null) {
- clientOptions.setSenderTransport(inferTransport(msgctx.getTo()));
- }
- if (clientOptions.isUseSeparateListener()) {
- if (clientOptions.getListenerTransport() == null) {
- clientOptions.setListenerTransport(serviceContext.getConfigurationContext()
- .getAxisConfiguration()
- .getTransportIn(clientOptions.getSenderTransport().getName()));
- }
- }
+ public MessageContext send(MessageContext msgctx, TransportInDescription transportIn)
+ throws AxisFault {
+ AxisEngine engine = new AxisEngine(msgctx.getConfigurationContext());
- if (msgctx.getTransportIn() == null) {
- msgctx.setTransportIn(clientOptions.getListenerTransport());
- }
- if (msgctx.getTransportOut() == null) {
- msgctx.setTransportOut(clientOptions.getSenderTransport());
- }
+ engine.send(msgctx);
- }
+ // create the response
+ MessageContext response = new MessageContext(msgctx.getConfigurationContext(),
+ msgctx.getSessionContext(), msgctx.getTransportIn(),
+ msgctx.getTransportOut());
- /**
- * This class acts as a callback that allows users to wait on the result.
- */
- public class SyncCallBack extends Callback {
- private SOAPEnvelope envelope;
- private Exception error;
+ response.setProperty(MessageContext.TRANSPORT_IN,
+ msgctx.getProperty(MessageContext.TRANSPORT_IN));
+ msgctx.getAxisOperation().registerOperationContext(response, msgctx.getOperationContext());
+ response.setServerSide(false);
+ response.setServiceContext(msgctx.getServiceContext());
+ response.setServiceGroupContext(msgctx.getServiceGroupContext());
- public void onComplete(AsyncResult result) {
- this.envelope = result.getResponseEnvelope();
- }
+ // If request is REST we assume the response is REST, so set the variable
+ response.setDoingREST(msgctx.isDoingREST());
- public void reportError(Exception e) {
- error = e;
- }
- }
+ SOAPEnvelope resenvelope = TransportUtils.createSOAPMessage(response,
+ msgctx.getEnvelope().getNamespace().getName());
- /**
- * Closes the call initiated to the Transport Listeners. If there are multiple
- * requests sent, the call should be closed only when all are are done.
- */
- public void close() throws AxisFault {
- if(clientOptions.isUseSeparateListener()) {
- ListenerManager.stop(serviceContext.getConfigurationContext(), clientOptions.getListenerTransport().getName().getLocalPart());
+ if (resenvelope != null) {
+ response.setEnvelope(resenvelope);
+ engine = new AxisEngine(msgctx.getConfigurationContext());
+ engine.receive(response);
+ } else {
+ throw new AxisFault(Messages.getMessage("blockingInvocationExpectsResponse"));
}
+
+ return response;
}
/**
@@ -353,13 +406,11 @@
* two way transport.
*/
private class NonBlockingInvocationWorker implements Runnable {
-
- private Callback callback;
private AxisOperation axisop;
+ private Callback callback;
private MessageContext msgctx;
- public NonBlockingInvocationWorker(Callback callback,
- AxisOperation axisop,
+ public NonBlockingInvocationWorker(Callback callback, AxisOperation axisop,
MessageContext msgctx) {
this.callback = callback;
this.axisop = axisop;
@@ -368,22 +419,27 @@
public void run() {
try {
- //send the request and wait for reponse
- MessageContext response =
- send(msgctx, clientOptions.getListenerTransport());
- //call the callback
+
+ // send the request and wait for reponse
+ MessageContext response = send(msgctx, clientOptions.getListenerTransport());
+
+ // call the callback
SOAPEnvelope resenvelope = response.getEnvelope();
SOAPBody body = resenvelope.getBody();
+
if (body.hasFault()) {
Exception ex = body.getFault().getException();
+
if (ex != null) {
callback.reportError(ex);
} else {
- //todo this needs to be fixed
+
+ // todo this needs to be fixed
callback.reportError(new Exception(body.getFault().getReason().getText()));
}
} else {
AsyncResult asyncResult = new AsyncResult(response);
+
callback.onComplete(asyncResult);
}
@@ -394,45 +450,20 @@
}
}
+
/**
- * Sends the message using a two way transport and waits for a response
- *
- * @param msgctx
- * @param transportIn
- * @return
- * @throws AxisFault
+ * This class acts as a callback that allows users to wait on the result.
*/
- public MessageContext send(MessageContext msgctx,
- TransportInDescription transportIn) throws AxisFault {
-
- AxisEngine engine = new AxisEngine(msgctx.getConfigurationContext());
- engine.send(msgctx);
-
- //create the response
- MessageContext response =
- new MessageContext(msgctx.getConfigurationContext(),
- msgctx.getSessionContext(),
- msgctx.getTransportIn(),
- msgctx.getTransportOut());
- response.setProperty(MessageContext.TRANSPORT_IN,
- msgctx.getProperty(MessageContext.TRANSPORT_IN));
- msgctx.getAxisOperation().registerOperationContext(response, msgctx.getOperationContext());
- response.setServerSide(false);
- response.setServiceContext(msgctx.getServiceContext());
- response.setServiceGroupContext(msgctx.getServiceGroupContext());
-
- //If request is REST we assume the response is REST, so set the variable
- response.setDoingREST(msgctx.isDoingREST());
+ public class SyncCallBack extends Callback {
+ private SOAPEnvelope envelope;
+ private Exception error;
- SOAPEnvelope resenvelope = TransportUtils.createSOAPMessage(response, msgctx.getEnvelope().getNamespace().getName());
+ public void onComplete(AsyncResult result) {
+ this.envelope = result.getResponseEnvelope();
+ }
- if (resenvelope != null) {
- response.setEnvelope(resenvelope);
- engine = new AxisEngine(msgctx.getConfigurationContext());
- engine.receive(response);
- } else {
- throw new AxisFault(Messages.getMessage("blockingInvocationExpectsResponse"));
+ public void reportError(Exception e) {
+ error = e;
}
- return response;
}
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/ListenerManager.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/ListenerManager.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/ListenerManager.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/ListenerManager.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
/*
- * Copyright 2004,2005 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.
- */
+* Copyright 2004,2005 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.axis2.client;
@@ -34,7 +35,6 @@
* re-architectured. It allows the client to initialize only one ConfigurationContext in a given JVM.
*/
public class ListenerManager {
-
public static int port = 6059;
public static Map configurationContextMap = new HashMap();
@@ -46,47 +46,53 @@
* @throws AxisFault
*/
public static synchronized void makeSureStarted(String transport,
- ConfigurationContext configurationContext)
+ ConfigurationContext configurationContext)
throws AxisFault {
+
// If this config context is in the map, that means we already have a listener for that
// config context
HashMap listeners = (HashMap) configurationContextMap.get(configurationContext);
+
if (listeners == null) {
listeners = new HashMap();
configurationContextMap.put(configurationContext, listeners);
} else {
TransportListenerState tsState = (TransportListenerState) listeners.get(transport);
+
if (tsState != null) {
tsState.waitingCalls++;
+
return;
}
}
- //means this transport not yet started, start the transport
+ // means this transport not yet started, start the transport
TransportInDescription tranportIn =
- configurationContext.getAxisConfiguration().getTransportIn(
- new QName(transport));
+ configurationContext.getAxisConfiguration().getTransportIn(new QName(transport));
TransportListener listener = tranportIn.getReceiver();
+
listener.start();
+
TransportListenerState tsState = new TransportListenerState(listener);
- listeners.put(transport, tsState);
+ listeners.put(transport, tsState);
tsState.waitingCalls++;
}
- public static synchronized void stop(ConfigurationContext configurationContext, String transport) throws AxisFault {
- HashMap listeners = (HashMap) configurationContextMap.get(configurationContext);
+ /**
+ * Controls the number of server sockets kept open.
+ */
+ public static ServerSocket openSocket(int port) throws AxisFault {
+ for (int i = 0; i < 5; i++) {
+ try {
+ return new ServerSocket(port + i);
+ } catch (IOException e) {
- if (listeners != null) {
- TransportListenerState tsState = (TransportListenerState) listeners.get(transport);
- if (tsState != null) {
- tsState.waitingCalls--;
- if (tsState.waitingCalls == 0) {
- tsState.listener.stop();
- listeners.remove(transport);
- }
+ // What I'm gonna do here. Try again.
}
}
+
+ throw new AxisFault(Messages.getMessage("failedToOpenSocket"));
}
/**
@@ -98,21 +104,41 @@
* @throws AxisFault
*/
public static EndpointReference replyToEPR(ConfigurationContext configurationContext,
- String serviceName,
- String transport)
+ String serviceName, String transport)
throws AxisFault {
HashMap listeners = (HashMap) configurationContextMap.get(configurationContext);
+
if (listeners != null) {
- TransportListenerState tsState = (TransportListenerState) listeners.get(
- transport);
+ TransportListenerState tsState = (TransportListenerState) listeners.get(transport);
+
if (tsState != null) {
return tsState.listener.getReplyToEPR(serviceName);
} else {
throw new AxisFault(Messages.getMessage("replyNeedStarting", transport));
}
} else {
- throw new AxisFault("Can not find listeners for " + transport + " for the given config" +
- " context " + configurationContext + ". So can not provide a replyTo epr here. ");
+ throw new AxisFault("Can not find listeners for " + transport + " for the given config"
+ + " context " + configurationContext
+ + ". So can not provide a replyTo epr here. ");
+ }
+ }
+
+ public static synchronized void stop(ConfigurationContext configurationContext,
+ String transport)
+ throws AxisFault {
+ HashMap listeners = (HashMap) configurationContextMap.get(configurationContext);
+
+ if (listeners != null) {
+ TransportListenerState tsState = (TransportListenerState) listeners.get(transport);
+
+ if (tsState != null) {
+ tsState.waitingCalls--;
+
+ if (tsState.waitingCalls == 0) {
+ tsState.listener.stop();
+ listeners.remove(transport);
+ }
+ }
}
}
@@ -120,26 +146,11 @@
* This class keeps information about the listener for a given transport.
*/
public static class TransportListenerState {
- public TransportListenerState(TransportListener listener) {
- this.listener = listener;
- }
-
public int waitingCalls = 0;
public TransportListener listener;
- }
- /**
- * Controls the number of server sockets kept open.
- */
- public static ServerSocket openSocket(int port) throws AxisFault {
- for (int i = 0; i < 5; i++) {
- try {
- return new ServerSocket(port + i);
- } catch (IOException e) {
- // What I'm gonna do here. Try again.
- }
+ public TransportListenerState(TransportListener listener) {
+ this.listener = listener;
}
- throw new AxisFault(Messages.getMessage("failedToOpenSocket"));
}
-
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/MEPClient.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/MEPClient.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/MEPClient.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/MEPClient.java Fri Dec 16 09:13:57 2005
@@ -1,25 +1,30 @@
/*
- * Copyright 2004,2005 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.
- */
+* Copyright 2004,2005 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.axis2.client;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.context.*;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.context.ServiceGroupContext;
import org.apache.axis2.description.AxisOperation;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.TransportOutDescription;
@@ -27,7 +32,11 @@
import org.apache.axis2.i18n.Messages;
import org.apache.axis2.om.OMAbstractFactory;
import org.apache.axis2.om.OMElement;
-import org.apache.axis2.soap.*;
+import org.apache.axis2.soap.SOAP11Constants;
+import org.apache.axis2.soap.SOAP12Constants;
+import org.apache.axis2.soap.SOAPEnvelope;
+import org.apache.axis2.soap.SOAPFactory;
+import org.apache.axis2.soap.SOAPHeader;
import org.apache.axis2.util.UUIDGenerator;
import javax.xml.namespace.QName;
@@ -38,18 +47,15 @@
* This is the super class for all the MEPClients.
*/
public abstract class MEPClient {
- ServiceContext serviceContext;
-
- protected final String mep;
-
- private List soapHeaderList;
+ private static final String ANONYMOUS_SERVICE = "AnonymousService";
/**
* Client will pass all the parameters to this invocation using this.
*/
protected Options clientOptions;
-
- private static final String ANONYMOUS_SERVICE = "AnonymousService";
+ protected final String mep;
+ ServiceContext serviceContext;
+ private List soapHeaderList;
public MEPClient(ServiceContext service, String mep) {
this.serviceContext = service;
@@ -57,163 +63,100 @@
}
/**
- * Prepares the message context for invocation. The properties in the
- * MEPClient are copied to the MessageContext.
+ * Allows users to add a SOAP header block.
+ *
+ * @param soapHeaderBlock
*/
- protected void prepareInvocation(AxisOperation axisop, MessageContext msgCtx)
- throws AxisFault {
+ public void addSOAPHeader(OMElement soapHeaderBlock) {
+ if (soapHeaderBlock == null) {
- // user must provide the minimum information for the engine to proceed
- // with the invocation.
- // For the time being, I think he should at least provide the toEPR. So
- // I should check that is
- // available either from the message context or from the options.
- if ((msgCtx == null || msgCtx.getTo() == null)
- && (clientOptions == null || clientOptions.getTo() == null)) {
- throw new AxisFault(
- "Can not proceed without options being set for invocation. Set the"
- + "properties for this invocation via MEPClient.setOptions(Options) first.");
- }
- if (axisop == null) {
- throw new AxisFault(Messages
- .getMessage("cannotBeNullAxisOperation"));
- }
- // make sure operation is type right MEP
- if (mep.equals(axisop.getMessageExchangePattern())) {
- throw new AxisFault(Messages.getMessage("mepClientSupportOnly",
- mep, axisop.getMessageExchangePattern()));
+ // what are you trying to do here. You wanna set null to a header ??
+ return;
}
- // if operation not alrady added, add it
- if (serviceContext.getAxisService().getOperation(axisop.getName()) == null) {
- serviceContext.getAxisService().addOperation(axisop);
+ if (soapHeaderList == null) {
+ soapHeaderList = new ArrayList();
}
- // now its the time to put the parameters set by the user in to the
- // correct places and to the
- // operation context.
- extractPropertiesFromOptionsToContexts(msgCtx);
-
- // check user has put any SOAPHeader using the call MEPClient methods
- // and add them, if any, to the
- // the SOAP message
- addUserAddedSOAPHeaders(msgCtx, clientOptions);
-
- // find and set the transport details
- configureTransportInformation(msgCtx);
-
+ soapHeaderList.add(soapHeaderBlock);
}
/**
- * This will give chance to the derived class to configure his transport
- * from the information injected by the user via options. This will be
- * called within the prepare invocation method, so user should not bother to
- * call this explicitly.
+ * Allows users to add their own headers to the out going message from the
+ * client. It is restrictive, in the sense, that user can set a header with
+ * only one text. <code><pre>
+ * <HeaderBlockName>your text</HeaderBlockName>
+ * </pre></code>. A more flexible way is to use addSOAPHeader(OMElement).
+ *
+ * @param soapHeaderQName
+ * @param soapHeaderText
*/
- protected abstract void configureTransportInformation(MessageContext msgCtxt)
- throws AxisFault;
-
- private void extractPropertiesFromOptionsToContexts(MessageContext msgCtx) {
-
- // copy addressing parameters
- msgCtx.setTo(clientOptions.getTo());
- msgCtx.setFrom(clientOptions.getFrom());
- msgCtx.setFaultTo(clientOptions.getFaultTo());
- msgCtx.setReplyTo(clientOptions.getReplyTo());
- msgCtx.setRelatesTo(clientOptions.getRelatesTo());
- msgCtx.setMessageID((clientOptions.getMessageId() == null || ""
- .equals(clientOptions.getMessageId())) ? UUIDGenerator
- .getUUID() : clientOptions.getMessageId());
- msgCtx.setWSAAction(clientOptions.getAction());
+ public void addSOAPHeader(QName soapHeaderQName, String soapHeaderText) {
+ OMElement omElement = OMAbstractFactory.getOMFactory().createOMElement(soapHeaderQName,
+ null);
- msgCtx.setSoapAction(clientOptions.getSoapAction());
- msgCtx.setProperty(Constants.Configuration.IS_USING_SEPARATE_LISTENER,
- new Boolean(clientOptions.isUseSeparateListener()));
+ omElement.setText(soapHeaderText);
- // I'm not setting the properties here. Those will be set, when we
- // create the operation context
+ if (soapHeaderList == null) {
+ soapHeaderList = new ArrayList();
+ }
+ soapHeaderList.add(omElement);
}
- protected void addUserAddedSOAPHeaders(MessageContext msgCtx,
- Options options) {
- if (soapHeaderList != null && soapHeaderList.size() > 0
- && msgCtx.getEnvelope() != null) {
+ protected void addUserAddedSOAPHeaders(MessageContext msgCtx, Options options) {
+ if ((soapHeaderList != null) && (soapHeaderList.size() > 0)
+ && (msgCtx.getEnvelope() != null)) {
SOAPFactory soapFactory;
SOAPHeader header = msgCtx.getEnvelope().getHeader();
+
if (header == null) {
soapFactory = getCorrectSOAPFactory(msgCtx);
header = soapFactory.createSOAPHeader(msgCtx.getEnvelope());
}
+
if (!header.isComplete()) {
header.build();
}
for (int i = 0; i < soapHeaderList.size(); i++) {
OMElement headerBlock = (OMElement) soapHeaderList.get(i);
+
header.addChild(headerBlock);
}
-
}
}
/**
- * Prepares the SOAPEnvelope using the payload.
+ * Assumes the values for the ConfigurationContext and ServiceContext to
+ * make the NON WSDL cases simple.
*
- * @param toSend
- * @return
* @throws AxisFault
*/
- protected MessageContext prepareTheSOAPEnvelope(OMElement toSend)
- throws AxisFault {
- MessageContext msgctx = new MessageContext(serviceContext
- .getConfigurationContext());
+ protected void assumeServiceContext(String clientHome) throws AxisFault {
+ ConfigurationContext configurationContext =
+ new ConfigurationContextFactory().buildClientConfigurationContext(clientHome);
+ AxisService axisService =
+ configurationContext.getAxisConfiguration().getService(ANONYMOUS_SERVICE);
- SOAPEnvelope envelope = createDefaultSOAPEnvelope();
- if (toSend != null) {
- envelope.getBody().addChild(toSend);
+ if (axisService == null) {
+
+ // we will assume a Service and operations
+ axisService = new AxisService(ANONYMOUS_SERVICE);
}
- msgctx.setEnvelope(envelope);
- return msgctx;
+
+ configurationContext.getAxisConfiguration().addService(axisService);
+ serviceContext = new ServiceGroupContext(configurationContext,
+ axisService.getParent()).getServiceContext(ANONYMOUS_SERVICE);
}
/**
- * Infers the transport by looking at the URL. The URL can be http:// tcp://
- * mail:// local://.
- *
- * @param epr
- * @return
- * @throws AxisFault
+ * This will give chance to the derived class to configure his transport
+ * from the information injected by the user via options. This will be
+ * called within the prepare invocation method, so user should not bother to
+ * call this explicitly.
*/
- protected TransportOutDescription inferTransport(EndpointReference epr)
- throws AxisFault {
- if (epr != null) {
- return inferTransport(epr.getAddress());
- } else {
- throw new AxisFault(Messages.getMessage("cannotInferTransport"));
- }
- }
-
- protected TransportOutDescription inferTransport(String uri)
- throws AxisFault {
- String transport = null;
- if (uri != null) {
- int index = uri.indexOf(':');
- if (index > 0) {
- transport = uri.substring(0, index);
- }
- }
-
- if (transport != null) {
- return serviceContext.getConfigurationContext()
- .getAxisConfiguration().getTransportOut(
- new QName(transport));
-
- } else {
- throw new AxisFault(Messages.getMessage("cannotInferTransport"));
- }
-
- }
+ protected abstract void configureTransportInformation(MessageContext msgCtxt) throws AxisFault;
/**
* Creates SOAPEvelope(in terms of version) from the values set.
@@ -233,11 +176,11 @@
}
String soapVersionURI = clientOptions.getSoapVersionURI();
+
if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(soapVersionURI)) {
return OMAbstractFactory.getSOAP12Factory().getDefaultEnvelope();
- } else if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI
- .equals(soapVersionURI)
- || "".equals(soapVersionURI) || soapVersionURI == null) {
+ } else if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(soapVersionURI)
+ || "".equals(soapVersionURI) || (soapVersionURI == null)) {
return OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
} else {
throw new AxisFault(Messages.getMessage("invaidSOAPversion"));
@@ -255,141 +198,205 @@
* @throws AxisFault
*/
public void engageModule(QName name) throws AxisFault {
- AxisConfiguration axisConf = serviceContext.getConfigurationContext()
- .getAxisConfiguration();
+ AxisConfiguration axisConf =
+ serviceContext.getConfigurationContext().getAxisConfiguration();
+
// if it is already engeged do not engege it agaien
if (!axisConf.isEngaged(name)) {
axisConf.engageModule(name);
}
}
- private SOAPFactory getCorrectSOAPFactory(MessageContext msgCtx) {
- String soapNSURI = msgCtx.getEnvelope().getNamespace().getName();
- if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(soapNSURI)) {
- return OMAbstractFactory.getSOAP11Factory();
- } else {
- return OMAbstractFactory.getSOAP12Factory();
- }
- }
+ private void extractPropertiesFromOptionsToContexts(MessageContext msgCtx) {
- public void setServiceContext(ServiceContext serviceContext) {
- this.serviceContext = serviceContext;
- }
+ // copy addressing parameters
+ msgCtx.setTo(clientOptions.getTo());
+ msgCtx.setFrom(clientOptions.getFrom());
+ msgCtx.setFaultTo(clientOptions.getFaultTo());
+ msgCtx.setReplyTo(clientOptions.getReplyTo());
+ msgCtx.setRelatesTo(clientOptions.getRelatesTo());
+ msgCtx.setMessageID(((clientOptions.getMessageId() == null)
+ || "".equals(clientOptions.getMessageId()))
+ ? UUIDGenerator.getUUID()
+ : clientOptions.getMessageId());
+ msgCtx.setWSAAction(clientOptions.getAction());
+ msgCtx.setSoapAction(clientOptions.getSoapAction());
+ msgCtx.setProperty(Constants.Configuration.IS_USING_SEPARATE_LISTENER,
+ new Boolean(clientOptions.isUseSeparateListener()));
- public ServiceContext getServiceContext() {
- return serviceContext;
+ // I'm not setting the properties here. Those will be set, when we
+ // create the operation context
}
/**
- * Assumes the values for the ConfigurationContext and ServiceContext to
- * make the NON WSDL cases simple.
+ * Infers the transport by looking at the URL. The URL can be http:// tcp:/
+ * mail:// local://.
*
+ * @param epr
+ * @return
* @throws AxisFault
*/
- protected void assumeServiceContext(String clientHome) throws AxisFault {
- ConfigurationContext configurationContext = new ConfigurationContextFactory()
- .buildClientConfigurationContext(clientHome);
-
- AxisService axisService = configurationContext.getAxisConfiguration()
- .getService(ANONYMOUS_SERVICE);
- if (axisService == null) {
- // we will assume a Service and operations
- axisService = new AxisService(ANONYMOUS_SERVICE);
+ protected TransportOutDescription inferTransport(EndpointReference epr) throws AxisFault {
+ if (epr != null) {
+ return inferTransport(epr.getAddress());
+ } else {
+ throw new AxisFault(Messages.getMessage("cannotInferTransport"));
}
- configurationContext.getAxisConfiguration().addService(axisService);
- serviceContext = new ServiceGroupContext(configurationContext,
- axisService.getParent()).getServiceContext(ANONYMOUS_SERVICE);
}
- public Options getClientOptions() {
- return clientOptions;
- }
+ protected TransportOutDescription inferTransport(String uri) throws AxisFault {
+ String transport = null;
- /**
- * User will set all the options and parameters for this invocation using
- * this.
- *
- * @param clientOptions
- * @see Options for more details.
- */
- public void setClientOptions(Options clientOptions) {
- this.clientOptions = clientOptions;
- }
+ if (uri != null) {
+ int index = uri.indexOf(':');
- /**
- * Allows users to add their own headers to the out going message from the
- * client. It is restrictive, in the sense, that user can set a header with
- * only one text. <code><pre>
- * <HeaderBlockName>your text</HeaderBlockName>
- * </pre></code>. A more flexible way is to use addSOAPHeader(OMElement).
- *
- * @param soapHeaderQName
- * @param soapHeaderText
- */
- public void addSOAPHeader(QName soapHeaderQName, String soapHeaderText) {
- OMElement omElement = OMAbstractFactory.getOMFactory().createOMElement(
- soapHeaderQName, null);
- omElement.setText(soapHeaderText);
- if (soapHeaderList == null) {
- soapHeaderList = new ArrayList();
+ if (index > 0) {
+ transport = uri.substring(0, index);
+ }
}
- soapHeaderList.add(omElement);
- }
- /**
- * Allows users to add a SOAP header block.
- *
- * @param soapHeaderBlock
- */
- public void addSOAPHeader(OMElement soapHeaderBlock) {
- if (soapHeaderBlock == null) {
- // what are you trying to do here. You wanna set null to a header ??
- return;
- }
- if (soapHeaderList == null) {
- soapHeaderList = new ArrayList();
+ if (transport != null) {
+ return serviceContext.getConfigurationContext().getAxisConfiguration().getTransportOut(
+ new QName(transport));
+ } else {
+ throw new AxisFault(Messages.getMessage("cannotInferTransport"));
}
- soapHeaderList.add(soapHeaderBlock);
}
- protected void inferTransportOutDescription(MessageContext msgCtx)
- throws AxisFault {
+ protected void inferTransportOutDescription(MessageContext msgCtx) throws AxisFault {
+
// user can set the transport by giving a TransportOutDescription or we
// will deduce that from the
// to epr information
-
// if user has not set the TransportOutDescription, lets infer that
if (clientOptions.getSenderTransport() == null) {
- AxisConfiguration axisConfig = this.serviceContext
- .getConfigurationContext().getAxisConfiguration();
+ AxisConfiguration axisConfig =
+ this.serviceContext.getConfigurationContext().getAxisConfiguration();
// we have a deprecated method for user to set the transport
// protocol directly. Lets support that also
- String senderTrasportProtocol = clientOptions
- .getSenderTransportProtocol();
+ String senderTrasportProtocol = clientOptions.getSenderTransportProtocol();
+
if (axisConfig != null) {
- if (senderTrasportProtocol == null
- || "".equals(senderTrasportProtocol)) {
+ if ((senderTrasportProtocol == null) || "".equals(senderTrasportProtocol)) {
+
// by this time we have passed all the information we
// collected via Options to the
// message context
- clientOptions.setSenderTransport(inferTransport(msgCtx
- .getTo()));
+ clientOptions.setSenderTransport(inferTransport(msgCtx.getTo()));
} else {
+
// if he has not set the transport information, we gonna
// infer that from the to EPR
- clientOptions
- .setSenderTransport(axisConfig
- .getTransportOut(new QName(
- senderTrasportProtocol)));
+ clientOptions.setSenderTransport(
+ axisConfig.getTransportOut(new QName(senderTrasportProtocol)));
}
}
+
if (this.clientOptions.getSenderTransport() == null) {
throw new AxisFault(Messages.getMessage("unknownTransport",
senderTrasportProtocol));
}
}
+ }
+
+ /**
+ * Prepares the message context for invocation. The properties in the
+ * MEPClient are copied to the MessageContext.
+ */
+ protected void prepareInvocation(AxisOperation axisop, MessageContext msgCtx) throws AxisFault {
+ // user must provide the minimum information for the engine to proceed
+ // with the invocation.
+ // For the time being, I think he should at least provide the toEPR. So
+ // I should check that is
+ // available either from the message context or from the options.
+ if (((msgCtx == null) || (msgCtx.getTo() == null))
+ && ((clientOptions == null) || (clientOptions.getTo() == null))) {
+ throw new AxisFault(
+ "Can not proceed without options being set for invocation. Set the"
+ + "properties for this invocation via MEPClient.setOptions(Options) first.");
+ }
+
+ if (axisop == null) {
+ throw new AxisFault(Messages.getMessage("cannotBeNullAxisOperation"));
+ }
+
+ // make sure operation is type right MEP
+ if (mep.equals(axisop.getMessageExchangePattern())) {
+ throw new AxisFault(Messages.getMessage("mepClientSupportOnly", mep,
+ axisop.getMessageExchangePattern()));
+ }
+
+ // if operation not alrady added, add it
+ if (serviceContext.getAxisService().getOperation(axisop.getName()) == null) {
+ serviceContext.getAxisService().addOperation(axisop);
+ }
+
+ // now its the time to put the parameters set by the user in to the
+ // correct places and to the
+ // operation context.
+ extractPropertiesFromOptionsToContexts(msgCtx);
+
+ // check user has put any SOAPHeader using the call MEPClient methods
+ // and add them, if any, to the
+ // the SOAP message
+ addUserAddedSOAPHeaders(msgCtx, clientOptions);
+
+ // find and set the transport details
+ configureTransportInformation(msgCtx);
}
+ /**
+ * Prepares the SOAPEnvelope using the payload.
+ *
+ * @param toSend
+ * @return
+ * @throws AxisFault
+ */
+ protected MessageContext prepareTheSOAPEnvelope(OMElement toSend) throws AxisFault {
+ MessageContext msgctx = new MessageContext(serviceContext.getConfigurationContext());
+ SOAPEnvelope envelope = createDefaultSOAPEnvelope();
+
+ if (toSend != null) {
+ envelope.getBody().addChild(toSend);
+ }
+
+ msgctx.setEnvelope(envelope);
+
+ return msgctx;
+ }
+
+ public Options getClientOptions() {
+ return clientOptions;
+ }
+
+ private SOAPFactory getCorrectSOAPFactory(MessageContext msgCtx) {
+ String soapNSURI = msgCtx.getEnvelope().getNamespace().getName();
+
+ if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(soapNSURI)) {
+ return OMAbstractFactory.getSOAP11Factory();
+ } else {
+ return OMAbstractFactory.getSOAP12Factory();
+ }
+ }
+
+ public ServiceContext getServiceContext() {
+ return serviceContext;
+ }
+
+ /**
+ * User will set all the options and parameters for this invocation using
+ * this.
+ *
+ * @param clientOptions
+ * @see Options for more details.
+ */
+ public void setClientOptions(Options clientOptions) {
+ this.clientOptions = clientOptions;
+ }
+
+ public void setServiceContext(ServiceContext serviceContext) {
+ this.serviceContext = serviceContext;
+ }
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/MessageSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/MessageSender.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/MessageSender.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/MessageSender.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
/*
- * Copyright 2004,2005 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.
- */
+* Copyright 2004,2005 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.axis2.client;
@@ -35,9 +36,12 @@
* Message Sender is similar to the Call. Call is just a wrapper that provides a simple API.
*/
public class MessageSender extends InOnlyMEPClient {
-
protected static AxisOperation axisOperationTemplate;
+ public MessageSender() throws AxisFault {
+ this((String) null);
+ }
+
/**
* Constructs a Message Sender from a Service Context.
*
@@ -47,23 +51,40 @@
super(service);
}
- public MessageSender() throws AxisFault {
- this((String) null);
- }
-
/**
* Constructs a Message Sender from a specified repository.
*
* @param clientHome repository location
* @throws AxisFault
*/
-
public MessageSender(String clientHome) throws AxisFault {
super(null);
assumeServiceContext(clientHome);
}
/**
+ * create a default service Context if the users are not interested in the lower levels of control
+ *
+ * @throws AxisFault
+ */
+ protected void assumeServiceContext(String clientHome) throws AxisFault {
+ super.assumeServiceContext(clientHome);
+ axisOperationTemplate = new OutOnlyAxisOperation(new QName("TemplateOperation"));
+
+ AxisService axisService = serviceContext.getAxisService();
+ AxisConfiguration axisConfiguration =
+ serviceContext.getConfigurationContext().getAxisConfiguration();
+ PhasesInfo info = axisConfiguration.getPhasesInfo();
+
+ // to set the operation flows
+ if (info != null) {
+ info.setOperationPhases(axisOperationTemplate);
+ }
+
+ axisService.addOperation(axisOperationTemplate);
+ }
+
+ /**
* Sends a SOAP elvelope created from an OMElement.
*
* @param opName
@@ -72,6 +93,7 @@
*/
public void send(String opName, OMElement toSend) throws AxisFault {
SOAPEnvelope envelope = createDefaultSOAPEnvelope();
+
if (toSend != null) {
envelope.getBody().addChild(toSend);
}
@@ -84,22 +106,19 @@
throw new AxisFault("Can not send null SOAP envelope");
}
- AxisOperation axisOp = serviceContext.getAxisService()
- .getOperation(new QName(opName));
+ AxisOperation axisOp = serviceContext.getAxisService().getOperation(new QName(opName));
+
if (axisOp == null) {
- //todo I just assumed mep is alwas in-out , this has to improve : Deepal
+
+ // todo I just assumed mep is alwas in-out , this has to improve : Deepal
axisOp = new OutOnlyAxisOperation(new QName(opName));
serviceContext.getAxisService().addOperation(axisOp);
-
axisOp = AxisOperationFactory.getAxisOperation(WSDLConstants.MEP_CONSTANT_IN_ONLY);
axisOp.setName(new QName(opName));
- axisOp.setRemainingPhasesInFlow(
- axisOperationTemplate.getRemainingPhasesInFlow());
+ axisOp.setRemainingPhasesInFlow(axisOperationTemplate.getRemainingPhasesInFlow());
axisOp.setPhasesOutFlow(axisOperationTemplate.getPhasesOutFlow());
- axisOp.setPhasesInFaultFlow(
- axisOperationTemplate.getPhasesInFaultFlow());
- axisOp.setPhasesOutFaultFlow(
- axisOperationTemplate.getPhasesOutFaultFlow());
+ axisOp.setPhasesInFaultFlow(axisOperationTemplate.getPhasesInFaultFlow());
+ axisOp.setPhasesOutFaultFlow(axisOperationTemplate.getPhasesOutFaultFlow());
serviceContext.getAxisService().addOperation(axisOp);
}
@@ -107,24 +126,5 @@
msgctx.setEnvelope(soapEnvelope);
super.send(axisOp, msgctx);
- }
-
- /**
- * create a default service Context if the users are not interested in the lower levels of control
- *
- * @throws AxisFault
- */
- protected void assumeServiceContext(String clientHome) throws AxisFault {
- super.assumeServiceContext(clientHome);
- axisOperationTemplate = new OutOnlyAxisOperation(new QName("TemplateOperation"));
- AxisService axisService = serviceContext.getAxisService();
-
- AxisConfiguration axisConfiguration = serviceContext.getConfigurationContext().getAxisConfiguration();
- PhasesInfo info = axisConfiguration.getPhasesInfo();
- //to set the operation flows
- if (info != null) {
- info.setOperationPhases(axisOperationTemplate);
- }
- axisService.addOperation(axisOperationTemplate);
}
}