patricktam
asked on
Use java to connect to a SOAP web services error
Dear java programmer and consultant,
I am new to java and I has been assigned for a project to write a Java SOAP web service messaging client to connect and upload an attachment to a Web Services endpoint repository.
A sample java program template together with all the related libarires have been given for my java client program development. Also, all the config properties file are configured correctly.
During the program runtime, the following error/warnings were encountered (Listed as below). Can anyone tell me what is the root cause of the issue ? Is it a programming related, configured or not sure if it is related to the network (i.e. Packet was blocked by firewall) ?
Your kind assistant is appciated in advance and let me know if further information is needed.
Regards
Patrick Tam
[hk.gov.spica_scopes.scope s.messagin g.client.M essagingCl ient] at [wc-test-web] Exception raised in sendMessage
javax.xml.soap.SOAPExcepti on: java.net.SocketTimeoutExce ption: connect timed out
at hk.gov.spica_scopes.common .utils.Soa pUtils.sen dMessage(S oapUtils.j ava:810)
at hk.gov.spica_scopes.common .client.Cl ientBase.s endMessage Ex(ClientB ase.java:2 29)
at hk.gov.spica_scopes.scopes .messaging .client.Me ssagingCli ent.sendAs yncRequest (Unknown Source)
at hk.gov.spica_scopes.scopes .messaging .client.Me ssagingCli ent.sendAs yncLargeAt tachmentRe quest(Unkn own Source)
at hk.gov.spica_scopes.scopes .messaging .client.Me ssagingCli ent.sendAs yncLargeAt tachmentRe quest(Unkn own Source)
at MessagingClientSample.test AsyncMsgSe rviceWithL argeAttach ment(Messa gingClient Sample.jav a:66)
at MessagingClientSample.main (Messaging ClientSamp le.java:36 )
at sun.reflect.NativeMethodAc cessorImpl .invoke0(N ative Method)
at sun.reflect.NativeMethodAc cessorImpl .invoke(Un known Source)
at sun.reflect.DelegatingMeth odAccessor Impl.invok e(Unknown Source)
at java.lang.reflect.Method.i nvoke(Unkn own Source)
at org.eclipse.jdt.internal.j arinjarloa der.JarRsr cLoader.ma in(JarRsrc Loader.jav a:58)
Caused by: java.net.SocketTimeoutExce ption: connect timed out
at java.net.DualStackPlainSoc ketImpl.wa itForConne ct(Native Method)
at java.net.DualStackPlainSoc ketImpl.so cketConnec t(Unknown Source)
at java.net.AbstractPlainSock etImpl.doC onnect(Unk nown Source)
at java.net.AbstractPlainSock etImpl.con nectToAddr ess(Unknow n Source)
at java.net.AbstractPlainSock etImpl.con nect(Unkno wn Source)
at java.net.PlainSocketImpl.c onnect(Unk nown Source)
at java.net.SocksSocketImpl.c onnect(Unk nown Source)
at java.net.Socket.connect(Un known Source)
at hk.gov.spica_scopes.common .utils.Soa pUtils.tes tConnectio n(SoapUtil s.java:824 )
at hk.gov.spica_scopes.common .utils.Soa pUtils.sen dMessage(S oapUtils.j ava:752)
... 11 more
[hk.gov.spica_scopes.scope s.messagin g.client.M essagingCl ient] at [wc-test-web] Exception raised in sendMessage
javax.xml.soap.SOAPExcepti on: java.net.SocketTimeoutExce ption: connect timed out
at hk.gov.spica_scopes.common .utils.Soa pUtils.sen dMessage(S oapUtils.j ava:810)
at hk.gov.spica_scopes.common .client.Cl ientBase.s endMessage Ex(ClientB ase.java:2 29)
at hk.gov.spica_scopes.scopes .messaging .client.Me ssagingCli ent.sendAs yncRequest (Unknown Source)
at hk.gov.spica_scopes.scopes .messaging .client.Me ssagingCli ent.sendAs yncLargeAt tachmentRe quest(Unkn own Source)
at hk.gov.spica_scopes.scopes .messaging .client.Me ssagingCli ent.sendAs yncLargeAt tachmentRe quest(Unkn own Source)
at MessagingClientSample.test AsyncMsgSe rviceWithL argeAttach ment(Messa gingClient Sample.jav a:66)
at MessagingClientSample.main (Messaging ClientSamp le.java:36 )
at sun.reflect.NativeMethodAc cessorImpl .invoke0(N ative Method)
at sun.reflect.NativeMethodAc cessorImpl .invoke(Un known Source)
at sun.reflect.DelegatingMeth odAccessor Impl.invok e(Unknown Source)
at java.lang.reflect.Method.i nvoke(Unkn own Source)
at org.eclipse.jdt.internal.j arinjarloa der.JarRsr cLoader.ma in(JarRsrc Loader.jav a:58)
Caused by: java.net.SocketTimeoutExce ption: connect timed out
at java.net.DualStackPlainSoc ketImpl.wa itForConne ct(Native Method)
at java.net.DualStackPlainSoc ketImpl.so cketConnec t(Unknown Source)
at java.net.AbstractPlainSock etImpl.doC onnect(Unk nown Source)
at java.net.AbstractPlainSock etImpl.con nectToAddr ess(Unknow n Source)
at java.net.AbstractPlainSock etImpl.con nect(Unkno wn Source)
at java.net.PlainSocketImpl.c onnect(Unk nown Source)
at java.net.SocksSocketImpl.c onnect(Unk nown Source)
at java.net.Socket.connect(Un known Source)
at hk.gov.spica_scopes.common .utils.Soa pUtils.tes tConnectio n(SoapUtil s.java:824 )
at hk.gov.spica_scopes.common .utils.Soa pUtils.sen dMessage(S oapUtils.j ava:752)
... 11 more
[hk.gov.spica_scopes.scope s.messagin g.client.M essagingCl ient] at [wc-test-web] Exception in sendAsyncLargeAttachmentRe quest
hk.gov.spica_scopes.common .exception .Applicati onExceptio n: Fail to send message
at hk.gov.spica_scopes.common .client.Cl ientBase.s endMessage Ex(ClientB ase.java:2 50)
at hk.gov.spica_scopes.scopes .messaging .client.Me ssagingCli ent.sendAs yncRequest (Unknown Source)
at hk.gov.spica_scopes.scopes .messaging .client.Me ssagingCli ent.sendAs yncLargeAt tachmentRe quest(Unkn own Source)
at hk.gov.spica_scopes.scopes .messaging .client.Me ssagingCli ent.sendAs yncLargeAt tachmentRe quest(Unkn own Source)
at MessagingClientSample.test AsyncMsgSe rviceWithL argeAttach ment(Messa gingClient Sample.jav a:66)
at MessagingClientSample.main (Messaging ClientSamp le.java:36 )
at sun.reflect.NativeMethodAc cessorImpl .invoke0(N ative Method)
at sun.reflect.NativeMethodAc cessorImpl .invoke(Un known Source)
at sun.reflect.DelegatingMeth odAccessor Impl.invok e(Unknown Source)
at java.lang.reflect.Method.i nvoke(Unkn own Source)
at org.eclipse.jdt.internal.j arinjarloa der.JarRsr cLoader.ma in(JarRsrc Loader.jav a:58)
Caused by: javax.xml.soap.SOAPExcepti on: java.net.SocketTimeoutExce ption: connect timed out
at hk.gov.spica_scopes.common .utils.Soa pUtils.sen dMessage(S oapUtils.j ava:810)
at hk.gov.spica_scopes.common .client.Cl ientBase.s endMessage Ex(ClientB ase.java:2 29)
... 10 more
Caused by: java.net.SocketTimeoutExce ption: connect timed out
at java.net.DualStackPlainSoc ketImpl.wa itForConne ct(Native Method)
at java.net.DualStackPlainSoc ketImpl.so cketConnec t(Unknown Source)
at java.net.AbstractPlainSock etImpl.doC onnect(Unk nown Source)
at java.net.AbstractPlainSock etImpl.con nectToAddr ess(Unknow n Source)
at java.net.AbstractPlainSock etImpl.con nect(Unkno wn Source)
at java.net.PlainSocketImpl.c onnect(Unk nown Source)
at java.net.SocksSocketImpl.c onnect(Unk nown Source)
at java.net.Socket.connect(Un known Source)
at hk.gov.spica_scopes.common .utils.Soa pUtils.tes tConnectio n(SoapUtil s.java:824 )
at hk.gov.spica_scopes.common .utils.Soa pUtils.sen dMessage(S oapUtils.j ava:752)
... 11 more
I am new to java and I has been assigned for a project to write a Java SOAP web service messaging client to connect and upload an attachment to a Web Services endpoint repository.
A sample java program template together with all the related libarires have been given for my java client program development. Also, all the config properties file are configured correctly.
During the program runtime, the following error/warnings were encountered (Listed as below). Can anyone tell me what is the root cause of the issue ? Is it a programming related, configured or not sure if it is related to the network (i.e. Packet was blocked by firewall) ?
Your kind assistant is appciated in advance and let me know if further information is needed.
Regards
Patrick Tam
[hk.gov.spica_scopes.scope
javax.xml.soap.SOAPExcepti
at hk.gov.spica_scopes.common
at hk.gov.spica_scopes.common
at hk.gov.spica_scopes.scopes
at hk.gov.spica_scopes.scopes
at hk.gov.spica_scopes.scopes
at MessagingClientSample.test
at MessagingClientSample.main
at sun.reflect.NativeMethodAc
at sun.reflect.NativeMethodAc
at sun.reflect.DelegatingMeth
at java.lang.reflect.Method.i
at org.eclipse.jdt.internal.j
Caused by: java.net.SocketTimeoutExce
at java.net.DualStackPlainSoc
at java.net.DualStackPlainSoc
at java.net.AbstractPlainSock
at java.net.AbstractPlainSock
at java.net.AbstractPlainSock
at java.net.PlainSocketImpl.c
at java.net.SocksSocketImpl.c
at java.net.Socket.connect(Un
at hk.gov.spica_scopes.common
at hk.gov.spica_scopes.common
... 11 more
[hk.gov.spica_scopes.scope
javax.xml.soap.SOAPExcepti
at hk.gov.spica_scopes.common
at hk.gov.spica_scopes.common
at hk.gov.spica_scopes.scopes
at hk.gov.spica_scopes.scopes
at hk.gov.spica_scopes.scopes
at MessagingClientSample.test
at MessagingClientSample.main
at sun.reflect.NativeMethodAc
at sun.reflect.NativeMethodAc
at sun.reflect.DelegatingMeth
at java.lang.reflect.Method.i
at org.eclipse.jdt.internal.j
Caused by: java.net.SocketTimeoutExce
at java.net.DualStackPlainSoc
at java.net.DualStackPlainSoc
at java.net.AbstractPlainSock
at java.net.AbstractPlainSock
at java.net.AbstractPlainSock
at java.net.PlainSocketImpl.c
at java.net.SocksSocketImpl.c
at java.net.Socket.connect(Un
at hk.gov.spica_scopes.common
at hk.gov.spica_scopes.common
... 11 more
[hk.gov.spica_scopes.scope
hk.gov.spica_scopes.common
at hk.gov.spica_scopes.common
at hk.gov.spica_scopes.scopes
at hk.gov.spica_scopes.scopes
at hk.gov.spica_scopes.scopes
at MessagingClientSample.test
at MessagingClientSample.main
at sun.reflect.NativeMethodAc
at sun.reflect.NativeMethodAc
at sun.reflect.DelegatingMeth
at java.lang.reflect.Method.i
at org.eclipse.jdt.internal.j
Caused by: javax.xml.soap.SOAPExcepti
at hk.gov.spica_scopes.common
at hk.gov.spica_scopes.common
... 10 more
Caused by: java.net.SocketTimeoutExce
at java.net.DualStackPlainSoc
at java.net.DualStackPlainSoc
at java.net.AbstractPlainSock
at java.net.AbstractPlainSock
at java.net.AbstractPlainSock
at java.net.PlainSocketImpl.c
at java.net.SocksSocketImpl.c
at java.net.Socket.connect(Un
at hk.gov.spica_scopes.common
at hk.gov.spica_scopes.common
... 11 more
ASKER
Thanks a lot in advance. I am using Desktop app and and here is the code:
Also, I am using Eclipse IDE to generate the JAR file for execution.
I like to know if the warning/error related to "connection/network related issue" or "actually configuration" or "program bug"..
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
import java.util.Vector;
import javax.xml.soap.SOAPMessage ;
import hk.gov.spica_scopes.common .logging.L ogger;
import hk.gov.spica_scopes.common .utils.Pro pertiesUti ls;
import hk.gov.spica_scopes.common .utils.Soa pUtils;
import hk.gov.spica_scopes.scopes .messaging .client.Me ssagingCli ent;
import hk.gov.spica_scopes.scopes .messaging .client.Pr opertyName s;
import hk.gov.spica_scopes.scopes .messaging .types.IMe ssageType;
import hk.gov.spica_scopes.scopes .messaging .types.IMe ssagingCon stants;
import hk.gov.spica_scopes.scopes .messaging .webserver .elements. testmsg.Te stMsgReque st;
public class MessagingClientSample {
public MessagingClientSample(Stri ng propFilePath) {
init(propFilePath);
}
public static void main(String[] args) {
try {
if (args.length != 3 || (!args[0].equalsIgnoreCase ("U") && !args[0].equalsIgnoreCase( "D")) ) {
System.out.println("Usage: ");
System.out.println("To upload file: MessagingClientSample U <Prop File Path> <Upload File Path>");
System.out.println("To download file: MessagingClientSample D <Prop File Path> <Download Folder Path>");
} else {
MessagingClientSample sample = new MessagingClientSample(args [1]);
if (args[0].equalsIgnoreCase( "U"))
sample.testAsyncMsgService WithLargeA ttachment( args[2]);
if (args[0].equalsIgnoreCase( "D"))
sample.testBatchPullServic e(args[2]) ;
}
}
catch (Exception e) {
e.printStackTrace();
m_logger.logDebug("General exception raised in main", e);
}
}
/**
* Sample on how to call async message service with large attachment
* @throws Exception
*/
public void testAsyncMsgServiceWithLar geAttachme nt(String filePath) throws Exception {
Vector fileList = new Vector();
List rcptList = new Vector();
rcptList.add("oghr1.app001 "); //EGIS Messaging Service AppID of Recipient
Map inMap = new TreeMap();
inMap.put(IMessagingConsta nts.RECIPI ENT_APP_ID _LIST, rcptList);
inMap.put(IMessagingConsta nts.MESSAG E_TYPE, IMessageType.REQUEST);
SOAPMessage requestMsg = SoapUtils.emptyMessage();
TestMsgRequest request = new TestMsgRequest();
request.setMessage("file transfer sample");
SoapUtils.addBody(requestM sg, request);
SOAPMessage response = clientKit.sendAsyncLargeAt tachmentRe quest(requ estMsg, inMap, filePath);
if (null != response && response.getSOAPBody().has Fault()) {
String fault = response.getSOAPBody().get Fault().ge tFaultStri ng();
m_logger.logInfo("SOAP Fault returned: " + fault);
throw new Exception("Soap fault in response message, fault message - " + fault);
}
}
/**
* Sample on how to call batch pull service
* @throws Exception
*/
public void testBatchPullService(Strin g downloadFilePath) throws Exception {
Map inMap = new TreeMap();
List rcptList = new Vector();
rcptList.add("oghr1.app001 "); //EGIS Messaging Service AppID of Recipient
inMap.put(IMessagingConsta nts.RECIPI ENT_APP_ID _LIST, rcptList);
inMap.put(IMessagingConsta nts.SENDER _APP_ID, "oghr1.app001"); //EGIS Messaging Service AppID of Sender
inMap.put(PropertyNames.LA RGE_ATTACH MENT_SUPPO RT_PROPERT Y, "Y");
inMap.put(PropertyNames.LA RGE_ATTACH MENT_DIR_P ROPERTY, downloadFilePath);
SOAPMessage requestMsg = clientKit.createBatchPullR equest(inM ap);
SOAPMessage response = clientKit.sendBatchPullReq uest(reque stMsg);
if (null != response) {
if (response.getSOAPBody().ha sFault()) {
String fault = response.getSOAPBody().get Fault().ge tFaultStri ng();
m_logger.logInfo("SOAP Fault returned: " + fault);
throw new Exception("Soap fault in response message, fault message - " + fault);
}else{
SOAPMessage[] msgs = clientKit.getMsgsFromRespo nse(respon se);
for(SOAPMessage m : msgs) {
String msgId = m.getSOAPHeader().getEleme ntsByTagNa me("MsgId" ).item(0). getFirstCh ild().getN odeValue() ;
m_logger.logInfo("Message ID: " + msgId);
testPullAckService(msgId);
}
}
}
}
/**
* Sample on how to call pull acknowledgement service
* @throws Exception
*/
public void testPullAckService(String msgId) throws Exception {
Map inMap = new TreeMap();
inMap.put(IMessagingConsta nts.MESSAG E_ID, msgId);
SOAPMessage requestMsg = clientKit.createPullAckReq uest(inMap );
SOAPMessage response = clientKit.sendPullAckReque st(request Msg);
if (null != response && response.getSOAPBody().has Fault()) {
String fault = response.getSOAPBody().get Fault().ge tFaultStri ng();
m_logger.logInfo("SOAP Fault returned: " + fault);
throw new Exception("Soap fault in response message, fault message - " + fault);
}
}
private void init(String propFilePath) {
try {
// Properties can be read from file
Properties propFromFile = PropertiesUtils.loadProper tiesFile(p ropFilePat h);
clientKit = new MessagingClient(propFromFi le);
}
catch (Exception e) {
m_logger.logError("General exception raised in init", e);
}
}
private MessagingClient clientKit = null;
private static Logger m_logger = Logger.getLogger(Messaging ClientSamp le.class);
}
Also, I am using Eclipse IDE to generate the JAR file for execution.
I like to know if the warning/error related to "connection/network related issue" or "actually configuration" or "program bug"..
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
import java.util.Vector;
import javax.xml.soap.SOAPMessage
import hk.gov.spica_scopes.common
import hk.gov.spica_scopes.common
import hk.gov.spica_scopes.common
import hk.gov.spica_scopes.scopes
import hk.gov.spica_scopes.scopes
import hk.gov.spica_scopes.scopes
import hk.gov.spica_scopes.scopes
import hk.gov.spica_scopes.scopes
public class MessagingClientSample {
public MessagingClientSample(Stri
init(propFilePath);
}
public static void main(String[] args) {
try {
if (args.length != 3 || (!args[0].equalsIgnoreCase
System.out.println("Usage:
System.out.println("To upload file: MessagingClientSample U <Prop File Path> <Upload File Path>");
System.out.println("To download file: MessagingClientSample D <Prop File Path> <Download Folder Path>");
} else {
MessagingClientSample sample = new MessagingClientSample(args
if (args[0].equalsIgnoreCase(
sample.testAsyncMsgService
if (args[0].equalsIgnoreCase(
sample.testBatchPullServic
}
}
catch (Exception e) {
e.printStackTrace();
m_logger.logDebug("General
}
}
/**
* Sample on how to call async message service with large attachment
* @throws Exception
*/
public void testAsyncMsgServiceWithLar
Vector fileList = new Vector();
List rcptList = new Vector();
rcptList.add("oghr1.app001
Map inMap = new TreeMap();
inMap.put(IMessagingConsta
inMap.put(IMessagingConsta
SOAPMessage requestMsg = SoapUtils.emptyMessage();
TestMsgRequest request = new TestMsgRequest();
request.setMessage("file transfer sample");
SoapUtils.addBody(requestM
SOAPMessage response = clientKit.sendAsyncLargeAt
if (null != response && response.getSOAPBody().has
String fault = response.getSOAPBody().get
m_logger.logInfo("SOAP Fault returned: " + fault);
throw new Exception("Soap fault in response message, fault message - " + fault);
}
}
/**
* Sample on how to call batch pull service
* @throws Exception
*/
public void testBatchPullService(Strin
Map inMap = new TreeMap();
List rcptList = new Vector();
rcptList.add("oghr1.app001
inMap.put(IMessagingConsta
inMap.put(IMessagingConsta
inMap.put(PropertyNames.LA
inMap.put(PropertyNames.LA
SOAPMessage requestMsg = clientKit.createBatchPullR
SOAPMessage response = clientKit.sendBatchPullReq
if (null != response) {
if (response.getSOAPBody().ha
String fault = response.getSOAPBody().get
m_logger.logInfo("SOAP Fault returned: " + fault);
throw new Exception("Soap fault in response message, fault message - " + fault);
}else{
SOAPMessage[] msgs = clientKit.getMsgsFromRespo
for(SOAPMessage m : msgs) {
String msgId = m.getSOAPHeader().getEleme
m_logger.logInfo("Message ID: " + msgId);
testPullAckService(msgId);
}
}
}
}
/**
* Sample on how to call pull acknowledgement service
* @throws Exception
*/
public void testPullAckService(String msgId) throws Exception {
Map inMap = new TreeMap();
inMap.put(IMessagingConsta
SOAPMessage requestMsg = clientKit.createPullAckReq
SOAPMessage response = clientKit.sendPullAckReque
if (null != response && response.getSOAPBody().has
String fault = response.getSOAPBody().get
m_logger.logInfo("SOAP Fault returned: " + fault);
throw new Exception("Soap fault in response message, fault message - " + fault);
}
}
private void init(String propFilePath) {
try {
// Properties can be read from file
Properties propFromFile = PropertiesUtils.loadProper
clientKit = new MessagingClient(propFromFi
}
catch (Exception e) {
m_logger.logError("General
}
}
private MessagingClient clientKit = null;
private static Logger m_logger = Logger.getLogger(Messaging
}
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I have successfully completed the project and no more queries
and mention are you using desktop app or web app for java