You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Rahul Dev <ra...@yahoo.com> on 2008/09/09 12:43:25 UTC
CXF inside Tomcat Servlet
Hi,
I am trying to load CXF inside my servlet. Here is what I am trying to do.
Am I doing anything wrong? Kindly advice.
Rahul
@WebService
public interface iService {
public MyStruct execute(MyStruct _MyStructObj) throws java.lang.Exception;
}
//No Annotations here...
public class iServiceWebServiceImpl implements iService {
public iServiceWebServiceImpl() {
}
@Resource
private WebServiceContext wsContext;
public MyStruct execute(MyStruct _MyStructObj) throws java.lang.Exception {
return new MyStruct();
}
}
public class MainServlet extends org.apache.cxf.transport.servlet.CXFNonSpringServlet {
.............
@Override
public void loadBus(ServletConfig servletConfig) throws ServletException {
super.loadBus(servletConfig);
Bus bus = getBus();
BusFactory.setDefaultBus(bus);
}
public void init(ServletConfig _ServletConfigObj) throws ServletException
try {
Class[] Classes = new Class[] { Class1.class, Class2.class};
if (true) {
Endpoint ep = Endpoint.publish("http://" + java.net.InetAddress.getLocalHost().getHostName() + "/myServlet/myServletWS", new iServiceWebServiceImpl());
HashMap props = new HashMap();
props.put("jaxb.additionalContextClasses", Classes);
props.put("mtom-enabled", Boolean.TRUE);
ep.setProperties(props);
} else {
Endpoint ep = Endpoint.create(new iServiceWebServiceImpl());
HashMap props = new HashMap();
props.put("jaxb.additionalContextClasses", Classes);
props.put("mtom-enabled", Boolean.TRUE);
ep.setProperties(props);
ep.publish("http://" + java.net.InetAddress.getLocalHost().getHostName() + "/myServlet/myServletWS");
}
} catch (Exception ex) {
log.fatal("CXF failed", ex);
throw new Exception(ex);
}
}
.............
}
Re: CXF inside Tomcat Servlet
Posted by Rahul Dev <ra...@yahoo.com>.
Dear Dan,
This did not work.
I tried with Endpoint.publish("/myServletWS"); and when I try to access http://localhost/myservlet/myServletWS?wsdl OR http://localhost/myServletWS?wsdl I cannot get to see the WSDL.
Is there something wrong at the way I initialize it inside the servlet? OR am I accessing it the wrong way?
Rahul
Daniel Kulp <dk...@apache.org> wrote:
When using the servlet transport, I don't think you do:
Endpoint.publish("http://" + java.net.InetAddress.getLocalHost().getHostName()
+ "/myServlet/myServletWS", new iServiceWebServiceImpl())
I think you just use the tailing part:
Endpoint.publish("/myServletWS");
as the servlet transport completely controls the rest of the URL.
Dan
On Tuesday 09 September 2008 6:43:25 am Rahul Dev wrote:
> Hi,
>
> I am trying to load CXF inside my servlet. Here is what I am trying to do.
>
> Am I doing anything wrong? Kindly advice.
> Rahul
>
>
> @WebService
> public interface iService {
>
> public MyStruct execute(MyStruct _MyStructObj) throws
> java.lang.Exception;
>
> }
>
> //No Annotations here...
> public class iServiceWebServiceImpl implements iService {
>
> public iServiceWebServiceImpl() {
> }
>
> @Resource
> private WebServiceContext wsContext;
>
> public MyStruct execute(MyStruct _MyStructObj) throws
> java.lang.Exception { return new MyStruct();
> }
> }
>
>
>
> public class MainServlet extends
> org.apache.cxf.transport.servlet.CXFNonSpringServlet {
>
> .............
>
> @Override
> public void loadBus(ServletConfig servletConfig) throws
> ServletException { super.loadBus(servletConfig);
> Bus bus = getBus();
> BusFactory.setDefaultBus(bus);
>
> }
>
>
> public void init(ServletConfig _ServletConfigObj) throws
> ServletException try {
> Class[] Classes = new Class[] { Class1.class, Class2.class};
>
> if (true) {
> Endpoint ep = Endpoint.publish("http://" +
> java.net.InetAddress.getLocalHost().getHostName() +
> "/myServlet/myServletWS", new iServiceWebServiceImpl()); HashMap props =
> new HashMap();
> props.put("jaxb.additionalContextClasses", Classes);
> props.put("mtom-enabled", Boolean.TRUE);
> ep.setProperties(props);
> } else {
> Endpoint ep = Endpoint.create(new
> iServiceWebServiceImpl()); HashMap props = new HashMap();
> props.put("jaxb.additionalContextClasses", Classes);
> props.put("mtom-enabled", Boolean.TRUE);
> ep.setProperties(props);
> ep.publish("http://" +
> java.net.InetAddress.getLocalHost().getHostName() +
> "/myServlet/myServletWS"); }
> } catch (Exception ex) {
> log.fatal("CXF failed", ex);
> throw new Exception(ex);
> }
>
> }
>
> .............
> }
--
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog
Re: CXF inside Tomcat Servlet
Posted by Daniel Kulp <dk...@apache.org>.
When using the servlet transport, I don't think you do:
Endpoint.publish("http://" + java.net.InetAddress.getLocalHost().getHostName()
+ "/myServlet/myServletWS", new iServiceWebServiceImpl())
I think you just use the tailing part:
Endpoint.publish("/myServletWS");
as the servlet transport completely controls the rest of the URL.
Dan
On Tuesday 09 September 2008 6:43:25 am Rahul Dev wrote:
> Hi,
>
> I am trying to load CXF inside my servlet. Here is what I am trying to do.
>
> Am I doing anything wrong? Kindly advice.
> Rahul
>
>
> @WebService
> public interface iService {
>
> public MyStruct execute(MyStruct _MyStructObj) throws
> java.lang.Exception;
>
> }
>
> //No Annotations here...
> public class iServiceWebServiceImpl implements iService {
>
> public iServiceWebServiceImpl() {
> }
>
> @Resource
> private WebServiceContext wsContext;
>
> public MyStruct execute(MyStruct _MyStructObj) throws
> java.lang.Exception { return new MyStruct();
> }
> }
>
>
>
> public class MainServlet extends
> org.apache.cxf.transport.servlet.CXFNonSpringServlet {
>
> .............
>
> @Override
> public void loadBus(ServletConfig servletConfig) throws
> ServletException { super.loadBus(servletConfig);
> Bus bus = getBus();
> BusFactory.setDefaultBus(bus);
>
> }
>
>
> public void init(ServletConfig _ServletConfigObj) throws
> ServletException try {
> Class[] Classes = new Class[] { Class1.class, Class2.class};
>
> if (true) {
> Endpoint ep = Endpoint.publish("http://" +
> java.net.InetAddress.getLocalHost().getHostName() +
> "/myServlet/myServletWS", new iServiceWebServiceImpl()); HashMap props =
> new HashMap();
> props.put("jaxb.additionalContextClasses", Classes);
> props.put("mtom-enabled", Boolean.TRUE);
> ep.setProperties(props);
> } else {
> Endpoint ep = Endpoint.create(new
> iServiceWebServiceImpl()); HashMap props = new HashMap();
> props.put("jaxb.additionalContextClasses", Classes);
> props.put("mtom-enabled", Boolean.TRUE);
> ep.setProperties(props);
> ep.publish("http://" +
> java.net.InetAddress.getLocalHost().getHostName() +
> "/myServlet/myServletWS"); }
> } catch (Exception ex) {
> log.fatal("CXF failed", ex);
> throw new Exception(ex);
> }
>
> }
>
> .............
> }
--
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog
CXF inside Tomcat Servlet
Posted by Rahul Dev <ra...@yahoo.com>.
Hi,
Can someone please advise me on this problem? Would be much appreciated.
I searched resources to find solutions but couldnt find any.
Regards
Rahul
Rahul Dev <ra...@yahoo.com> wrote: Hi,
I am trying to load CXF inside my servlet. Here is what I am trying to do.
Am I doing anything wrong? Kindly advice.
Rahul
@WebService
public interface iService {
public MyStruct execute(MyStruct _MyStructObj) throws java.lang.Exception;
}
//No Annotations here...
public class iServiceWebServiceImpl implements iService {
public iServiceWebServiceImpl() {
}
@Resource
private WebServiceContext wsContext;
public MyStruct execute(MyStruct _MyStructObj) throws java.lang.Exception {
return new MyStruct();
}
}
public class MainServlet extends org.apache.cxf.transport.servlet.CXFNonSpringServlet {
.............
@Override
public void loadBus(ServletConfig servletConfig) throws ServletException {
super.loadBus(servletConfig);
Bus bus = getBus();
BusFactory.setDefaultBus(bus);
}
public void init(ServletConfig _ServletConfigObj) throws ServletException
try {
Class[] Classes = new Class[] { Class1.class, Class2.class};
if (true) {
Endpoint ep = Endpoint.publish("http://" + java.net.InetAddress.getLocalHost().getHostName() + "/myServlet/myServletWS", new iServiceWebServiceImpl());
HashMap props = new HashMap();
props.put("jaxb.additionalContextClasses", Classes);
props.put("mtom-enabled", Boolean.TRUE);
ep.setProperties(props);
} else {
Endpoint ep = Endpoint.create(new iServiceWebServiceImpl());
HashMap props = new HashMap();
props.put("jaxb.additionalContextClasses", Classes);
props.put("mtom-enabled", Boolean.TRUE);
ep.setProperties(props);
ep.publish("http://" + java.net.InetAddress.getLocalHost().getHostName() + "/myServlet/myServletWS");
}
} catch (Exception ex) {
log.fatal("CXF failed", ex);
throw new Exception(ex);
}
}
.............
}