Welcome, Guest. Please login or register.
Did you miss your activation email?
Pages: [1]   Go Down
  Print  
Author Topic: [Fix] SOAP Message Factory response error  (Read 2053 times)
0 Members and 1 Guest are viewing this topic.
G. Ritardo
Member
*
*

Reputation: 0
Offline Offline
Posts: 53
Referrals: 0

Awards
« on: April 30, 2009, 09:50:10 AM »

I am writing both the server and the client. The server builds the XML using JAXB marshalling and piping back to the client in the HTTP socket. From the client the request is built using the message factory and sent over the connection factory instantiation. When the response is received the SAAJ API indicates the response was bad and equals null. The client is a applet.

Error Message
Jun 29, 2008 5:01:49 PM com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection post
SEVERE: SAAJ0008: Bad Response; null
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: java.security.PrivilegedActionException: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Bad response: (-1null


Client Code
Code
GeSHi (java):
  1. SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
  2. if(connection == null)
  3. connection = soapConnectionFactory.createConnection();
  4. MessageFactory factory = MessageFactory.newInstance();
  5. SOAPMessage message = factory.createMessage();
  6. SOAPHeader header = message.getSOAPHeader();
  7. SOAPBody body = message.getSOAPBody();
  8. header.detachNode();
  9. QName bodymain = new QName("icb_xml");
  10. SOAPBodyElement mainbodyElement =  body.addBodyElement(bodymain);
  11. ...
  12. ...
  13. ...
  14. URL endpoint = new URL(serverurl);
  15. System.out.println("b");
  16. SOAPMessage response = connection.call(message, endpoint);
Created by GeSHI 1.0.7.20

Comm_log
[Client Request]>POST / HTTP/1.1
Accept: text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-Type: text/xml; charset=utf-8
Content-Length: 242
Cache-Control: no-cache
Pragma: no-cache
User-Agent: Java(tm) 2 SDK, Standard Edition v1.6.0_05 Java/1.6.0_05
Host: sjdpprojectserver.hopto.org
Connection: keep-alive

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><icb_xml><login><username>jaco</username><password>12345</password><language>English</language></login></icb_xml></SOAP-ENV:Body></SOAP-ENV:Envelope>

[Server Response]><env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"><env:Header/><env:Body><icb_xml><loginResponse><err_code>0</err_code><user_id>101</user_id></loginResponse></icb_xml></env:Body></env:Envelope>

Solution
Code
GeSHi (java):
  1. public String sendSoapLoginMessage(String usernameintput, String passwordintput) throws Exception
  2.    {      
  3.        SOAPFactory soapFactory = SOAPFactory.newInstance();
  4.        MessageFactory mf = MessageFactory.newInstance();
  5.        SOAPMessage message = mf.createMessage();
  6.        SOAPBody body = message.getSOAPBody();
  7.        // You can detach the SOAP header in this example
  8.        // msg.getSOAPHeader().detachNode();
  9.  
  10.  
  11.        Name bodyName = soapFactory.createName("icb_xml" , "sjp", serverurl);
  12.  
  13.        SOAPElement xmlElement = body.addBodyElement(bodyName);
  14.  
  15.  
  16.        Name loginName = soapFactory.createName("login");
  17.        SOAPElement loginElement = xmlElement.addChildElement(loginName);
  18.  
  19.        SOAPElement child = soapFactory.createElement("username");
  20.        child.addTextNode(usernameintput);
  21.  
  22.        loginElement.addChildElement(child);
  23.  
  24.        child = soapFactory.createElement("password");
  25.        child.addTextNode(passwordintput);
  26.  
  27.  
  28.        loginElement.addChildElement(child);
  29.  
  30.        child = soapFactory.createElement("language");
  31.        child.addTextNode(icb.language);
  32.  
  33.        loginElement.addChildElement(child);
  34.  
  35.        message.saveChanges();
  36.  
  37.        // Send the message
  38.        System.out.println("Send the SOAP message\n");
  39.  
  40.  
  41.        String server = serverurl;
  42.        String response = "";
  43.  
  44.        try
  45.        {
  46.            if(out==null)
  47.            {
  48.                if(uc == null)
  49.                {    
  50.                    u = new URL(DEFAULT_SERVER);
  51.                    uc = u.openConnection();
  52.                }
  53.  
  54.                if(urlconnection == null)
  55.                {    
  56.                    urlconnection = (HttpURLConnection) uc;
  57.                    urlconnection.setDoOutput(true);
  58.                    urlconnection.setDoInput(true);
  59.                    urlconnection.setRequestMethod("POST");
  60.                    urlconnection.setRequestProperty("SOAPAction", SOAP_ACTION);
  61.                }
  62.                out = urlconnection.getOutputStream();
  63.            }
  64.  
  65.            if(wout == null)
  66.                wout = new OutputStreamWriter(out);
  67.  
  68.            String soapmessage = printMessage(message);
  69.            wout.write(soapmessage);
  70.  
  71.            wout.flush();
  72.            //wout.close();
  73.            System.out.println(2);
  74.            if(is == null)
  75.                is = urlconnection.getInputStream();
  76.            response = readServerResponseMessage(is);
  77.            //is.close();
  78.            int sizemore = "</loginResponse>".length();
  79.            response = response.substring(response.indexOf("<loginResponse>"),response.indexOf("</loginResponse>")+sizemore);
  80.            System.out.println("[SERVER RESPONSE]"+response);
  81.        }
  82.        catch (IOException e)
  83.        {
  84.            System.err.println(e);
  85.        }
  86.        catch(Exception eb)
  87.        {
  88.            System.err.println(eb);
  89.        }        
  90.  
  91.  
  92.  
  93.       return response;
  94.    }
  95.  
  96. public void closeConnections()
  97. {
  98. try
  99. {
  100. wout.close();
  101. is.close();
  102. }
  103. catch(Exception e)
  104. {
  105. e.printStackTrace();
  106. }        
  107. }
  108.  
  109. public String readServerResponseMessage(InputStream is)
  110. {
  111. char[] readChars = new char[65000];
  112. String response = "";
  113. try
  114. {  
  115. while (br.read(readChars) != -1)
  116. {          
  117. response = new String(readChars);
  118. break;
  119.  
  120. }
  121.  
  122. }
  123. catch (IOException e)
  124. {  
  125. e.printStackTrace();
  126. }
  127. catch(Exception e)
  128. {
  129. e.printStackTrace();
  130. }
  131.  
  132. return response;
  133. }
Created by GeSHI 1.0.7.20
Logged

Founder of www.Retardation-Foundation.com :: A community for retarded people!? Powered by admin Gaylord Ritardo.
lj1987
Member
*

Reputation: 0
Offline Offline
Posts: 16
Referrals: 0

Awards
« Reply #1 on: January 15, 2010, 05:15:28 AM »


 But a healthy lifestyle goes miles in making the skin look wow young. They should be used as a

supplement only. But, one should wow power leveling not forego healthy eating habits and a disciplined

lifestyle.Exercising is a good way to make the skin breathe. Fresh blood and oxygen come to the rescue and repair the skin, making it look young and

refreshing. Water is another indispensable item for glowing skin. Skin will lose out world of warcraft gold

on the water while internal organs will lap up most of it to help in their function. This will gold in wow

result in a shortage of water in the skin, leading to wrinkles. Water is one of the best anti-aging products.Although it cannot be classified under anti-

aging products, but fasting is another way to healthy living, and thus, glowing skin. It has been medically proven that a decreased food intake results in a

drop in insulin wow gold eu and temperature levels. This in turn, leads to longevity of life. Fasting

forces the body to use its surplus fat, thus burning the calories and making the body lean and healthy.As we age, we are also more susceptible to weakened

muscle control, poorer vision and other things that can contribute to more danger. So, a wow cheap gold

thorough safety check is suggested. I recommend asking another party to perform a check to make sure all potential hazard areas are covered. Some items that

may be necessary for your added safety are grab bars for the shower/bathroom, shower chairs, walkers best wow

gold
and rollators, non-slip rugs; even some simple things such as simply replacing some light bulbs.The other product area refers to items assisting

with providing a sense of security for you and your family. Items such as patient monitors, whole house alarm systems, even an AED unit for those with heart

disease could be useful.Bottom-line, YOU wow gold cheap are your own best advocate


« Last Edit: January 15, 2010, 11:04:29 AM by HappyFace » Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Your Ad Here