JAXB Marshsall issue Weblogic12c - web-services

Issue
Application migration to 12c and jaxb is not working on it
Description
The application is currently on Weblogic 10 and consumes some webservices. We post the XML directly to the webservice using HttpURLConnection. Before posting we marshal the request and after receiving the response we unmarshall them
The app needs to be migrated on 12c and when we tested the app on 12c , it was not working the same. The request that was sent to the webservice had a difference.Please see below the schema, java classes and marshalled request
Refund.xsd
----------
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:avis="http://www.avis.com/XMLSchema" elementFormDefault="unqualified">
<xsd:element name="RefundRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Request" avis:usage="ups"/>
<xsd:element ref="DeliveryNumber" avis:usage="ups"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!-- Request and DeliveryNumber attributes her -->
Generated the Refund.java and related classes using Eclipse-->Generate--> JAxB classes.
am behind a firewall and in teh JAXB wizard it did ask me for a proxy. I didnt provide any poxy. Generted class
Refund.java
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "",propOrder = {
"request",
"barCodeDeliveryNumber"
})
#XmlRootElement(name = "TrackRequest")
public class RefundRequest{
#XmlElement(name = "Request", required = true)
protected Request request;
#XmlElement(name = "DeliveryNumber", required = true)
protected String deliveryNumber;
/**
* Gets the value of the request property.
*
* #return
* possible object is
* {#link Request }
*
*/
public Request getRequest() {
return request;
}
/**
* Sets the value of the request property.
*
* #param value
* allowed object is
* {#link Request }
*
*/
public void setRequest(Request value) {
this.request = value;
}
/**
* Gets the value of the DeliveryNumber property.
*
* #return
* possible object is
* {#link String }
*
*/
public String getDeliveryNumber() {
return barCodeDeliveryNumber;
}
/**
* Sets the value of the barCodeDeliveryNumber property.
*
* #param value
* allowed object is
* {#link String }
*
*/
public void setDeliveryNumber(String value) {
this.barCodeDeliveryNumber = value;
}
Am marshalling the object to XML(see below) and passing it to the web service . Web service returns "XML not well formed"
App Library
javax.annotation_1.0.jar
javax.annotation_1.1.jar
javax.persistence_1.0.0.0_1-0.jar
javax.persistence_1.0.1.0_1-0.jar
javax.xml.bind_2.0.jar
javax.xml.bind_2.1.1.jar
jaxb-api.jar
jaxb-impl.jar
jaxws-api.jar
jaxws-rt.jar
jsr181-api.jar
jsr250-api.jar
Weblogic 12c using jrockit160_29
Code Snippet
private static Marshaller mreqinfo;
JAXBContext jxcreq =JAXBContext.newInstance(RefundRequest.class.getPackage().getName());
mreqinfo=jxcreq.createMarshaller();
mreqinfo.marshall(refundRequestObj)
Looking at the logs , i could see the teh following marshalled request on weblogic 12c.
There is an xmlns:ns0="" which i think is creating the problem
**Marshalled Request - not working one when tried in weblogic 12c jrockit160_29
.**
Need to get rid of the xmlns:ns0=""
<?xml version="1.0" encoding="UTF-8"?>
<RefundRequest xmlns:ns0="">
<Request>
<TransactionReference>
<CustomerContext>YILE00010208201120.04.08.4|11/22/2013 12:28:31:085</CustomerContext>
</TransactionReference>
<RequestAction>Refund</RequestAction>
</Request>
<DeliveryNumber>974869</DeliveryNumber>
</RefundRequest>
***Marshalled Request in Weblogic 10 (existing working version in weblogic 10 jrockit160_29
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RefundRequest>
<Request>
<TransactionReference>
<CustomerContext>YILE00010208201120.04.08.4|11/22/2013 12:28:31:085</CustomerContext>
</TransactionReference>
<RequestAction>Refund</RequestAction>
</Request>
<DeliveryNumber>974869</DeliveryNumber>
</RefundRequest>

In WebLogic 12.1.1 which you are using EclipseLink JAXB (MOXy) is used as the default JAXB (JSR-222) provider (see: http://blog.bdoughan.com/2011/12/eclipselink-moxy-is-jaxb-provider-in.html). The issue that you are hitting is due to a bug that has since been fixed in the EclipseLink 2.3.3 release (current release is EclipseLink 2.5.1).
Below is a link with instructions on using a newer version of EclipseLink in WebLogic:
http://blog.bdoughan.com/2012/10/updating-eclipselink-in-weblogic.html
If you are an Oracle Support customer then you can communicate with them to request an official patch for this issue.

To fix this issue, you can add your own jaxb jars (jaxb-core.jar, jaxb-impl.jar) by overriding the jaxb jars in Weblogic 12c. You can do this by placing your own jaxb jars into your war, under WEB-INF/lib and configure the weblogic.xml by using the prefer-web-inf-classes element tag. Then place the weblogic.xml under WEB-INF directory of your war
prefer-web-inf-classes Element
The weblogic.xml Web application deployment descriptor contains a
element (a sub-element of the
element). By default, this element is set to
False. Setting this element to True subverts the classloader
delegation model so that class definitions from the Web application
are loaded in preference to class definitions in higher-level
classloaders. This allows a Web application to use its own version of
a third-party class, which might also be part of WebLogic Server.
Refer to this link for more details
http://docs.oracle.com/cd/E13222_01/wls/docs90/programming/classloading.html
weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" 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 http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:weblogic-version>12.1.</wls:weblogic-version>
<wls:container-descriptor>
<wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>
</wls:container-descriptor>
<wls:container-descriptor>
<wls:show-archived-real-path-enabled>true</wls:show-archived-real-path-enabled>
</wls:container-descriptor>
<wls:context-root>your_context_root_name</wls:context-root>

Had the same problem: JAXB placing prefixes like < ns0:TagName>.
Solved by adding prefer-application-resources to weblogic-application.xml:
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-application>
<prefer-application-resources>
<resource-name>META-INF/services/javax.xml.bind.*</resource-name>
</prefer-application-resources>
</weblogic-application>

Related

How do I set the WS-Addressing MessageId header when using CXF with Apache Camel?

I'm invoking a web service that requires WS-Addressing SOAP headers. I'm using Apache Camel with CXF to invoke the web service. When I configure the CXF endpoint with the web service's WSDL, it's smart enough to automatically add WS-Adressing SOAP headers, but I need to set a custom MessageId.
Here is the message that is currently being sent:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<ws:international xmlns:ws="http://www.w3.org/2005/09/ws-i18n">
<ws:locale xmlns:ws="http://www.w3.org/2005/09/ws-i18n">en_CA</ws:locale>
</ws:international>
<fram:user wsa:IsReferenceParameter="true" xmlns:fram="http://wsbo.webservice.ephs.pdc.ibm.com/Framework/" xmlns:wsa="http://www.w3.org/2005/08/addressing">BESTSystem</fram:user>
<Action soap:mustUnderstand="true" xmlns="http://www.w3.org/2005/08/addressing">http://webservice.ephs.pdc.ibm.com/Client/QueryHumanSubjects</Action>
<MessageID soap:mustUnderstand="true" xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:945cfd10-9fd2-48f9-80b4-ac1b9f3293c6</MessageID>
<To soap:mustUnderstand="true" xmlns="http://www.w3.org/2005/08/addressing">https://panweb5.panorama.gov.bc.ca:8081/ClientWebServicesWeb/ClientProvider</To>
<ReplyTo soap:mustUnderstand="true" xmlns="http://www.w3.org/2005/08/addressing">
<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
</ReplyTo>
</soap:Header>
<soap:Body>
<ns2:queryHumanSubjectsRequest xmlns:ns2="http://wsbo.webservice.ephs.pdc.ibm.com/Client/" xmlns:ns3="http://wsbo.webservice.ephs.pdc.ibm.com/FamilyHealth/">
<!-- stuff -->
</ns2:queryHumanSubjectsRequest>
</soap:Body>
</soap:Envelope>
As you can see, the MessageId value is "urn:uuid:945cfd10-9fd2-48f9-80b4-ac1b9f3293c6". I need to set a custom value.
I tried adding the MessageId header they way I add the other headers like "international" and "user", but some part of the framework overrides the value.
// Note this doesn't work! Something overrides the value. It works for other headers.
#Override
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn();
List<SoapHeader> headers = CastUtils.cast((List<?>) in.getHeader(Header.HEADER_LIST));
SOAPFactory sf = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
QName MESSAGE_ID_HEADER = new QName("http://www.w3.org/2005/08/addressing", "MessageID", "wsa");
SOAPElement messageId = sf.createElement(MESSAGE_ID_HEADER);
messageId.setTextContent("customValue");
SoapHeader soapHeader = new SoapHeader(MESSAGE_ID_HEADER, messageId);
headers.add(soapHeader);
}
The CXF website has some documentation on how to set WS-Addressing headers, but I don't see how to apply it to Apache Camel. The Apache Camel CXF documentation doesn't specifically mention WS-Addressing either.
The documentation links you posted actually do have the information you need, although it's not immediately obvious how to apply it to Camel.
The CXF documentation says that:
The CXF org.apache.cxf.ws.addressing.impl.AddressingPropertiesImpl object can be used to control many aspects of WS-Addressing including the Reply-To:
AddressingProperties maps = new AddressingPropertiesImpl();
EndpointReferenceType ref = new EndpointReferenceType();
AttributedURIType add = new AttributedURIType();
add.setValue("http://localhost:9090/decoupled_endpoint");
ref.setAddress(add);
maps.setReplyTo(ref);
maps.setFaultTo(ref);
((BindingProvider)port).getRequestContext()
.put("javax.xml.ws.addressing.context", maps);
Note that it sets the addressing properties on the "RequestContext".
The Apache Camel documentation says that:
How to propagate a camel-cxf endpoint’s request and response context
CXF client API provides a way to invoke the operation with request and response context. If you are using a camel-cxf endpoint producer to invoke the outside web service, you can set the request context and get response context with the following code:
CxfExchange exchange = (CxfExchange)template.send(getJaxwsEndpointUri(), new Processor() {
public void process(final Exchange exchange) {
final List<String> params = new ArrayList<String>();
params.add(TEST_MESSAGE);
// Set the request context to the inMessage
Map<String, Object> requestContext = new HashMap<String, Object>();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, JAXWS_SERVER_ADDRESS);
exchange.getIn().setBody(params);
exchange.getIn().setHeader(Client.REQUEST_CONTEXT , requestContext);
exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, GREET_ME_OPERATION);
}
});
The above example has some stuff we don't need, but the important thing is that it shows us how to set the CXF Request Context.
Put them together and you get:
#Override
public void process(Exchange exchange) throws Exception {
AttributedURIType messageIDAttr = new AttributedURIType();
messageIDAttr.setValue("customValue");
AddressingProperties maps = new AddressingProperties();
maps.setMessageID(messageIDAttr);
Map<String, Object> requestContext = new HashMap<>();
requestContext.put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, maps);
exchange.getIn().setHeader(Client.REQUEST_CONTEXT, requestContext);
}
// org.apache.cxf.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES = "javax.xml.ws.addressing.context"
// org.apache.cxf.endpoint.Client.REQUEST_CONTEXT = "RequestContext"
Warning: In my route, I invoke multiple different web services sequentially. I discovered that after setting the RequestContext as shown above, Camel started using the same RequestContext for all web services, which resulted in an error: "A header representing a Message Addressing Property is not valid and the message cannot be processed". This is because the incorrect "Action" header was used for all web service invocations after the first.
I traced this back to Apache Camel using a "RequestContext" Exchange property, separate from the header we set, which apparently takes priority over the header. If I remove this property prior to calling subsequent web services, CXF automatically fills in the correct Action header.
if your problem not solved, I suggest you to combine your cxf service with custom interceptor. it easy to work with your soap message. like this:
<bean id="TAXWSS4JOutInterceptorBean" name="TAXWSS4JOutInterceptorBean" class="com.javainuse.beans.SetDetailAnswerInterceptor " />
<cxf:cxfEndpoint id="CXFTest" address="/javainuse/learn"
endpointName="a:SOATestEndpoint" serviceName="a:SOATestEndpointService"
serviceClass="com.javainuse.SOATestEndpoint"
xmlns:a ="http://javainuse.com">
<cxf:binding>
<soap:soapBinding mtomEnabled="false" version="1.2" />
</cxf:binding>
<cxf:features>
<wsa:addressing xmlns:wsa="http://cxf.apache.org/ws/addressing"/>
</cxf:features>
<cxf:inInterceptors>
<ref bean="TAXWSS4JInInterceptorBean" />
</cxf:inInterceptors>
<cxf:inFaultInterceptors>
</cxf:inFaultInterceptors>
<cxf:outInterceptors>
<ref bean="TAXWSS4JOutInterceptorBean" />
</cxf:outInterceptors>
<cxf:outFaultInterceptors>
</cxf:outFaultInterceptors>
</cxf:cxfEndpoint>
and in the interceptor you can set soap headers like this:
public class SetDetailAnswerInterceptor extends WSS4JOutInterceptor {
public SetDetailAnswerInterceptor() {
}
#Override
public void handleMessage(SoapMessage mc) {
AttributedURIType value = new AttributedURIType();
value.setValue("test");
((AddressingProperties) mc.get("javax.xml.ws.addressing.context.outbound")).setMessageID(value);
}
}

Guvnor drools 5.5 rest api for creating model and rule asset

I am trying to create an asset in guvnor through rest api. but the asset is getting created as txt under other assets in guvnor.How can i make it rule asset or model asset. below is my code
Client client = ClientBuilder.newClient();
client.register(HttpAuthenticationFeature.basic("admin", "admin"));
client.register(MultiPartFeature.class);
final MultiPart multipart = new FormDataMultiPart();
File file = new File("C:\\assetfile.xml");
multipart.bodyPart(new FormDataBodyPart("asset",file,MediaType.APPLICATION_XML_TYPE));
final Response response = client.target("http://localhost:8080/guvnor-5.5.0.Final-tomcat-6.0/rest/packages/samplePackage/assets")
.request()
.post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE));
System.out.println(response.readEntity(String.class));
client.close();
my xml file is
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<asset>
<author>admin</author>
<description/>
<metadata>
<checkInComment/>
<disabled>false</disabled>
<format>brl<format>
<versionNumber>1</versionNumber>
</metadata>
<sourceLink>
http://localhost:8080/guvnor-5.5.0.Final-tomcat-6.0/rest/packages/samplePackage/assets/location1234/source
</sourceLink>
<title>location1234</title>
</asset>
According to https://simplesassim.wordpress.com/tag/drools-guvnor-rest-api/, it appears that you may also need to add your file content as a "binary" argument.
multipart.bodyPart(new FormDataBodyPart("asset",file,MediaType.APPLICATION_XML_TYPE));
multipart.bodyPart(new FormDataBodyPart("binary",file)); // Add this line
I hope that the above change helps.

Calling multiple WCF and asmx web services dynamically without generating proxy or using WSDL

We connect with multiple (20-30) third-party web services within our C# Batch Application. We are attempting to find the best way to call these web services dynamically (without generating proxy or using wsdl). All the third party agencies endpoints or URL's will be configured in database table. Client app will check the URL at run-time and make a service call. We are not worried about async calls it’s all synchronized process.
SQL Table : Client-configuration
Client URL Method IsActive
A http://serverhost/ClientA/Service1.svc Submit 1
B http://serverhost/ClientB/Service2.asmx Submit 1
The only issue is we are not sure about the third party service implementation is WCF or asmx. I have read few articles online to use HttpWebRequest to call web services dynamically (without generating proxies/wsdl.)
Is this the best way to implement this or any concerns I need to think of?
Please see below ex:
public static void CallWebService(string xml)
{
var _Url = "http://serverhost/ClientA/Service1.svc";
var _action = "http://serverhost/ClientA/Service1.svc/Submit";
try
{
ASCIIEncoding encoder = new ASCIIEncoding();
byte[] data = encoder.GetBytes(xml);
XmlDocument soapEnvelopeXml = CreateSoapEnvelope(xml);
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(_Url);
webRequest.Headers.Add("SOAPAction", _action);
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.ContentLength = data.Length;
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
Stream webStream = webRequest.GetRequestStream();
webStream.Write(data, 0, data.Length);
webStream.Close();
WebResponse response = webRequest.GetResponse();
Stream responseStream = response.GetResponseStream();
using (StreamReader sr = new StreamReader(responseStream))
{
string s = sr.ReadToEnd();
}
}
catch (Exception ex)
{
responseStream = ex.Response.GetResponseStream();
}
}
Here is the details shared by one of the client.
http://setup.localhost.com/ClientA/Service1.asmx
Operation : Submit
SOAP 1.1
The following is a sample SOAP 1.1 request and response. The placeholders shown need to be
replaced with actual values.
POST /ClientA/Service1.asmx HTTP/1.1
Host: setup.localhost.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://setup.localhost.com/Submit"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Submit xmlns="http://setup.localhost.com/">
<eCitXML>string</eCitXML>
<eCitPdf>base64Binary</eCitPdf>
<eCitKey>string</eCitKey>
</Submit>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<SubmitResponse xmlns="http://setup.localhost.com/">
<SubmitResult>string</SubmitResult>
</SubmitResponse>
</soap:Body>
</soap:Envelope>
SOAP 1.2
The following is a sample SOAP 1.2 request and response. The placeholders shown need to be
replaced with actual values.
POST /ClientA/Service1.asmx HTTP/1.1
Host: setup.localhost.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-
envelope">
<soap12:Body>
<Submit xmlns="http://setup.localhost.com/">
<eCitXML>string</eCitXML>
<eCitPdf>base64Binary</eCitPdf>
<eCitKey>string</eCitKey>
</Submit>
</soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-
envelope">
<soap12:Body>
<SubmitResponse xmlns="http://setup.localhost.com/">
<SubmitResult>string</SubmitResult>
</SubmitResponse>
</soap12:Body>
</soap12:Envelope>
I think your question could be rephrased as
Is there a generic method to call any SOAP 1.1 or 1.2 web service operation without prior knowledge of the service operation except for the SOAP action and URL?
I'm assuming that all the third party web services expose a common operation which accepts and returns the same types.
If this is the case then providing you model the service operation contract correctly you could use ChannelFactory to call all the services.
Calling WCF services is straightforward in this manner, but to call asmx services you'd need to do a bit more work. So your client code would need to know if the service was asmx or wcf, and moreover, if wcf, whether the service is soap 1.1 or 1.2.
I must say I'm struggling to understand what advantage you will have once you have achieved this. I can see the value if you owned all the 20+ services you were calling, but this clearly is not the case.
Granted, you won't have a ton of nasty generated service reference code, but the whole point of WSDL is it allows for machine generated service contracts. If the third party services make any breaking changes you'll need to manually synchronize these inside your client code, rather than just regenerating the client.

Camel: route1 started and consuming from: Endpoint[...] but it is not consuming

When I start camel in standalone mode I get a message that my routes are consuming from Endpoints that I have set up:
Route: route1 started and consuming from: Endpoint[http://localhost:9090/hrm/hrm_push?bindingStyle=SimpleConsumer]
Great!
But when I cut & past whats in between [] into my browser I'm getting a 404.
Surely if Camel says it is consuming at that address I should be able to use that address to contact my Rest web service.
Here is my appContext
<bean id="transformer" class="com.xxxx.portlistener.services.Transformer">
</bean>
<cxf:rsServer id="pushServer"
address="http://localhost:9090/hrm/hrm_push?bindingStyle=SimpleConsumer" >
<cxf:serviceBeans>
<ref bean="transformer" />
</cxf:serviceBeans>
</cxf:rsServer>
<cxf:rsServer id="pingServer"
address="http://localhost:9090/hrm/hrm_ping" >
<cxf:serviceBeans>
<ref bean="transformer" />
</cxf:serviceBeans>
</cxf:rsServer>
<!-- Camel Configuration -->
<camel:camelContext id="camel-1" xmlns="http://camel.apache.org/schema/spring">
<package>com.xxxx.portlistener.services</package>
<camel:route id="route1">
<camel:from uri="cxfrs://bean://pushServer"/>
<camel:to uri="log:TEST?showAll=true" />
</camel:route>
<camel:route id="route2">
<camel:from uri="cxfrs://bean://pingServer"/>
<camel:to uri="log:TEST?showAll=true" />
</camel:route>
</camel:camelContext>
My Service Interface:
#Path("/hrm/")
public interface PushService
{
/**
* trasform will change the given Object....
*/
#POST
#Produces("text/plain")
#Path("/hrm_push/")
public Response pusher(Object pushee);
#GET
#Produces("text/plain")
#Path("/hrm_ping/")
public Response ping();
}
The error from the console:
Jan 21, 2014 10:45:50 AM org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor processRequest
WARNING: No root resource matching request path / has been found.
Jan 21, 2014 10:45:51 AM org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse
WARNING: WebApplicationException has been caught : no cause is available
Can anyone spot what I'm doing wrong?
Thanks,
Andrew
You have duplicated path settings in the CXF RS bean and in the Java annotations. The two will be combined, therefore the final URL will be something like http://localhost:9090/hrm/hrm_push + "/hrm/" + "/hrm_push/" which is probably not what you wanted.
A recommendation would be to use the CXF RS bean to define the base URL only, then use the Java annotations for everything else.

I am able to write a javax.jws.WebService successfully. However I do not know exactly how to write a web service client for same in java

I have written Webservice in java which has successfully created WSDL. I am stuck in writing a webservice client for my webservice in java. I would like to use my webservice from some jsp classes. How do i do it?
#WebService
public interface AddService {
double getMultipicationResult(double M1, double M2);
}
#WebService(endpointInterface = "com.sample.AddService")
public class AddServiceImpl implements AddService {
public AddServiceImpl() {
}
#Override
public double getMultipicationResult(double M1, double M2) {
M1 = M1*M2;
return M1;
}
}
I have written the client something like :-
public class AddServiceClient {
private AddServiceClient() {
}
public static void main(String args[]){
{
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"SpringClientWebServices.xml"});
AddService client = (AddService)context.getBean("client");
double response = 0.0;
response = client.getMultipicationResult(10.0, 20.5);
}
}
and SpringClientWebServices.xml is as follows :-
<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:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="client" class="com.sample.AddService"
factory-bean="clientFactory" factory-method="create"/>
<bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="com.sample.AddService"/>
<property name="address" value="http://localhost:8080/sample/services/Addition"/>
</bean>
</beans>
I am getting exception as follows:-
Exception in thread "main" org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.apache.cxf.jaxws.JaxWsProxyFactoryBean] for bean with name 'clientFactory' defined in class path resource [SpringClientWebServices.xml]; nested exception is java.lang.ClassNotFoundException: org.apache.cxf.jaxws.JaxWsProxyFactoryBean
First of all you are missing the CXF jars as evident from the ClassNotFoundException. Please include the cxf jars.
Second regarding using the service in JSPs then you have to first initialize the Spring container via web.xml and not via main method. Use Spring MVC and implement controller which makes calls to webservice and provide data to the JSP.
If you want to consume a service directly from the JSP, consider a JavaScript client like mentioned: http://cxf.apache.org/docs/javascript-client-samples.html
I prefer to use a jar that contains the service interface and create a dynamic Spring client using CXF and Spring in a separate jar, then bring in both f those dependencies. This is also documented in the CXF site.