Setting disableCNCheck using Grails Cxf Client Plugin - web-services

I'm trying to set disableCNCheck to true for my web service. I'm using Grails 2.2.0 with the Cxf Client plugin.
I found this question:
wsdl2java CXF command line error about disableCNCheck option
with this piece of code:
protected void disableCNCheck(Object port) {
Client client = ClientProxy.getClient(port)
TLSClientParameters params = new TLSClientParameters()
params.setDisableCNCheck(true)
HTTPConduit httpConduit = (HTTPConduit) client?.getConduit()
httpConduit?.setTlsClientParameters(params)
}
In which class would this code belong and where would the method be called? Is there a configuration parameter for the Cxf Client plugin that I could set instead?

Instead of the code you can achieve the disableCNCheck by adding the below xml config to grails-app/conf/spring/resources.xml [ Grails 2.2.3 , cxf-client plugin 1.6.1
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:http="http://cxf.apache.org/transports/http/configuration"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd
">
<http:conduit name="*.http-conduit">
<http:tlsClientParameters disableCNCheck="true" />
</http:conduit>
</beans>

Related

JAX-WS multiple endpoints Not Found: Invalid Request

I'm trying implement a web service for two endpoints and getting this error
"404 Not Found: Invalid Request" when tried accessing the service after deploying onto the apache toncat 8.
Below are my web service implementation classes, sun-jaxws.xml and web.xml
WebImplementation1.java
package com.ws.soap.services;
import javax.jws.WebService;
#WebService(endpointInterface = "com.ws.soap.services.WebServiceImpl1")
public class WebServiceImpl1 {
public String printMessage() {
return "Hello from WebServiceImpl1 ";
}
}
WebServiceImplementation2.java
package com.ws.soap.services;
import javax.jws.WebService;
#WebService(endpointInterface = "com.ws.soap.services.WebServiceImpl2")
public class WebServiceImpl2 {
public String displayMessage() {
return "Hello from WebServiceImpl2 ";
}
}
sun-jaxws.xml
<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"
version="2.0">
<endpoint name="WebServiceImpl1" implementation="com.ws.soap.services.WebServiceImpl1"
url-pattern="/impl1" />
<endpoint name="WebServiceImpl2" implementation="com.ws.soap.services.WebServiceImpl2"
url-pattern="/impl2" />
</endpoints>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>JAX-WS-Tomcat</display-name>
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>sayhello</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sayhello</servlet-name>
<url-pattern>/impl1</url-pattern>
<url-pattern>/impl2</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>
Using the exact code supplied (plus the JAX-WS RI jars downloaded from https://jax-ws.java.net/), I was able to create a webapp and successfully access the service endpoints /impl1 and /impl2. Be advised the <url-pattern> and <endpoint ... url-pattern="/impl1"> directives state the resource path to the JAX-WS endpoints within the context path of the enclosing web application.
So, if the name of the webapp is MyWebServices (MyWebServices.war with no other files/code than described in the post, deployed to Tomcat 8) and you have <url-pattern>/impl1</url-pattern> in web.xml, and with a default Tomcat instance listening on port 8080, your web service endpoint would be http://localhost:800/MyWebServices/impl1 with the WSDL available via http://localhost:800/MyWebServices/impl1?wsdl
If you want to customize your context path of your webapp (e.g. you don't want /MyWebServices/... you can use the techniques described in this SO question.
For example, my local Tomcat 8 is running on port 8081:

Web Service Consumer Anypoint Studio (CE runtime): How to pass params?

I need to pass params on Web Service/SOAP calls.
I am using Web Service Consumer in Anypoint Studio (needs run on Mule CE - Community Edition), but I received the following message: "Operation messages with more than 1 part are not supported"
Is there a form to call Web Service/SOAP on Mule CE passing params?
Thanks for any help/examples!
EDIT:
Accord comment, I am testing a calculator web service, in SoapUI return result OK, but in mule return 0.
I am passing the params with Set Payload component. I setted the value with "xml request" returned on SoapUI.
Following the XML code.
<ws:consumer-config name="Web_Service_Consumer1" wsdlLocation="http://www.dneonline.com/calculator.asmx?WSDL" service="Calculator" port="CalculatorSoap12" serviceAddress="http://www.dneonline.com/calculator.asmx" doc:name="Web Service Consumer"/>
<flow name="calculadora-soap-publicoFlow">
<poll doc:name="Poll">
<set-payload value="<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/"> <soap:Header/> <soap:Body> <tem:Add> <tem:intA>3</tem:intA> <tem:intB>2</tem:intB> </tem:Add> </soap:Body> </soap:Envelope>" doc:name="Set Payload"/>
</poll>
<ws:consumer config-ref="Web_Service_Consumer1" operation="Add" doc:name="Web Service Consumer"/>
<json:xml-to-json-transformer doc:name="XML to JSON"/>
<logger level="INFO" doc:name="Logger" message="#[message.payload]"/>
</flow>
Where could be the problem? Thanks!
I found how it works.
We need to pass Web Service Consumer it´s just params, does not full XML envelop. Following the value of the Set Payload just params:
<ns0:Add xmlns:ns0="http://tempuri.org/">
<ns0:intA>1</ns0:intA>
<ns0:intB>3</ns0:intB>
</ns0:Add>

To consume a web service with multiple input arguments in mule

I'm a beginner, I have a mule flow, in which i would like to call SOAP web service operation which has 4 input arguments
"public double calculateInterest(double principal, double year, double rate, int appid)".
I tried using a file or http endpoint where i end up in String array, or object array while using set payload.
the exception thrown is
cannot be cast to java.lang.Double. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of type: String[]
Could somebody suggest the best way to do it.
you can configure file or http inbound, write a java component (remove cxf component), extract parameters from payload, cast in the required type and call web-service method from the component.
see here is an example of a simple webservice :-
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="CE-3.3.0" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd ">
<flow name="getCalculationFlow1" doc:name="getCalculationFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="getCalculation" doc:name="HTTP"/>
<cxf:jaxws-service serviceClass="com.services.getcalculation.v1.GetCalculation" doc:name="SOAP"/>
<component class="com.services.schema.getcalculation.v1.GetCalculationImpl" doc:name="Java"/>
</flow>
</mule>
where com.services.getcalculation.v1.GetCalculation is the webservice class which is generated using Apache CXF from WSDL files and com.services.schema.getcalculation.v1.GetCalculationImpl is the implemantation class of webservice ... hope this help

set contextpath for EJB3 webservice on Weblogic 11g

I build a web service with ejb3 and maven (EAR File),code First, JAXWS, Without WSDL and without WAR, only ejb, with Eclipse, the service works in JBOSS but now i need put the service in Weblogic 11g.
With JBOSS i have the annotation
#WebContext(contextRoot="/wsManCa7", urlPattern="/manCA7WS")
But on Weblogic not, I found this link http://erikwramner.wordpress.com/2012/03/26/ejb3-web-service-context-path-in-weblogic-11g/ to create weblogic-webservices.xml and webservices.xml I put the files inside the META-INF of the jar (And JAr inside EAR) but web logic throws this error
Servlet: "WSEE_SERVLET" failed to preload on startup in Web application:
"/ManCA7". com.sun.xml.ws.server.ServerRtException: Port namespace
http://someserver.com/ManCA7 doesnt match Service namespace {1} at
com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:160) at
com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:496) at
com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:539) at
weblogic.wsee.jaxws.JAXWSDeployedServlet.getEndpoint(JAXWSDeployedServlet.java:183) at
weblogic.wsee.jaxws.JAXWSServlet.registerEndpoint(JAXWSServlet.java:138) at
weblogic.wsee.jaxws.JAXWSServlet.init(JAXWSServlet.java:67) at ....
I understand the problem is this tag
<wsdl-port xmlns:ws="http://someserver.com/ManCA7">ws:ManCA7Port</wsdl-port>
But which is the required Service namespace???
I don't know what put inside the tag :(
my webservices.xml is
<?xml version="1.0" encoding="UTF-8"?>
<webservices xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2">
<webservice-description>
<webservice-description-name>ManCA7</webservice-description-name>
<port-component>
<port-component-name>ManCA7Port</port-component-name>
<wsdl-port xmlns:ws="http://someserver.com/ManCA7">ws:ManCA7Port</wsdl-port>
<service-endpoint-interface>my.company.manCA7.sei.ManCa7SEI</service-endpoint-interface>
<service-impl-bean>
<ejb-link>ManCa7EndPoint</ejb-link>
</service-impl-bean>
</port-component>
</webservice-description>
</webservices>
And my weblogic-webservices.xml is
<?xml version = '1.0' encoding = 'UTF-8'?>
<weblogic-webservices xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-webservices
http://www.bea.com/ns/weblogic/weblogic-webservices/1.0/weblogic-webservices.xsd"
xmlns="http://www.bea.com/ns/weblogic/weblogic-webservices">
<webservice-description>
<webservice-description-name>ManCA7</webservice-description-name>
<webservice-type>JAXWS</webservice-type>
<port-component>
<port-component-name>ManCA7Port</port-component-name>
<service-endpoint-address>
<webservice-contextpath>/ManCA7</webservice-contextpath>
<webservice-serviceuri>/Mant</webservice-serviceuri>
</service-endpoint-address>
<wsdl>
<exposed>true</exposed>
</wsdl>
</port-component>
</webservice-description>
</weblogic-webservices>
And my EJB expose the service with this
#WebService(endpointInterface = "my.company.manCA7.sei.ManCa7SEI")
#TransactionManagement(TransactionManagementType.CONTAINER)
#Stateless
public class ManCa7EndPoint implements ManCa7SEI{
private final Logger logger = LoggerFactory.getLogger(ManCa7EndPoint.class);
.
.
.
I Found the Solution...
In the annotation webservice I put the same namespace of webservices.xml and worked !!
Inside webservices.xml
<wsdl-port xmlns:ws="http://someserver.com/ManCA7">ws:ManCA7Port</wsdl-port>
Inside EJB
#WebService(endpointInterface = "my.company.manCA7.sei.ManCa7SEI",targetNamespace = "http://someserver.com/ManCA7")
#TransactionManagement(TransactionManagementType.CONTAINER)
#Stateless
public class ManCa7EndPoint implements ManCa7SEI{
The solution was targetNamespace = "http://someserver.com/ManCA7"

Spring Integration inbound webservices wsdl generation

I am trying to evaluate Spring Integration specially interested in exposing a simple POJO based service into a SOAP based webservice via service activator. Currently I am stuck & have issue generating dynamic wsdl. The WSDL is not loaded & browser shows 404 error.
I try to access with the following url on my local
http://localhost:8080/ws-inbound-gateway/echoService
http://localhost:8080/ws-inbound-gateway/echoService/echoService.wsdl
Below is the configuration
inbound-gateway-config.xml
<int:channel id="inbound" />
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath" value="com.manish.schema.generated" />
</bean>
<int-ws:inbound-gateway id="empServiceGateway"
request-channel="inbound" marshaller="marshaller"
unmarshaller="marshaller" />
<int:service-activator input-channel="inbound"
requires-reply="true" ref="employeeServiceActivator" method="getEmployeeDetails">
</int:service-activator>
<bean id="employeeServiceActivator"
class="org.springframework.integration.samples.ws.EmployeeServiceResponder" />
<bean id="employeeService" class="com.manish.service.EmployeeService" />
EmployeeService is just a pojo class while EmployeeServiceResponder is a service activator that invokes method on a service class.
For dynamic wsdl generation
spring-ws-config.xml
<import resource="classpath:/META-INF/spring/integration/inbound-gateway-config.xml" />
<sws:dynamic-wsdl id="echoService" portTypeName="empServiceGateway" locationUri="/echoService" targetNamespace="http://manish.niyati.com/echo">
<sws:xsd location="/WEB-INF/echo.xsd"/>
</sws:dynamic-wsdl>
<bean
class="org.springframework.ws.server.endpoint.mapping.UriEndpointMapping">
<property name="defaultEndpoint" ref="empServiceGateway"></property>
</bean>
web.xml
<servlet>
<servlet-name>spring-ws</servlet-name>
<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/spring-ws-config.xml</param-value>
</init-param>
<init-param>
<param-name>transformWsdlLocations</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-ws</servlet-name>
<url-pattern>/echoService</url-pattern>
</servlet-mapping>
Kindly let me know what else is missing in order to make this service accessible as web-service via SI.
Also when I try to access the service from using WebService template I get the SOAPFAULT
02:18:59.436 INFO [main][org.springframework.ws.soap.saaj.SaajSoapMessageFactory] Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
02:18:59.437 DEBUG [main][org.springframework.ws.soap.saaj.SaajSoapMessageFactory] Using MessageFactory class [com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl]
02:18:59.484 DEBUG [main][org.springframework.ws.client.core.WebServiceTemplate] Opening [org.springframework.ws.transport.http.HttpUrlConnection#249fa95c] to [http://localhost:8080/ws-inbound-gateway/echoService]
02:18:59.519 TRACE [main][org.springframework.ws.soap.saaj.support.SaajUtils] SOAPElement [com.sun.xml.internal.messaging.saaj.soap.ver1_1.Envelope1_1Impl] implements SAAJ 1.3
02:18:59.535 TRACE [main][org.springframework.ws.soap.saaj.support.SaajUtils] SOAPElement [com.sun.xml.internal.messaging.saaj.soap.ver1_1.Body1_1Impl] implements SAAJ 1.3
02:18:59.562 TRACE [main][org.springframework.ws.client.MessageTracing.sent] Sent request [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><ed:employeeRequest xmlns:ed="http://manish.niyati.com/echo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ed:empid>100</ed:empid> </ed:employeeRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>]
02:18:59.604 TRACE [main][org.springframework.ws.client.MessageTracing.received] Received response [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Server</faultcode><faultstring xml:lang="en">**java.lang.NullPointerException**</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>] for request [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><ed:employeeRequest xmlns:ed="http://manish.niyati.com/echo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ed:empid>100</ed:empid> </ed:employeeRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>]
02:18:59.605 DEBUG [main][org.springframework.ws.client.core.WebServiceTemplate] Received Fault message for request [SaajSoapMessage {http://manish.niyati.com/echo}employeeRequest]
02:18:59.607 TRACE [main][org.springframework.ws.soap.saaj.support.SaajUtils] SOAPElement [com.sun.xml.internal.messaging.saaj.soap.ver1_1.Fault1_1Impl] implements SAAJ 1.3
Thanks in Advance
-MS
To get the WSDL, change the web.xml url-pattern to <url-pattern>/*</url-pattern>.
and the URL is http://localhost:8080/ws-inbound-gateway/echoService.wsdl.
Everything else looks good.
Regarding the WebServiceTemplateQuestion, what are you sending? It looks like you are using the ws sample app, which uses a WebServiceTemplate...
#Test
public void testWebServiceRequestAndResponse() {
StringResult result = new StringResult();
Source payload = new StringSource(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<echoRequest xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">hello</echoRequest>");
template.sendSourceAndReceiveToResult(WS_URI, payload, result);
logger.info("RESULT: " + result.toString());
assertThat(result.toString(), equalTo(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<echoResponse xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">hello</echoResponse>"));
}
And that works just fine.
Looks like your NPE is on the server - take a look at the server logs to see what happened.
You are doing it in a much more complex way. With a simple configuration and using some basic annotations, you can develop a web service in a short time.
I have myself used Apache CXF for web service development and it is quite good for spring based configuration. You can also take a look at this blog. It has shown all the steps with figures to develop a web service with the generation of wsdl and a client to consume the web service.