• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Got null response from webservice while calling an implementation method which has arguements in it

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I created one webservice using apache cxf maven and deployes in tomcat. But when I write client program if the methods has parameters in it . Those parameters have been again initialized to default values in webservice implementation . here is the code snippet kindly suggest any changes required.

studentService.java

package com.web.service;

import java.util.Date;

import javax.jws.WebMethod;
import javax.jws.WebService;

import com.web.beans.Student;
import com.web.output.studentServiceResponse;

@WebService
public interface studentService {
@WebMethod
public studentServiceResponse insertStudent(Student s);
@WebMethod
public studentServiceResponse updateStudent(Student s);
@WebMethod
public studentServiceResponse deleteStudent(Student s);
@WebMethod
public void rtriveStudent();
@WebMethod
public Date getDate();
}

studentServiceImpl.java

package com.web.service;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

import org.apache.log4j.Logger;

import com.web.beans.Student;
import com.web.db.getConnection;
import com.web.output.studentServiceResponse;

@WebService(endpointInterface="com.web.service.studentService")
public class studentServiceImpl implements studentService{


@Override
@WebMethod(operationName = "inserStudent")
public studentServiceResponse insertStudent(@WebParam(name="student") Student s) {
Connection con=null;
int rs =0;
System.out.println("In Insert student .......");
System.out.println(s);
studentServiceResponse response = new studentServiceResponse();
try{
getConnection db=new getConnection();
con=db.getDBConnection();
String Query = "INSERT INTO studentinfo VALUES("+s.getId()+",'"+s.getName()+"',"+s.getAge()+")";
PreparedStatement ps = con.prepareStatement(Query);
rs=ps.executeUpdate();
if(rs>0){
response.setMessage("Student Values are updated successfully");
}
else{
response.setMessage("Student Values are not updated successfully");
}
return response;
}
catch(Exception e){
response.setMessage("Student Values are not updated successfully");
}
finally{
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return response;
}

@Override
public studentServiceResponse updateStudent(Student s) {
Connection con=null;
int rs =0;
studentServiceResponse response = new studentServiceResponse();
try{
getConnection db=new getConnection();
con=db.getDBConnection();
String Query = "UPDATE studentinfo SET name='"+s.getName()+"',age="+s.getAge()+" WHERE id="+s.getId();
PreparedStatement ps = con.prepareStatement(Query);
rs = ps.executeUpdate();
if(rs>0){
response.setMessage("Student Values are updated successfully");
}
else{
response.setMessage("Student Values are not updated successfully");
}
return response;
}
catch(Exception e){
response.setMessage("Student Values are not updated successfully");
}
finally{
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return response;
}

@Override
public studentServiceResponse deleteStudent(Student s) {
Connection con=null;
int rs =0;
studentServiceResponse response = new studentServiceResponse();
try{
getConnection db=new getConnection();
con=db.getDBConnection();
String Query ="DELETE FROM studentinfo WHERE id="+s.getId();
System.out.println(Query);
PreparedStatement ps = con.prepareStatement(Query);
rs = ps.executeUpdate();
System.out.println("The value of Rs is :"+rs);
if(rs>0){
response.setMessage("Student Values are updated successfully");
}
else{
response.setMessage("Student Values are not updated successfully");
}
return response;
}
catch(Exception e){
response.setMessage("Student Values are not updated successfully");
}
finally{
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return response;
}

public Date getDate(){
return new Date();
}

@Override
public void rtriveStudent() {
Connection con = null;
try{
getConnection db=new getConnection();
con=db.getDBConnection();
String Query = " SELECT count(*) FROM studentinfo";
PreparedStatement ps = con.prepareStatement(Query);
int count =0;
ResultSet rs = ps.executeQuery();
while(rs.next()){
count++;
}
System.out.println("The total numbe rof records :"+count);
}
catch(Exception e){
System.out.println(e);
}
}}

appContext.xml
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:cxf="http://cxf.apache.org/core"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://cxf.apache.org/core
http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd"
default-autowire="byName">

<!-- Load CXF modules from cxf.jar -->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

<!-- Enable message logging using the CXF logging feature -->
<cxf:bus>
<cxf:features>
<cxf:logging />
</cxf:features>
</cxf:bus>

<!-- The service bean -->
<bean id="studentServiceImpl"
class="com.web.service.studentServiceImpl" />

<!-- Aegis data binding -->
<bean id="aegisBean"
class="org.apache.cxf.aegis.databinding.AegisDatabinding"
scope="prototype" />

<bean id="jaxws-and-aegis-service-factory"
class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"
scope="prototype">
<property name="dataBinding" ref="aegisBean" />
<property name="serviceConfigurations">
<list>
<bean
class="org.apache.cxf.jaxws.support.JaxWsServiceConfiguration" />
<bean
class="org.apache.cxf.aegis.databinding.AegisServiceConfiguration" />
<bean
class="org.apache.cxf.service.factory.DefaultServiceConfiguration" />
</list>
</property>
</bean>

<!-- Service endpoint -->

<jaxws:endpoint id="studentService"
implementorClass="com.web.service.studentServiceImpl"
implementor="#studentServiceImpl" address="/studentService">
<jaxws:serviceFactory>
<ref bean="jaxws-and-aegis-service-factory" />
</jaxws:serviceFactory>
</jaxws:endpoint>

</beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="services" version="2.5">

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/appContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Log4JTestServlet</servlet-name>
<servlet-class>test.Log4JTestServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>Log4JInitServlet</servlet-name>
<servlet-class>test.Log4JInitServlet</servlet-class>
<init-param>
<param-name>log4j-properties-location</param-name>
<param-value>WEB-INF/log4j.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Log4JTestServlet</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
</web-app>

I created web client using a configuration file and created client program

client.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!-- START SNIPPET: beans -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd">

<bean id="client" class="com.web.service.studentService"
factory-bean="clientFactory" factory-method="create"/>

<bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="com.web.service.studentService"/>
<property name="address" value="http://localhost:8080/studentService/services/studentService"/>
</bean>

</beans>
<!-- END SNIPPET: beans -->

ClientMain.java

package com.web.client;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.FileSystemResource;

import com.web.beans.Student;
import com.web.service.studentService;

public class clientMain {

public static void main(String[] args) {
//ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"client-beans.xml"});
BeanFactory context = new XmlBeanFactory(new FileSystemResource("src/main/java/com/web/client/client-beans.xml"));
studentService service = (studentService)context.getBean("client");
System.out.println(service.getDate());
Student student = new Student();
student.setId(2);
student.setName("Eresh");
student.setAge(25);
System.out.println(service.insertStudent(student));
//student.setId(1);
//System.out.println(service.deleteStudent(student));
//service.rtriveStudent();
}

}

In the above client program I am able to retreive date from getDate() but I am unable to process the request from insertStudent(Student s)

The out put is :
Dec, 2012 10:58:49 PM org.apache.cxf.bus.spring.BusApplicationContext getConfigResources
INFO: No cxf.xml configuration file detected, relying on defaults.
3 Dec, 2012 10:58:50 PM org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
INFO: Creating Service {http://service.web.com/}studentServiceService from class com.web.service.studentService
Mon Dec 03 22:58:50 IST 2012
studentServiceResponse [message=null]

I cannot figure out why insertStudent is unable to insert in database in service Impl class the values of student object again set to [0,null,0]

Can any one help me in correcting this , tell me where i am mistaken.

Thanks
Eresh




 
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first things first, Javaranch has taken lot of efforts to improve the user experience by providing different formatting options.So while asking question kindly make use of it, it helps in reading the question easily
example, use code block to put your code, also instead of pasting entire java file just paste the required code, for example you mention about insertStudent and getDate so there is no point in pasting deleteStudent, updateStudent etc code.

sorry for irrelevant comments but it was quite a task to read your post.

Now to answer your question, only thing I see wrong is @WebMethod(operationName = "inserStudent") has t missing in insertStudent.
if this does not fix it then there are bunch of question

1) did you see output of SoP's (System.out.println) ? you have few SoP's in insertStudent method but I don't see it in the log you pasted at the end.
2) try passing parameter to getDate method and see if its printed in service method.
3) Instead of client try SOAPUI and see it it behaves differently, this will narrow down the problem i.e if SOAPUI works correctly then server configuration is correct and something is wrong with client code and vice verse.

-P
 
Eresh Leo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Praful,
Thanks for your reply . Initially I tested using soap ui , it was working fine . But later on I created client inorder to ensure its is also behaving as per expected .

If getdate() is called without any arguement it is working fine but if i give any parameter . I just wrote an sop for that parameter in serviceImpl class . But all I got is default values like 0 for int and null for string.
As you said I corrected still the same behaviour. Still all the parameters are passed as default values assigned to wrapper or primitive what ever it is defined in the service. After generation of wsdl i tested using soap ui . There was nothing wrong in it all of logic is working fine . But client is creating problem .

regards
EResh
 
Eresh Leo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I actually figured the problem here. If I give primitive types it is accepting well and I can traverse that value to implementation method. But if I give Object in place of primitives i faced this issue. Suppose Student is a complex data type which has property fields in it . If I send Student as an arguement soap is not taking the values instead it is initilizing to their default values .

I got the error when executing client program :

INFO: Inbound Message
----------------------------
Encoding: UTF-8
Headers: {cache-control=[no-cache], content-type=[text/xml; charset=UTF-8], connection=[keep-alive], host=[localhost:8080], soapaction=[""], transfer-encoding=[chunked], accept=[*], user-agent=[Java/1.6.0_35], pragma=[no-cache]}
Messages:
Message:

Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:checkData xmlns:ns2="http://service.web.com/"><student><age>25</age><id>1</id><name>eresh</name></student></ns2:checkData></soap:Body></soap:Envelope>
--------------------------------------
5 Dec, 2012 10:14:05 AM org.apache.cxf.aegis.type.TypeUtil getReadType
WARNING: xsi:type absent, and no type available for age
5 Dec, 2012 10:14:05 AM org.apache.cxf.aegis.type.TypeUtil getReadType
WARNING: xsi:type absent, and no type available for id
5 Dec, 2012 10:14:05 AM org.apache.cxf.aegis.type.TypeUtil getReadType
WARNING: xsi:type absent, and no type available for name
5 Dec, 2012 10:14:05 AM org.apache.cxf.interceptor.LoggingOutInterceptor$LoggingCallback onClose
INFO: Outbound Message
---------------------------
Encoding: UTF-8
Headers: {SOAPAction=[""]}
Messages:
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:checkDataResponse xmlns:ns1="http://service.web.com/"><return>tested</return></ns1:checkDataResponse></soap:Body></soap:Envelope>
--------------------------------------
5 Dec, 2012 10:31:24 AM org.apache.coyote.http11.Http11Protocol pause
 
Praful Thakare
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay that narrows down the problem to client, does it still work with SOAPUI if you pass object instead of primitive type?

may be the warning message is telling something


WARNING: xsi:type absent, and no type available for age
WARNING: xsi:type absent, and no type available for id
WARNING: xsi:type absent, and no type available for name



how is it defined in wsdl as input?
 
Eresh Leo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes The problem is in client. I modified pojo class I got this in wsdl . Can you help me where I was wrong ?



All getters and setters
 
Eresh Leo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In soap Ui I didnt get any error it is processing as expected

 
Praful Thakare
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmm, nothing looks wrong but surly something is...will try to replicate your code locally over weekend (if i get time) and see whats happening.
 
Eresh Leo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm , fine . Let me know if you able to figure it out.
Thanks
Eresh
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic