Discussion:
need : java 8 transactional web app Axis2 client sample
Tushar Kapila
2017-09-08 10:28:31 UTC
Permalink
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;
}
--
Regards
Tushar Kapila
Thorsten Schöning
2017-09-08 13:17:40 UTC
Permalink
Guten Tag Tushar Kapila,
Post by Tushar Kapila
This leads to socket issues.
You should describe those issues more detailed, like what exactly
happens, providing concrete exceptions or such. At least for me it's
not clear what your actual problem is.

I have the strong feeling it's about not being able to execute more
than X parallel connections to your remote endpoint from the client?
Would fit to your mention of "MultiThread...". If so, that's because
Axis2 uses a connection manager which by default only allows two
connections to the same host at the same time. So depending on how
your client actually works, if it needs to serve multiple parallel
requests the same time, because itself is a server, there might be
some bottleneck.

That connection manager can be configured:

https://axis.apache.org/axis2/java/core/docs/http-transport.html#setting_cached_httpclient_object
http://wso2.com/library/3316/
http://wso2.com/library/3316/#cachedClient
http://wso2.com/library/3316/#connectionManager
Post by Tushar Kapila
private void initHttpConnectionManager(ConfigurationContext cfgCtx)
{
MultiThreadedHttpConnectionManager connMgr = (MultiThreadedHttpConnectionManager) cfgCtx.getProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER);
// Wenn es noch keine Instanz gibt, erzeugen und speichern wir selbst eine,
// die dann mit unseren Optionen gefüttert werden kann.
if (connMgr == null)
{
connMgr = new MultiThreadedHttpConnectionManager();
cfgCtx.setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER, connMgr);
}
HttpConnectionManagerParams connMgrParams = connMgr.getParams();
connMgrParams.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, 100);
connMgrParams.setMaxTotalConnections(100);
}
Mit freundlichen Grüßen,

Thorsten Schöning
--
Thorsten Schöning E-Mail: ***@AM-SoFT.de
AM-SoFT IT-Systeme http://www.AM-SoFT.de/

Telefon...........05151- 9468- 55
Fax...............05151- 9468- 88
Mobil..............0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-***@axis.apache.org
For additional commands, e-mail: java-user-***@axis.apache.org
Tushar Kapila
2017-09-09 16:48:11 UTC
Permalink
thank you, i purposely did not write in detail about the errors, as I want
to rewrite the code anyway. So was looking a good sample to follow.

Want to make sure sockets are being shared across invocations. That the
initialization code is once. Right now its all in one method. and seems
that unneccessary initialization is happening. On the other hand since some
of the classes are not thread safe, wondering what a good way to do it?
ObjectPool ? Or some thing else?
Post by Thorsten Schöning
Guten Tag Tushar Kapila,
Post by Tushar Kapila
This leads to socket issues.
You should describe those issues more detailed, like what exactly
happens, providing concrete exceptions or such. At least for me it's
not clear what your actual problem is.
I have the strong feeling it's about not being able to execute more
than X parallel connections to your remote endpoint from the client?
Would fit to your mention of "MultiThread...". If so, that's because
Axis2 uses a connection manager which by default only allows two
connections to the same host at the same time. So depending on how
your client actually works, if it needs to serve multiple parallel
requests the same time, because itself is a server, there might be
some bottleneck.
https://axis.apache.org/axis2/java/core/docs/http-transport.
html#setting_cached_httpclient_object
http://wso2.com/library/3316/
http://wso2.com/library/3316/#cachedClient
http://wso2.com/library/3316/#connectionManager
Post by Tushar Kapila
private void initHttpConnectionManager(ConfigurationContext
cfgCtx)
Post by Tushar Kapila
{
MultiThreadedHttpConnectionManager connMgr = (
MultiThreadedHttpConnectionManager) cfgCtx.getProperty(
HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER);
Post by Tushar Kapila
// Wenn es noch keine Instanz gibt, erzeugen und
speichern wir selbst eine,
Post by Tushar Kapila
// die dann mit unseren Optionen gefÃŒttert werden kann.
if (connMgr == null)
{
connMgr = new MultiThreadedHttpConnectionMan
ager();
Post by Tushar Kapila
cfgCtx.setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER,
connMgr);
Post by Tushar Kapila
}
HttpConnectionManagerParams connMgrParams =
connMgr.getParams();
Post by Tushar Kapila
connMgrParams.setMaxConnectionsPerHost(
HostConfiguration.ANY_HOST_CONFIGURATION, 100);
Post by Tushar Kapila
connMgrParams.setMaxTotalConnections(100);
}
Mit freundlichen GrÌßen,
Thorsten Schöning
--
AM-SoFT IT-Systeme http://www.AM-SoFT.de/
Telefon...........05151- 9468- 55
Fax...............05151- 9468- 88
Mobil..............0178-8 9468- 04
AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - GeschÀftsfÌhrer: Andreas Muchow
---------------------------------------------------------------------
--
Regards
Tushar Kapila
Thorsten Schöning
2017-09-13 15:43:34 UTC
Permalink
Guten Tag Tushar Kapila,
Post by Tushar Kapila
Want to make sure sockets are being shared across invocations. That
the initialization code is once. Right now its all in one method.
and seems that unneccessary initialization is happening. On the
other hand since some of the classes are not thread safe, wondering
what a good way to do it? ObjectPool ? Or some thing else?
I'm not sure I understand your question: As I described in the last
mail, Axis2 is managing sockets and connections and caches things
already for you.

Mit freundlichen Grüßen,

Thorsten Schöning
--
Thorsten Schöning E-Mail: ***@AM-SoFT.de
AM-SoFT IT-Systeme http://www.AM-SoFT.de/

Telefon...........05151- 9468- 55
Fax...............05151- 9468- 88
Mobil..............0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-***@axis.apache.org
For additional commands, e-mail: java-user-***@axis.apache.org
Tushar Kapila
2017-09-16 15:54:44 UTC
Permalink
Guten Tag. Yes your right. Our main issue was time-outs with one server
that we were connecting to. The server we are connecting to had problems.
Set up 10 second time-outs, reuse the Http client, multi threaded, number
of connections, to each host and total setting. Txns still fail, but are
now failing fast and not tying up our local ports.
Post by Thorsten Schöning
Guten Tag Tushar Kapila,
Post by Tushar Kapila
Want to make sure sockets are being shared across invocations. That
the initialization code is once. Right now its all in one method.
and seems that unneccessary initialization is happening. On the
other hand since some of the classes are not thread safe, wondering
what a good way to do it? ObjectPool ? Or some thing else?
I'm not sure I understand your question: As I described in the last
mail, Axis2 is managing sockets and connections and caches things
already for you.
Mit freundlichen GrÌßen,
Thorsten Schöning
--
AM-SoFT IT-Systeme http://www.AM-SoFT.de/
Telefon...........05151- 9468- 55
Fax...............05151- 9468- 88
Mobil..............0178-8 9468- 04
AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - GeschÀftsfÌhrer: Andreas Muchow
---------------------------------------------------------------------
--
Regards
Tushar Kapila
Loading...