Tushar Kapila
2017-09-08 10:28:31 UTC
Getting info from a remote server using Axis2 and soap.
We have axis2 working fine. But right now we are creating everything
everytime the method is called.
This leads to socket issues.
Looking for sample code/ open src project that does it correctly or notes
on how to do in transaction - production environment?
Use apache object pool? What to pool?
Use MultiThread.. ? (cant remember what but saw some post last night).
Below is our code, its all in one function now. Class is a singleton.
Thanks for your time.
//...
//1.6 axis in use
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.transport.http.HttpTransportProperties;
import org.apache.axis2.transport.http.HTTPConstants;
import net.rubyeye.xmemcached.MemcachedClient;
import javax.xml.soap.MessageFactory;
import org.apache.axis2.AxisFault;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axiom.soap.SOAPMessage;
import org.apache.axis2.client.OperationClient;
import org.apache.axis2.context.MessageContext;
//...
public String getImpDataFromZaServer(String client, String cid){
MessageContext reqMessageContext = null;
String encCid= "";
String wsdlURL = LeParameters.getParameter(client,
"CLIENT_WSDL_URL");
String axisProtocolHandler = LeParameters.getParameter(client,
"CLIENT_WSDL_PROTOCOL_HANDLER");//com.sun.net.ssl.internal.www.protocol
ClientAddressRange cRange =
ClientAddressRangeManager.getClientAddressRangeByPan(cid, client);
Map <String, String> proxyDetails = getProxyDetails(client, cRange);
String httpProxyIP = null;
String httpProxyPort = null;
httpProxyIP = proxyDetails.get("HTTP_PROXY_IP");
httpProxyPort = proxyDetails.get("HTTP_PROXY_PORT");
logger.debug("httpProxyIP: " +httpProxyIP);
logger.debug("httpProxyPort: " +httpProxyPort);
String impData = null;
int intPort = 443;
if(null != httpProxyPort){
try{
intPort = Integer.parseInt(httpProxyPort);
}catch(Exception exp){
logger.error("Unable to fetch customer details");
return impData;
}
}
Options options = new Options();
HttpTransportProperties.ProxyProperties proxyProperties = new
HttpTransportProperties.ProxyProperties();
proxyProperties.setProxyName(httpProxyIP);
proxyProperties.setProxyPort(intPort);
options.setProperty(HTTPConstants.PROXY, proxyProperties);
options.setProperty(HTTPConstants.CHUNKED,false);
System.setProperty("java.protocol.handler.pkgs :",
axisProtocolHandler);
try{
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://tempuri.org/",
"tns");
OMElement method = fac.createOMElement("FetchImpDataNumber",
omNs);
OMElement cardNum = fac.createOMElement("CidNumber", omNs);
cardNum.addChild(fac.createOMText(cardNum, cid));
method.addChild(cardNum);
options.setTo( new EndpointReference(wsdlURL));
options.setTransportInProtocol(Constants.TRANSPORT_HTTPS);
ServiceClient sender = new ServiceClient();
OperationClient opClient =
sender.createClient(ServiceClient.ANON_OUT_IN_OP);
opClient.setOptions(options);
opClient.getOptions().setAction("
http://tempuri.org/FetchImpDataNumber");
SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = factory.getDefaultEnvelope();
envelope.getBody().addChild(method);
reqMessageContext = new MessageContext();
reqMessageContext.setEnvelope(envelope);
opClient.addMessageContext(reqMessageContext);
opClient.execute(true);
MessageContext responseMessageContx = opClient
.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
SOAPEnvelope env = responseMessageContx.getEnvelope();
String response = null;
HashMap mp =null;
String email = "";
String countryCode = "";
String nameOnCard = "";
String clrPan ="";
String responseTxnID = "";
response = env.toString();
logger.info("Parse resposmse :[" + response + "]");
clrPan = extractField(response,"<Cid_Number>","</Cid_Number>",
false);
impData = extractField(response,"<ADDY_CUST>","</ADDY_CUST>",
false);
}catch(Exception ex){
logger.error("Unable to fetch customer details from CLIENT: "+
ex ", c :" + client + ", cid :" + cid + ",", ex);
}
return impData;
}
We have axis2 working fine. But right now we are creating everything
everytime the method is called.
This leads to socket issues.
Looking for sample code/ open src project that does it correctly or notes
on how to do in transaction - production environment?
Use apache object pool? What to pool?
Use MultiThread.. ? (cant remember what but saw some post last night).
Below is our code, its all in one function now. Class is a singleton.
Thanks for your time.
//...
//1.6 axis in use
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.transport.http.HttpTransportProperties;
import org.apache.axis2.transport.http.HTTPConstants;
import net.rubyeye.xmemcached.MemcachedClient;
import javax.xml.soap.MessageFactory;
import org.apache.axis2.AxisFault;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axiom.soap.SOAPMessage;
import org.apache.axis2.client.OperationClient;
import org.apache.axis2.context.MessageContext;
//...
public String getImpDataFromZaServer(String client, String cid){
MessageContext reqMessageContext = null;
String encCid= "";
String wsdlURL = LeParameters.getParameter(client,
"CLIENT_WSDL_URL");
String axisProtocolHandler = LeParameters.getParameter(client,
"CLIENT_WSDL_PROTOCOL_HANDLER");//com.sun.net.ssl.internal.www.protocol
ClientAddressRange cRange =
ClientAddressRangeManager.getClientAddressRangeByPan(cid, client);
Map <String, String> proxyDetails = getProxyDetails(client, cRange);
String httpProxyIP = null;
String httpProxyPort = null;
httpProxyIP = proxyDetails.get("HTTP_PROXY_IP");
httpProxyPort = proxyDetails.get("HTTP_PROXY_PORT");
logger.debug("httpProxyIP: " +httpProxyIP);
logger.debug("httpProxyPort: " +httpProxyPort);
String impData = null;
int intPort = 443;
if(null != httpProxyPort){
try{
intPort = Integer.parseInt(httpProxyPort);
}catch(Exception exp){
logger.error("Unable to fetch customer details");
return impData;
}
}
Options options = new Options();
HttpTransportProperties.ProxyProperties proxyProperties = new
HttpTransportProperties.ProxyProperties();
proxyProperties.setProxyName(httpProxyIP);
proxyProperties.setProxyPort(intPort);
options.setProperty(HTTPConstants.PROXY, proxyProperties);
options.setProperty(HTTPConstants.CHUNKED,false);
System.setProperty("java.protocol.handler.pkgs :",
axisProtocolHandler);
try{
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://tempuri.org/",
"tns");
OMElement method = fac.createOMElement("FetchImpDataNumber",
omNs);
OMElement cardNum = fac.createOMElement("CidNumber", omNs);
cardNum.addChild(fac.createOMText(cardNum, cid));
method.addChild(cardNum);
options.setTo( new EndpointReference(wsdlURL));
options.setTransportInProtocol(Constants.TRANSPORT_HTTPS);
ServiceClient sender = new ServiceClient();
OperationClient opClient =
sender.createClient(ServiceClient.ANON_OUT_IN_OP);
opClient.setOptions(options);
opClient.getOptions().setAction("
http://tempuri.org/FetchImpDataNumber");
SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = factory.getDefaultEnvelope();
envelope.getBody().addChild(method);
reqMessageContext = new MessageContext();
reqMessageContext.setEnvelope(envelope);
opClient.addMessageContext(reqMessageContext);
opClient.execute(true);
MessageContext responseMessageContx = opClient
.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
SOAPEnvelope env = responseMessageContx.getEnvelope();
String response = null;
HashMap mp =null;
String email = "";
String countryCode = "";
String nameOnCard = "";
String clrPan ="";
String responseTxnID = "";
response = env.toString();
logger.info("Parse resposmse :[" + response + "]");
clrPan = extractField(response,"<Cid_Number>","</Cid_Number>",
false);
impData = extractField(response,"<ADDY_CUST>","</ADDY_CUST>",
false);
}catch(Exception ex){
logger.error("Unable to fetch customer details from CLIENT: "+
ex ", c :" + client + ", cid :" + cid + ",", ex);
}
return impData;
}
--
Regards
Tushar Kapila
Regards
Tushar Kapila