[JBoss Web Services] - Dynamic webservice call with dispatch client using reliable messaging example
by Patrik Jetzer
Patrik Jetzer [http://community.jboss.org/people/patrik.jetzer] created the discussion
"Dynamic webservice call with dispatch client using reliable messaging example"
To view the discussion, visit: http://community.jboss.org/message/570436#570436
--------------------------------------------------------------
I'm having difficulties to find examples about adding reliable messaging functionality to the webservice client code.
The Dispatch Client is used to dynamically calling the webservice(s)
This is the way the webservice is called tried to access an example reliable messaging enabled webservice deployed on localhost:
import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.soap.SOAPBinding;
// -------------
public void sendRM() {
// String wsdlLocationString = " http://localhost:8080/SimpleWS/SimpleService?wsdl http://localhost:8080/SimpleWS/SimpleService?wsdl";
String namespace = " http://ws.example.com/ http://ws.example.com/";
String serviceName = "SimpleService";
String portName = "SimpleServicePort";
String methodName = "echoRequest";
try {
// Qnames for service as defined in wsdl.
QName serviceQName = new QName(namespace, serviceName);
// QName for Port As defined in wsdl.
QName portQName = new QName(namespace, portName);
// Endpoint Address
String endpointAddress = " http://localhost:8080/SimpleWS/SimpleService http://localhost:8080/SimpleWS/SimpleService";
// Create a dynamic Service instance
Service service = Service.create(serviceQName);
// Add a port to the Service
service.addPort(portQName, SOAPBinding.SOAP11HTTP_BINDING,
endpointAddress);
// Create a dispatch instance
Dispatch<SOAPMessage> dispatch = service.createDispatch(portQName,
SOAPMessage.class, Service.Mode.MESSAGE);
// Use Dispatch as BindingProvider
BindingProvider bp = (BindingProvider) dispatch;
// Optionally Configure RequestContext to send SOAPAction HTTP Header
Map<String, Object> rc = bp.getRequestContext();
rc.put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
rc.put(BindingProvider.SOAPACTION_URI_PROPERTY, methodName);
// Obtain a preconfigured SAAJ MessageFactory
MessageFactory factory = ((SOAPBinding) bp.getBinding()).getMessageFactory();
// Create SOAPMessage Request
SOAPMessage request = factory.createMessage();
// Request Header
SOAPHeader header = request.getSOAPHeader();
// Request Body
SOAPBody body = request.getSOAPBody();
// Compose the soap:Body payload
QName payloadName = new QName(namespace, methodName, "ns1");
SOAPBodyElement payload = body.addBodyElement(payloadName);
SOAPElement message = payload.addChildElement("input");
message.addTextNode("dummyHelloWorld");
// Invoke the endpoint synchronously
SOAPMessage reply = null;
try {
// Invoke Endpoint Operation and read response
reply = dispatch.invoke(request);
((Closeable) dispatch).close();
} catch (WebServiceException wse) {
wse.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
The dump of the soap messages show me that the reliable messaging messages are not produced.
when .invoke() method is called a
"javax.xml.ws.soap.SOAPFaultException: A required header representing a Message Addressing Property is not present"
is produced.
Env Setting:
JBossAS 4.2.2 JRE 1.6.0_20
Webservice stack jbossws-metro-3.0.5.GA
Does anybody have an example of dynamically calling a webservice with reliable messaging enabled?
Is there a link i have missed with one of my google searches?
Is there another approach i can use instead of using client Dispatch class?
I have to use the dynamical approach because i can't use the generated client artefacts produced by wsconsume/ wsimport,
since at design time it is not defined what services will be used to callback.
any help is welcomed
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/570436#570436]
Start a new discussion in JBoss Web Services at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
13 years, 6 months
[JBoss Web Services] - Problem with securing web service with ws security ( username token )
by Łukasz Marczuk
Łukasz Marczuk [http://community.jboss.org/people/lmarczuk] created the discussion
"Problem with securing web service with ws security ( username token )"
To view the discussion, visit: http://community.jboss.org/message/560597#560597
--------------------------------------------------------------
Hello,
I'am trying to secure web service ( from ejb 3.0 stateless bean) and it is not working.
here is my code :
Bean :
@Stateless
@SOAPBinding(style=SOAPBinding.Style.RPC)
@SecurityDomain("JBossWS")
@EndpointConfig(configName = "Standard WSSecurity Endpoint")
@WebService(name="Hello",targetNamespace = " http://test http://test",serviceName = "HelloWSSService")
public class HelloBean implements IHello {
@WebMethod
public String sayHello(String aName) {
return "siemanko " + aName;
}
}
// ... some imports
@Stateless
@SOAPBinding(style=SOAPBinding.Style.RPC)
@SecurityDomain("JBossWS")
@EndpointConfig(configName = "Standard WSSecurity Endpoint")
@WebService(name="Hello",targetNamespace = "http://test",serviceName = "HelloWSSService")
public class HelloBean implements IHello {
@WebMethod
public String sayHello(String aName) {
return "siemanko " + aName;
}
}
interface :
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
@EndpointConfig(configName = "Standard WSSecurity Endpoint")
@WebService(name="Hello",targetNamespace = "http://test",serviceName = "HelloWSSService")
public interface IHello {
String sayHello( String name);
}
In my META-INF folder i put jboss-wsse-server.xml file :
<jboss-ws-security xmlns="http://www.jboss.com/ws-security/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jboss.com/ws-security/config
http://www.jboss.com/ws-security/schema/jboss-ws-security_1_0.xsd">
<config>
<timestamp ttl="300"/>
<requires/>
</config>
</jboss-ws-security>
Now i deploy my app on server and i test it from SoapUI.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:test="http://test">
<soapenv:Header/>
<soapenv:Body>
<test:sayHello>
<arg0>?</arg0>
</test:sayHello>
</soapenv:Body>
</soapenv:Envelope>
And anser :
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header>
<wsse:Security env:mustUnderstand="1" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext..." xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utilit...">
<wsu:Timestamp wsu:Id="timestamp">
<wsu:Created>2010-09-06T11:41:38.621Z</wsu:Created>
<wsu:Expires>2010-09-06T11:46:38.621Z</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</env:Header>
<env:Body>
<test:sayHelloResponse xmlns:test="http://test">
<return>siemanko ?</return>
</test:sayHelloResponse>
</env:Body>
</env:Envelope>
Got any idea why i can't secure my web service like that? i tryid it on jboss 4.2.3 , 5.01, 5.1, and 6 actually i work on 5.0.1 with JBoss Web Services - Native Server 3.3.1.GA.
Mayby i'm skipping some step or jboss-wsse-server.xml is incorect ?
when i put to jboss-wsse-server.xml this :
<jboss-ws-security xmlns="http://www.jboss.com/ws-security/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jboss.com/ws-security/config
http://www.jboss.com/ws-security/schema/jboss-ws-security_1_0.xsd">
<config>
<username/>
<authenticate>
<usernameAuth/>
</authenticate>
</config>
</jboss-ws-security>
Also nothing happend and i'am albe to get response without puting principals in header.
JBossWS is good configured in login-config.xml
Please help.
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/560597#560597]
Start a new discussion in JBoss Web Services at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
13 years, 6 months