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 de...@apache.org on 2006/05/19 20:08:26 UTC
svn commit: r407869 - in /webservices/axis2/trunk/java/modules:
core/src/org/apache/axis2/client/ServiceClient.java
core/src/org/apache/axis2/description/AxisService2OM.java
integration/test/org/apache/axis2/processingModel/SoapProcessingModelTest.java
Author: deepal
Date: Fri May 19 11:08:26 2006
New Revision: 407869
URL: http://svn.apache.org/viewvc?rev=407869&view=rev
Log:
- added a way to cleanup service client
- Say if some one create SC with not null configcontext and null axiservice , then if he call cleanup then that service will be removed from axisConfiguration
- Override finalize method to call the cleanup method so when SC goes out of the scope it will automatically do the cleanup
Modified:
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/ServiceClient.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2OM.java
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/processingModel/SoapProcessingModelTest.java
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/ServiceClient.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/ServiceClient.java?rev=407869&r1=407868&r2=407869&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/ServiceClient.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/ServiceClient.java Fri May 19 11:08:26 2006
@@ -20,7 +20,6 @@
import javax.wsdl.Definition;
import javax.xml.namespace.QName;
-import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
@@ -31,15 +30,15 @@
public class ServiceClient {
// service and operation names used for anonymously stuff
- public static final String ANON_SERVICE = "__ANONYMOUS_SERVICE__";
+ public static final String ANON_SERVICE = "annonService";
public static final QName ANON_OUT_ONLY_OP = new QName(
- "__OPERATION_OUT_ONLY__");
+ "annonOutonlyOp");
public static final QName ANON_ROBUST_OUT_ONLY_OP = new QName(
- "__OPERATION_ROBUST_OUT_ONLY__");
+ "annonRobustOp");
- public static final QName ANON_OUT_IN_OP = new QName("__OPERATION_OUT_IN__");
+ public static final QName ANON_OUT_IN_OP = new QName("annonOutInOp");
// the metadata for the service that I'm clienting for
private AxisService axisService;
@@ -63,6 +62,8 @@
private ArrayList headers;
private CallbackReceiver callbackReceiver;
+ //whther we creat configctx or not
+ private boolean createConfigCtx;
/**
* Create a service client configured to work with a specific AxisService.
@@ -78,23 +79,24 @@
*/
public ServiceClient(ConfigurationContext configContext,
AxisService axisService) throws AxisFault {
- // create a config context if needed
+ configureServiceClient(configContext, axisService);
+ }
+ private void configureServiceClient(ConfigurationContext configContext, AxisService axisService) throws AxisFault {
initializeTransports(configContext);
// save the axisConfig and service
this.axisConfig = this.configContext.getAxisConfiguration();
if (axisService != null) {
this.axisService = axisService;
} else {
- if (this.axisConfig.getService(ANON_SERVICE) != null) {
- this.axisService = this.axisConfig.getService(ANON_SERVICE);
- } else {
- this.axisService = createAnonymousService();
- }
+ this.axisService = createAnonymousService();
}
-
if (this.axisConfig.getService(this.axisService.getName()) == null) {
this.axisConfig.addService(this.axisService);
+ } else {
+ throw new AxisFault(Messages.getMessage(
+ "twoservicecannothavesamename",
+ this.axisService.getName()));
}
ServiceGroupContext sgc = new ServiceGroupContext(this.configContext,
(AxisServiceGroup) this.axisService.getParent());
@@ -114,23 +116,8 @@
public ServiceClient(ConfigurationContext configContext, Definition wsdl4jDefinition,
QName wsdlServiceName, String portName) throws AxisFault {
- // create a config context if needed
- initializeTransports(configContext);
- try {
- this.axisConfig = this.configContext.getAxisConfiguration();
- this.axisService = AxisService.createClientSideAxisService(
- wsdl4jDefinition, wsdlServiceName, portName, options);
- // add the service to the config context if it isn't in there
- // already
- if (this.axisConfig.getService(this.axisService.getName()) == null) {
- this.axisConfig.addService(this.axisService);
- }
- ServiceGroupContext sgc = new ServiceGroupContext(this.configContext,
- (AxisServiceGroup) this.axisService.getParent());
- this.serviceContext = sgc.getServiceContext(this.axisService);
- } catch (IOException e) {
- throw new AxisFault(e);
- }
+ configureServiceClient(configContext, AxisService.createClientSideAxisService(
+ wsdl4jDefinition, wsdlServiceName, portName, options));
}
/**
@@ -149,27 +136,8 @@
*/
public ServiceClient(ConfigurationContext configContext, URL wsdlURL,
QName wsdlServiceName, String portName) throws AxisFault {
- // create a config context if needed
- initializeTransports(configContext);
- try {
- this.axisConfig = this.configContext.getAxisConfiguration();
- axisService = AxisService.createClientSideAxisService(wsdlURL,
- wsdlServiceName, portName, options);
- // add the service to the config context if it isn't in there
- // already
- if (this.axisConfig.getService(this.axisService.getName()) == null) {
- this.axisConfig.addService(this.axisService);
- } else {
- throw new AxisFault(Messages.getMessage(
- "twoservicecannothavesamename",
- this.axisService.getName()));
- }
- ServiceGroupContext sgc = new ServiceGroupContext(this.configContext,
- (AxisServiceGroup) this.axisService.getParent());
- this.serviceContext = sgc.getServiceContext(this.axisService);
- } catch (IOException e) {
- throw new AxisFault(e);
- }
+ configureServiceClient(configContext, AxisService.createClientSideAxisService(wsdlURL,
+ wsdlServiceName, portName, options));
}
private void initializeTransports(ConfigurationContext configContext) throws AxisFault {
@@ -187,6 +155,7 @@
createConfigurationContextFromFileSystem(null, null);
trsManager = new ListenerManager();
trsManager.init(this.configContext);
+ createConfigCtx = true;
} else {
this.configContext = ListenerManager.defaultConfigurationContext;
}
@@ -213,7 +182,7 @@
// shortcut client API. NOTE: We only add the ones we know we'll use
// later in the convenience API; if you use
// this constructor then you can't expect any magic!
- AxisService axisService = new AxisService(ANON_SERVICE);
+ AxisService axisService = new AxisService(ANON_SERVICE + this.hashCode());
RobustOutOnlyAxisOperation robustoutoonlyOperation = new RobustOutOnlyAxisOperation(
ANON_ROBUST_OUT_ONLY_OP);
axisService.addOperation(robustoutoonlyOperation);
@@ -635,5 +604,24 @@
*/
public ServiceContext getServiceContext() {
return serviceContext;
+ }
+
+ protected void finalize() throws Throwable {
+ super.finalize();
+ cleanup();
+ }
+
+ /**
+ * This will remove axissrevice , if it is passed configuration context into it.
+ * The problem is if some one keep of on creating service client by giving
+ * configuration conetxt and null aixsService , in that case it SC will
+ * create new axisServices and add that into axisConfig , so to remove the
+ * one that this particular SC instance create one can use this method.
+ */
+ public void cleanup() throws AxisFault {
+ if (!createConfigCtx) {
+ configContext.getAxisConfiguration().removeServiceGroup(
+ ((AxisServiceGroup) axisService.getParent()).getServiceGroupName());
+ }
}
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2OM.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2OM.java?rev=407869&r1=407868&r2=407869&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2OM.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2OM.java Fri May 19 11:08:26 2006
@@ -1,22 +1,6 @@
package org.apache.axis2.description;
import org.apache.axiom.om.*;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamReader;
-
-import org.apache.axiom.om.OMAbstractFactory;
-import org.apache.axiom.om.OMAttribute;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
import org.apache.axiom.om.util.StAXUtils;
@@ -37,7 +21,6 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.StringWriter;
-import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
@@ -45,20 +28,20 @@
/*
* 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.
- *
- *
+ *
+ *
*/
public class AxisService2OM implements Java2WSDLConstants {
@@ -90,7 +73,7 @@
private boolean generateHttp = false;
public AxisService2OM(AxisService service, String[] serviceURL,
- String style, String use) {
+ String style, String use) {
this.axisService = service;
url = serviceURL;
if (style == null) {
@@ -187,7 +170,9 @@
Iterator operations = axisService.getOperations();
while (operations.hasNext()) {
AxisOperation axisOperation = (AxisOperation) operations.next();
-
+ if (axisOperation.isControlOperation()) {
+ continue;
+ }
String MEP = axisOperation.getMessageExchangePattern();
if (WSDLConstants.MEP_URI_IN_ONLY.equals(MEP)
|| WSDLConstants.MEP_URI_IN_OPTIONAL_OUT.equals(MEP)
@@ -234,7 +219,7 @@
}
private void generateHeaderMessages(AxisMessage axismessage, OMFactory fac,
- OMElement defintions) {
+ OMElement defintions) {
ArrayList extList = axismessage.getSoapHeaders();
for (int i = 0; i < extList.size(); i++) {
SOAPHeaderMessage header = (SOAPHeaderMessage) extList.get(i);
@@ -254,7 +239,7 @@
}
private void writeMessage(AxisMessage axismessage, OMFactory fac,
- OMElement defintions) {
+ OMElement defintions) {
QName schemaElementName = axismessage.getElementQName();
OMElement messageElement = fac
.createOMElement(MESSAGE_LOCAL_NAME, wsdl);
@@ -763,7 +748,7 @@
}
private void writeSoapHeaders(AxisMessage inaxisMessage, OMFactory fac,
- OMElement input, OMNamespace soapNameSpace) throws Exception {
+ OMElement input, OMNamespace soapNameSpace) throws Exception {
ArrayList extElementList;
extElementList = inaxisMessage.getSoapHeaders();
if (extElementList != null) {
@@ -777,8 +762,8 @@
}
private void addExtensionElemnet(OMFactory fac, OMElement element,
- String name, String att1Name, String att1Value, String att2Name,
- String att2Value, OMNamespace soapNameSpace) {
+ String name, String att1Name, String att1Value, String att2Name,
+ String att2Value, OMNamespace soapNameSpace) {
OMElement soapbinding = fac.createOMElement(name, soapNameSpace);
element.addChild(soapbinding);
soapbinding.addAttribute(att1Name, att1Value, null);
@@ -786,8 +771,8 @@
}
private void addExtensionElement(OMFactory fac, OMElement element,
- String name, String att1Name, String att1Value,
- OMNamespace soapNameSpace) {
+ String name, String att1Name, String att1Value,
+ OMNamespace soapNameSpace) {
OMElement extElement = fac.createOMElement(name, soapNameSpace);
element.addChild(extElement);
extElement.addAttribute(att1Name, att1Value, null);
@@ -802,7 +787,7 @@
}
private void addSOAPHeader(OMFactory fac, OMElement element,
- SOAPHeaderMessage header, OMNamespace soapNameSpace) {
+ SOAPHeaderMessage header, OMNamespace soapNameSpace) {
OMElement extElement = fac.createOMElement("header", soapNameSpace);
element.addChild(extElement);
String use = header.getUse();
@@ -831,7 +816,7 @@
}
private void addPolicyAsExtElement(int type, PolicyInclude policyInclude,
- OMElement element, OMFactory factory) throws Exception {
+ OMElement element, OMFactory factory) throws Exception {
ArrayList elementList = policyInclude.getPolicyElements(type);
StAXPolicyWriter pwrt = (StAXPolicyWriter) PolicyFactory
.getPolicyWriter(PolicyFactory.StAX_POLICY_WRITER);
@@ -898,7 +883,7 @@
}
private void addPolicyAsExtAttribute(int type, PolicyInclude policyInclude,
- OMElement element, OMFactory factory) throws Exception {
+ OMElement element, OMFactory factory) throws Exception {
ArrayList elementList = policyInclude.getPolicyElements(type);
StAXPolicyWriter pwrt = (StAXPolicyWriter) PolicyFactory
Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/processingModel/SoapProcessingModelTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/processingModel/SoapProcessingModelTest.java?rev=407869&r1=407868&r2=407869&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/processingModel/SoapProcessingModelTest.java (original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/processingModel/SoapProcessingModelTest.java Fri May 19 11:08:26 2006
@@ -83,15 +83,10 @@
try {
ConfigurationContext configContext = Utils
.getNewConfigurationContext(Constants.TESTING_REPOSITORY);
- configContext.getAxisConfiguration().addService(clientService);
-
- ServiceContext serviceContext = new ServiceGroupContext(
- configContext, (AxisServiceGroup) clientService.getParent())
- .getServiceContext(clientService);
serviceClient = new ServiceClient(configContext, clientService);
MessageContext msgctx = new MessageContext();
- msgctx.setConfigurationContext(serviceContext.getConfigurationContext());
+ msgctx.setConfigurationContext(configContext);
msgctx.setEnvelope(envelope);
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org