We will create the needed classes to generate a Web Service client from its WSDL.
We will base in the HelloWorld project, and here will add the security. In this project we response with a Hello for the name which sent as argument through the Web Service.
Read the rest of this entry »
We want to intercept the WS input and output. In order to:
- Logging any part in the message
- Registering sent messages
- Add security controls
- ….
Here we are going to do a input/output WS example log.
We annotate the WS with Handler Chain descriptor:
@WebService
@HandlerChain(file="src/META-INF/handlerChain.xml")
public class Hello {
@WebMethod
public String sayHello(String name) {
return "Hello, "+name+".";
}
}
It will have the following contents:
<?xml version="1.0" encoding="UTF-8"?>
<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
<handler-chain>
<handler>
<handler-class>lebrijo.handlers.WSHandler</handler-class>
</handler>
</handler-chain>
</handler-chains>
WSHandler class will implements the SOAPHandler interface:
public class WSHandler implements SOAPHandler<SOAPMessageContext> {
public Set<QName> getHeaders() {
return null;
}
public boolean handleFault(SOAPMessageContext context) {
logToSystemOut(context);
return true;
}
public boolean handleMessage(SOAPMessageContext context) {
logToSystemOut(context);
return true;
}
private void logToSystemOut(SOAPMessageContext smc) {
Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outboundProperty.booleanValue()) {
System.out.println("Outgoing message:");
} else {
System.out.println("Incoming message:");
}
SOAPMessage message = smc.getMessage();
try {
message.writeTo(System.out);
} catch (Exception e) {
System.out.println("Exception in handler: " + e);
}
}
public void close(MessageContext context) {
// TODO Auto-generated method stub
}
In this post we are going to see how to secure a Web Service with basic HTTP Auth, in weblogic. We will base in a previous project where we created a very basic WS: Hello World.
In the Security Realm > MyRealm we have to create:
- An user: user/12345678
- A group: TutorialUser
- Add the user to the group
In the Weblogic console as we see on the picture:

In web.xml we have to add the security confs needed (path, basic type,….):
<!--
SECURITY
-->
<security-constraint>
<display-name>Regla01</display-name>
<web-resource-collection>
<web-resource-name>WSPOST</web-resource-name>
<description>
<url-pattern>/*</url-pattern>
<http-method>POST</http-method>
</description>
<auth-constraint>
<description>
<role-name>TutorialUser</role-name>
</description>
</auth-constraint>
<session-config>
<session-timeout>5</session-timeout>
</session-config>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>myrealm</realm-name>
</login-config>
<security-role>
<description>
<role-name>TutorialUser</role-name>
</description>
</security-role>
</web-resource-collection>
</security-constraint>
In weblogic.xml map the application role with server role (it is mandatory):
<wls:security-role-assignment>
<wls:role-name>TutorialUser</wls:role-name>
<wls:principal-name>TutorialUser</wls:principal-name>
</wls:security-role-assignment>
We can test with SoapUI creating a new WS project, with WSDL address (http://localhost:7001/wsc/HelloService?WSDL) and previous Weblogic credentials created:

Today we will create a SOAP Web Service, based on LebrijoSchool project which we were making in early weeks over Oracle-Weblogic Architechture.
First of all is to add the Web Services facet. Right button > Properties … :

After, we will create the class from a Spring Service class. Right button > New > WebLogic Web Service for Spring Beans:

Choose the Service, and the methods that we want to publish as Web Service.
Finally put it in the logical package: lebrijo.school.webservices. And name it as “SchoolCertificatesWS”.
This is the code:
@Autowired
@Qualifier("RegistryService")
private IRegistryService springServ;
@WebMethod
public Registry findRegistryById(java.lang.String id) throws Exception {
return springServ.findRegistryById( id );
}
We have a Weblogic client to test the WS, we can acces thru the URL http://localhost:7001/wls_utc/.
Today we are going to see ho to create a WS which says Hello over Weblogic, with its IDE Eclipse OEPE.
We will create a New project > Web Service Project:

We created teh following class:
package services;import javax.jws.*;
@WebService
public class Hello {
@WebMethod
public String sayHello(String name) {
return "Hello, "+name+".";
}
}
With these annotations we can serve the WS, and with right button on the classes and Run as > Run on Server. It launches the test WS application in the navigator:

To access to WSDL: http://localhost:7001/wsc/HelloService?WSDL
To test every WSDL published: http://localhost:7001/wls_utc/begin.do