Link to home
Create AccountLog in
Avatar of patricktam
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.scopes.messaging.client.MessagingClient] at [wc-test-web] Exception raised in sendMessage
javax.xml.soap.SOAPException: java.net.SocketTimeoutException: connect timed out
      at hk.gov.spica_scopes.common.utils.SoapUtils.sendMessage(SoapUtils.java:810)
      at hk.gov.spica_scopes.common.client.ClientBase.sendMessageEx(ClientBase.java:229)
      at hk.gov.spica_scopes.scopes.messaging.client.MessagingClient.sendAsyncRequest(Unknown Source)
      at hk.gov.spica_scopes.scopes.messaging.client.MessagingClient.sendAsyncLargeAttachmentRequest(Unknown Source)
      at hk.gov.spica_scopes.scopes.messaging.client.MessagingClient.sendAsyncLargeAttachmentRequest(Unknown Source)
      at MessagingClientSample.testAsyncMsgServiceWithLargeAttachment(MessagingClientSample.java:66)
      at MessagingClientSample.main(MessagingClientSample.java:36)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.net.SocketTimeoutException: connect timed out
      at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
      at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
      at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
      at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
      at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
      at java.net.PlainSocketImpl.connect(Unknown Source)
      at java.net.SocksSocketImpl.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at hk.gov.spica_scopes.common.utils.SoapUtils.testConnection(SoapUtils.java:824)
      at hk.gov.spica_scopes.common.utils.SoapUtils.sendMessage(SoapUtils.java:752)
      ... 11 more
[hk.gov.spica_scopes.scopes.messaging.client.MessagingClient] at [wc-test-web] Exception raised in sendMessage
javax.xml.soap.SOAPException: java.net.SocketTimeoutException: connect timed out
      at hk.gov.spica_scopes.common.utils.SoapUtils.sendMessage(SoapUtils.java:810)
      at hk.gov.spica_scopes.common.client.ClientBase.sendMessageEx(ClientBase.java:229)
      at hk.gov.spica_scopes.scopes.messaging.client.MessagingClient.sendAsyncRequest(Unknown Source)
      at hk.gov.spica_scopes.scopes.messaging.client.MessagingClient.sendAsyncLargeAttachmentRequest(Unknown Source)
      at hk.gov.spica_scopes.scopes.messaging.client.MessagingClient.sendAsyncLargeAttachmentRequest(Unknown Source)
      at MessagingClientSample.testAsyncMsgServiceWithLargeAttachment(MessagingClientSample.java:66)
      at MessagingClientSample.main(MessagingClientSample.java:36)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.net.SocketTimeoutException: connect timed out
      at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
      at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
      at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
      at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
      at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
      at java.net.PlainSocketImpl.connect(Unknown Source)
      at java.net.SocksSocketImpl.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at hk.gov.spica_scopes.common.utils.SoapUtils.testConnection(SoapUtils.java:824)
      at hk.gov.spica_scopes.common.utils.SoapUtils.sendMessage(SoapUtils.java:752)
      ... 11 more
[hk.gov.spica_scopes.scopes.messaging.client.MessagingClient] at [wc-test-web] Exception in sendAsyncLargeAttachmentRequest
hk.gov.spica_scopes.common.exception.ApplicationException: Fail to send message
      at hk.gov.spica_scopes.common.client.ClientBase.sendMessageEx(ClientBase.java:250)
      at hk.gov.spica_scopes.scopes.messaging.client.MessagingClient.sendAsyncRequest(Unknown Source)
      at hk.gov.spica_scopes.scopes.messaging.client.MessagingClient.sendAsyncLargeAttachmentRequest(Unknown Source)
      at hk.gov.spica_scopes.scopes.messaging.client.MessagingClient.sendAsyncLargeAttachmentRequest(Unknown Source)
      at MessagingClientSample.testAsyncMsgServiceWithLargeAttachment(MessagingClientSample.java:66)
      at MessagingClientSample.main(MessagingClientSample.java:36)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: javax.xml.soap.SOAPException: java.net.SocketTimeoutException: connect timed out
      at hk.gov.spica_scopes.common.utils.SoapUtils.sendMessage(SoapUtils.java:810)
      at hk.gov.spica_scopes.common.client.ClientBase.sendMessageEx(ClientBase.java:229)
      ... 10 more
Caused by: java.net.SocketTimeoutException: connect timed out
      at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
      at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
      at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
      at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
      at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
      at java.net.PlainSocketImpl.connect(Unknown Source)
      at java.net.SocksSocketImpl.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at hk.gov.spica_scopes.common.utils.SoapUtils.testConnection(SoapUtils.java:824)
      at hk.gov.spica_scopes.common.utils.SoapUtils.sendMessage(SoapUtils.java:752)
      ... 11 more
Avatar of Tamil Arasi
Tamil Arasi
Flag of India image

can you post your code that will be easy to help to you?
and mention are you using desktop app or web app for java
Avatar of patricktam
patricktam

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.Logger;
import hk.gov.spica_scopes.common.utils.PropertiesUtils;
import hk.gov.spica_scopes.common.utils.SoapUtils;

import hk.gov.spica_scopes.scopes.messaging.client.MessagingClient;
import hk.gov.spica_scopes.scopes.messaging.client.PropertyNames;
import hk.gov.spica_scopes.scopes.messaging.types.IMessageType;
import hk.gov.spica_scopes.scopes.messaging.types.IMessagingConstants;
import hk.gov.spica_scopes.scopes.messaging.webserver.elements.testmsg.TestMsgRequest;


public class MessagingClientSample {
      
    public MessagingClientSample(String 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.testAsyncMsgServiceWithLargeAttachment(args[2]);
                  
                  if (args[0].equalsIgnoreCase("D"))
                        sample.testBatchPullService(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 testAsyncMsgServiceWithLargeAttachment(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(IMessagingConstants.RECIPIENT_APP_ID_LIST, rcptList);        
        inMap.put(IMessagingConstants.MESSAGE_TYPE, IMessageType.REQUEST);

        SOAPMessage requestMsg = SoapUtils.emptyMessage();
        TestMsgRequest request = new TestMsgRequest();
        request.setMessage("file transfer sample");
        SoapUtils.addBody(requestMsg, request);
       
        SOAPMessage response = clientKit.sendAsyncLargeAttachmentRequest(requestMsg, inMap, filePath);
       
            if (null != response && response.getSOAPBody().hasFault()) {
                  String fault = response.getSOAPBody().getFault().getFaultString();
                  
                  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(String downloadFilePath) throws Exception {
        Map inMap = new TreeMap();

        List rcptList = new Vector();
        rcptList.add("oghr1.app001");            //EGIS Messaging Service AppID of Recipient
        inMap.put(IMessagingConstants.RECIPIENT_APP_ID_LIST, rcptList);        
        inMap.put(IMessagingConstants.SENDER_APP_ID, "oghr1.app001");            //EGIS Messaging Service AppID of Sender
        inMap.put(PropertyNames.LARGE_ATTACHMENT_SUPPORT_PROPERTY, "Y");
        inMap.put(PropertyNames.LARGE_ATTACHMENT_DIR_PROPERTY, downloadFilePath);

        SOAPMessage requestMsg = clientKit.createBatchPullRequest(inMap);
        SOAPMessage response = clientKit.sendBatchPullRequest(requestMsg);
       
            if (null != response) {
                  if (response.getSOAPBody().hasFault()) {
                        String fault = response.getSOAPBody().getFault().getFaultString();
                        
                        m_logger.logInfo("SOAP Fault returned: " + fault);
                        throw new Exception("Soap fault in response message, fault message - " + fault);
                  }else{
                        SOAPMessage[] msgs = clientKit.getMsgsFromResponse(response);
                        for(SOAPMessage m : msgs) {
                              
                          String msgId = m.getSOAPHeader().getElementsByTagName("MsgId").item(0).getFirstChild().getNodeValue();
                          
                          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(IMessagingConstants.MESSAGE_ID, msgId);

        SOAPMessage requestMsg = clientKit.createPullAckRequest(inMap);
        SOAPMessage response = clientKit.sendPullAckRequest(requestMsg);
       
            if (null != response && response.getSOAPBody().hasFault()) {
                  String fault = response.getSOAPBody().getFault().getFaultString();
                  
                  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.loadPropertiesFile(propFilePath);
           
            clientKit = new MessagingClient(propFromFile);
        }

        catch (Exception e) {
            m_logger.logError("General exception raised in init", e);
        }
    }

    private MessagingClient clientKit = null;
    private static Logger m_logger = Logger.getLogger(MessagingClientSample.class);
}
ASKER CERTIFIED SOLUTION
Avatar of patricktam
patricktam

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
I have successfully completed the project and no more queries