Sunday, December 18, 2011

JAXB can't handle interfaces

If you get the following error:

Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions com.unicacorp.interact.api.NameValuePair is an interface, and JAXB can't handle interfaces. this problem is related to the following location:
at com.unicacorp.interact.api.NameValuePair
at public com.unicacorp.interact.api.NameValuePair[] com.singtel
.ma.rto.jaxws.GetCustomerOffers.arg6
at com.singtel.ma.rto.jaxws.GetCustomerOffershttp://www.blogger.com/img/blank.gif
com.unicacorp.interact.api.NameValuePair does not have a no-arg default construc
tor.
this problem is related to the following location:
at com.unicacorp.interact.api.NameValuePairhttp://www.blogger.com/img/blank.gif
at public com.unicacorp.interact.api.NameValuePair[] com.singtel
.ma.rto.jaxws.GetCustomerOffers.arg6
at com.singtel.ma.rto.jaxws.GetCustomerOffers


Make sure you are using the right classes (not interface). If you really need to use interface, check out this link

Adding the "@XmlJavaTypeAdapter(AnyTypeAdapter.class)" annotation to the object interface solved this problem by telling JAXB to use a special type adapter needed for interfaces. @XmlJavaTypeAdapter(AnyTypeAdapter.class) @XmlRootElement public interface MyObject { ... }
Note: The AnyTypeAdapter.java source code is very simple and can be readily found online.


Marshalling Error Encountered

It turns out that adding the AnyTypeAdapter annotation was only part of the solution. Although this annotation lets the web service start successfully, the first call to getMyObjects() resulted in a marshalling error.
INFO: Interceptor has thrown exception, unwinding noworg.apache.cxf.interceptor.Fault: Marshalling Error: class com.attivio.webservice.WebServiceTest$MyObjectImpl1 nor any of its super class is known to this context. Caused by: javax.xml.bind.MarshalException - with linked exception: [javax.xml.bind.JAXBException: class com.attivio.webservice.WebServiceTest$MyObjectImpl1 nor any of its super class is known to this context.]
The final piece of the puzzle was solved by creating a per-module interface, MyApi1, which extends MyApi and has the “@XmlSeeAlso({MyObjectImpl1.class, MyObjectImpl2.class})” annotation. By extending this interface and registering it as the endpoint class, JAXB was able to find the appropriate implementations of the MyObject interface for serialization. By putting the annotation on a module specific interface, instead of the base interface, different modules can have different objects and APIs without the need to know details of the other modules.
@WebService @XmlSeeAlso({MyObjectImpl1.class, MyObjectImpl2.class}) public interface MyApi1 extends MyApi { } public static class MyApiImpl implements MyApi1 { ... }

Tuesday, October 4, 2011

WebSphere & JAX-WS

What better for a novice like me to learn how to deploy Webservices on WebSphere than to try it using hello world.

Here's my code:

1. Web Service Endpoint Interface

/**
*
*/
package com.singtel.ma.rto;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
/**
* @author Main Masrudyn
*
*/
//Service Endpoint Interface
@WebService
public interface RTO {


@WebMethod String getHelloWorldAsString(String name);

}


2. Web Service Endpoint Implementation

package com.singtel.ma.rto;


import javax.jws.WebMethod;
import javax.jws.WebService;

//Service Implementation
@WebService(endpointInterface = "com.singtel.ma.rto.RTO")
public class RTOImpl implements RTO {

public String getHelloWorldAsString(String name) {
return "Hello World JAX-WS " + name;
}

}

3. Deploy on WebSphere, choose Detailed:


4. Ensure Deploy Webservice


5. Click on Service providers - ensure listener start




6. Check the webservice is running : http://rhel55-32.mydomain.com:9080/RTO/RTOImplService/RTOImplService.wsdl

Tuesday, September 13, 2011

WebLogic Domains, Servers, Machines and Node Managers

It's been awhile since my last post. In my current project, I need to be able to use WebLogic more effectively - that got me started on using its servers/machines functionality.

Previously, I simply created a single domain and deployed all my apps on the Admin domain. According to my tech support, this is not best practice. Since my company apps is deployed as separate war files and each war is quite memory intensive, the recommendation is to create a new server (leave the domain as what it is meant for - administrative purpose only) and deploy each app on its own server.

So how do you configure this then?

To create a Managed Server in an existing domain:

1.If you have not already done so, in the Change Center of the Administration Console, click Lock & Edit (see Use the Change Center).
2.In the left pane of the Console, select Environment > Servers.
3.In the Servers table, click New.
4.On the Create a New Server: Server Properties page:
a.Enter the name of the server in the Name field.
Each server within a domain must have a name that is unique for all configuration objects in the domain. Within a domain, each server, machine, cluster, JDBC connection pool, virtual host, and any other resource type must be named uniquely and must not use the same name as the domain.

The server name is not used as part of the URL for applications that are deployed on the server. It is for your identification purposes only. The server name displays in the Administration Console, and if you use WebLogic Server command-line utilities or APIs, you use this name to identify the server.

b.In Listen Address, if you want to limit the valid addresses for a server instance, enter an IP address or DNS name. Otherwise, URLs to the server can specify any of the host computer's IP address, any DNS name that maps to one of the IP addresses, or the localhost string.
See Configuration Options.

c.In Listen Port, enter the port number from which you want to access the server instance.
If you run multiple server instances on a single computer, each server must use its own listen port.

d.Specify whether or not this server will be a stand alone server or will belong to a cluster.
If this server is part of a cluster:

•Select an existing cluster from the drop down list.
•Select the button to create a new cluster
See Create a cluster.

e.Click Next.
f.Review the configuration options you have chosen.
g.Click Finish.
5.To activate these changes, in the Change Center of the Administration Console, click Activate Changes.
Not all changes take effect immediately—some require a restart (see Use the Change Center).


Create and configure machines to run on UNIX


A machine is the logical representation of the computer that hosts one or more WebLogic Server instances. Each managed server must be assigned to a machine.

To create and configure

1.If you have not already done so, in the Change Center of the Administration Console, click Lock & Edit (see Use the Change Center).
2.In the Administration Console, expand Environment and select Machines. The Machines table displays in the right pane showing all the machines defined in the domain.

3.Click New.
4.Enter a name for the new machine in the Name attribute field.
This name is used to identify the machine within the WebLogic Server domain. This name does not have to correspond to the machine's network name.

5.Select UNIX in the Machine OS field.
6.Click Ok. The new machine is displayed in the Machines table.

7.Select the name of the machine you just created.
8.Select the Configuration tab, then select General.
a.To specify a non-privileged user account under which the server instance runs, place a check mark in the Enable Post-bind UID field and enter the user ID in the Post-Bind UID field.
The user ID that you enter must have read, write, and execute privileges within the BEA Home directory, the WebLogic Server product directory tree, and your domain directory.

The default value of the Post-Bind UID field, nobody, is a standard UNIX account that provides the least possible privileges. While the nobody account is acceptable for use in a development environment, in a production environment, BEA recommends that you create an operating-system user account specifically for running instances of WebLogic Server. See "Securing the WebLogic Server Host."

b.To specify a non-privileged group instead of (or in addition to) providing a user ID, place a check mark in the Enable Post-bind GID field and enter the group ID in the Post-Bind GID field.
9.Select the Node Manager tab.
a.Select the Node Manager type from the drop down box in the Type field.
For more information on different Node Manager types, see Node Manager Administrator's Guide.

b.Enter the DNS name or IP address upon which Node Manager listens in the Listen Address box.
If you identify the Listen Address by IP address, you must disable Host Name Verification on Administration Servers that will access Node Manager. For more information and instructions, see "Using Hostname Verification" in Managing WebLogic Security.

c.Enter a value in the Listen Port field. This is the port where Node Manager listens for incoming requests.
d.If you have set the Type field to SSH or RSH, you should specify values in the Node Manager Home and Shell Command fields.
For more information on configuring Node Manager using SSH or RSH, see Node Manager Administrator's Guide.

10.Click Save.
11.To activate these changes, in the Change Center of the Administration Console, click Activate Changes.
Not all changes take effect immediately—some require a restart (see Use the Change Center).



Assign server instances to machines
Before you begin

Ensure you have created a machine and the Managed Server you want to add to it. For information on creating a Managed Server, see Create Managed Servers.



1.If you have not already done so, in the Change Center of the Administration Console, click Lock & Edit (see Use the Change Center).
2.In the Administration Console, expand Environment and select Servers.
3.Click the name of the server to which you wish to assign a machine.
4.Click the Configuration tab, then click General.
5.Select the machine you want to assign the server to in the Machine field.
Note: You cannot change the machine of the Administation Server using the Administration Console. You cannot change the cluster or machine of a running server.

6.Click Save.
7.To activate these changes, in the Change Center of the Administration Console, click Activate Changes.



Finally configure the username and password under the Server -> Configuration -> Server Start


Then you can start the server using ./startManagedWebLogic.sh 81Platform http://localhost:7001