Java - ayuda con web service con rpc

 
Vista:

ayuda con web service con rpc

Publicado por Karina Edith (1 intervención) el 21/03/2013 00:59:25
hola muy buenas tardes estoy empezando con web services con rpc pero al generar el cliente apartir de un wsdl me sale este error

20/03/2013 06:08:36 PM opm.wsc.mediator.client.OPM_WSC_MEDIATOR main
GRAVE: null
error de serialización: java.lang.IllegalArgumentException: object is not an instance of declaring class
at com.sun.xml.rpc.encoding.ObjectSerializerBase.serialize(ObjectSerializerBase.java:132)
at com.sun.xml.rpc.encoding.ReferenceableSerializerImpl.serializeInstance(ReferenceableSerializerImpl.java:219)
at com.sun.xml.rpc.encoding.SOAPSerializationContext.serializeMultiRefObjects(SOAPSerializationContext.java:104)
at com.sun.xml.rpc.client.StreamingSender._writeRequest(StreamingSender.java:656)
at com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:87)
at com.sun.xml.rpc.client.dii.CallInvokerImpl.doInvoke(CallInvokerImpl.java:103)
at com.sun.xml.rpc.client.dii.BasicCall.invoke(BasicCall.java:492)
at opm.wsc.mediator.client.OPM_WSC_MEDIATOR.main(OPM_WSC_Mediator.java:91)

CAUSE:

java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.xml.rpc.encoding.ValueTypeSerializer$1.get(ValueTypeSerializer.java:104)
at com.sun.xml.rpc.encoding.GenericObjectSerializer.doSerializeInstance(GenericObjectSerializer.java:178)
at com.sun.xml.rpc.encoding.ObjectSerializerBase.serialize(ObjectSerializerBase.java:124)
at com.sun.xml.rpc.encoding.ReferenceableSerializerImpl.serializeInstance(ReferenceableSerializerImpl.java:219)
at com.sun.xml.rpc.encoding.SOAPSerializationContext.serializeMultiRefObjects(SOAPSerializationContext.java:104)
at com.sun.xml.rpc.client.StreamingSender._writeRequest(StreamingSender.java:656)
at com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:87)
at com.sun.xml.rpc.client.dii.CallInvokerImpl.doInvoke(CallInvokerImpl.java:103)
at com.sun.xml.rpc.client.dii.BasicCall.invoke(BasicCall.java:492)
at opm.wsc.mediator.client.OPM_WSC_MEDIATOR.main(OPM_WSC_Mediator.java:91)
BUILD SUCCESSFUL (total time: 3 seconds)


Este es mi codigo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import javax.xml.rpc.Call;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.Service;
import opm.wsc.mediator.dto.Request;
import opm.wsc.mediator.dto.Response;
//import opm.wsc.mediator.interfaces.OpenAPI;
import org.apache.commons.beanutils.PropertyUtils;
//import opm.wsc.mediator.interfaces.SoapMap;
//import opm.wsc.mediator.interfaces.SoapMapValue;
import opm.wsc.mediator.interfaces.*;
import opm.wsc.mediator.utils.*;
//import opm.wsc.mediator.utils.Constants;
//import opm.wsc.mediator.utils.MyPropertyUtils;
//import opm.wsc.mediator.utils.DateUtils;
 
/**
 *
 * @author QACG
 */
public class OPM_WSC_MEDIATOR {
 
    public static void main (String[] args){
        String serviceName;
        Request request;
 
        if (args.length < 1) {
            System.out.println("Falta el servicio que desea");
            System.exit(-1);
        }
        serviceName = args[0].trim();
 
        if (serviceName.equals("notification")) { // notification( msisdn, menssage)
            if(args.length > 2){
                String msisdn = args[1];
                String menssage = args[2];
                System.out.println("request de notification\n" + msisdn + "\n" + menssage );
 
                request = new Request();
 
                request.setServiceName(serviceName);
                request.setSystemDate(DateUtils.getEpochTime());
                request.setCountryCode(Constants.COUNTRY_CODE_MEXICO);
                request.setMsisdn(msisdn);
                request.setMessage(menssage);
 
                //PropertyUtils.setProperty(request, "serviceName", service);
                OPM_WSC_MEDIATOR mediator = new OPM_WSC_MEDIATOR();
                try {
                    SoapMap soapMap = mediator.getSoapMapFromRequest(request);
 
                    //System.out.println("EndPoint:" + GeneralUtils.getEndPointAddress());
                    for (SoapMapValue soapMapValue : soapMap.getValues() ) {
                        System.out.println("soapMapValue name:" + soapMapValue.getName());
                        System.out.println("soapMapValue value:" + soapMapValue.getSingleValue());
                    }
                    /* // Primer intento
                    URL url=new URL(GeneralUtils.getEndPointAddress());
                    QName qname = new QName("urn:openApi", "OpenAPIService");
                    //OpenAPIService openAPIService = new OpenAPIService_Impl();
                    Service service = Service.create(url, qname);
                    OpenAPIService openAPIService = service.getPort(OpenAPIService.class);
                    //service.
                    */
 
                    ServiceFactory factory = ServiceFactory.newInstance();
                    Service service = factory.createService(new QName("OpenAPIService"));
                    Call call = service.createCall(new QName("OpenAPI"));
                    call.setTargetEndpointAddress(GeneralUtils.getEndPointAddress());
 
                    call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true));
                    call.setProperty(Call.SOAPACTION_URI_PROPERTY, "");
                    call.setProperty("javax.xml.rpc.encodingstyle.namespace.uri", "http://schemas.xmlsoap.org/soap/encoding/");
                    QName QNAME_TYPE_SOAPMAP = new QName("http://www.w3.org/2001/XMLSchema", "impl:SoapMap");
                    call.setReturnType(QNAME_TYPE_SOAPMAP);
                    call.setOperationName(new QName("urn:openApi", "notification"));
                    call.addParameter("impl:SoapMap", QNAME_TYPE_SOAPMAP, ParameterMode.IN);
                    SoapMap parameters[] = {soapMap};
                    SoapMap result = (SoapMap)call.invoke(parameters);
                    Response response = mediator.getResponseFromSoapMap(result);
 
                    System.out.println("Response desc:" + response.getResponseDescription());
 
 
                } catch (Exception ex) {
                    Logger.getLogger(OPM_WSC_MEDIATOR.class.getName()).log(Level.SEVERE, null, ex);
                }
 
 
            } else
                System.out.println("Falta msisdn, message");
 
        } else if (serviceName.equals("getPIN")) { // getPin( msisdn, flowId, accessMethod)
            if (args.length>2){
                String msisdn=args[1];
                String flowId=args[2];
                System.out.println("request de getPIN \n"+msisdn+ "\n"+ flowId);
 
                request= new Request();
                request.setServiceName(serviceName);
                request.setSystemDate(DateUtils.getEpochTime());
                request.setCountryCode(Constants.COUNTRY_CODE_MEXICO);
                request.setMsisdn(msisdn);
                request.setFlowId(flowId);
                request.setAccessMethod(Constants.AccessMethod_SUCURSAL_BRANCH);
 
                OPM_WSC_MEDIATOR mediator = new OPM_WSC_MEDIATOR();
                try {
                    SoapMap soapMap = mediator.getSoapMapFromRequest(request);
 
                    //System.out.println("EndPoint:" + GeneralUtils.getEndPointAddress());
                    for (SoapMapValue soapMapValue : soapMap.getValues() ) {
                        System.out.println("soapMapValue name:" + soapMapValue.getName());
                        System.out.println("soapMapValue value:" + soapMapValue.getSingleValue());
                    }
 
 
                  } catch (Exception ex) {
                    Logger.getLogger(OPM_WSC_MEDIATOR.class.getName()).log(Level.SEVERE, null, ex);
                }
 
            } else
                System.out.println("Falta msisdn, flowId");
        }
 
    }
 
    /**
     * Método que genera un objeto SoapMap dado un objeto Request.
     * @param request, obejto Request que contiene la informacion necesaria para hacer una peticion a Gemalto
     * @return SoapMap, objeto que puede ser enviado a través de la peticion WSC.
     * @throws Exception 
     */
    public SoapMap getSoapMapFromRequest(Request request) throws Exception
    {
        SoapMap soapMap = new SoapMap();
 
        MyPropertyUtils myPropertyUtils = new MyPropertyUtils();
        List<String> names = myPropertyUtils.listNestedPropertyName(request);
        SoapMapValue[] soapMapValues = new SoapMapValue[names.size()];
        int i = 0;
        for (String name : names) // (int i = 0; i < names.size(); i++) // (String name : names) 
        {
            SoapMapValue soapMapValue = new SoapMapValue();
            soapMapValue.setName(name);
            soapMapValue.setSingleValue(String.valueOf(PropertyUtils.getNestedProperty(request, name)));
            soapMapValues[i++] = soapMapValue;
            //soapMap.getValues().add(soapMapValue);
 
        }
        soapMap.setValues(soapMapValues);
        return soapMap;
    }
 
    /**
     * Método que genera un objeto Response dado un objeto SoapMap.
     * @param soapMap, SoapMap que contiene la respuesta de Gemalto hacia el Switch.
     * @return Request, objeto que contiene la informacion de los valores de un objeto SoapMap.
     * @throws IllegalAccessException
     * @throws InvocationTargetException
     * @throws NoSuchMethodException 
     */
    public Response getResponseFromSoapMap(SoapMap soapMap) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
    {
        Response response = new Response();
 
        for (SoapMapValue soapMapValue : soapMap.getValues())
        {   /*
            if (soapMapValue.getName().equals("transactions"))
            {   
                System.out.println(soapMapValue.getName());
                List<SoapMap> ls  = soapMapValue.getMapArrayValue();
                for (SoapMap val : ls)
                {
                    List<SoapMapValue> lsmv = val.getValues();
                    response.setTransactions(lsmv);
                    for (SoapMapValue val2 : lsmv)
                    {
                        System.out.println(val2.getName());
//                        System.out.println(val2.getSingleValue());
                    }
                }
            }
            if (soapMapValue.getName().equals("transaction"))
            {
                System.out.println(soapMapValue.getName());
                System.out.println(soapMapValue.getSingleValue());
                List<String> ls = soapMapValue.getArrayValue();
                for (String val : ls)
                {
                    System.out.println("val");
                    System.out.println(val);
                }
            }
            else
            {
                System.out.println(soapMapValue.getName());
                System.out.println(soapMapValue.getSingleValue());
            }*/
            System.out.println(soapMapValue.getName());
            System.out.println(soapMapValue.getSingleValue());
            PropertyUtils.setProperty(response, soapMapValue.getName().trim(), soapMapValue.getSingleValue());
        }
        return response;
    }
 
}



no se que estoy haciendo mal,
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
-1
Responder

ayuda con web service con rpc

Publicado por Carlos Sanchez (1 intervención) el 09/10/2013 03:00:55
Viendo tu error, observo que simplemente tienes que comentar la linea de código donde te aparece el error(linea 91). :D espero sea de tu ayuda mi aportación.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

ayuda con web service con rpc

Publicado por Luis F. Tena (1 intervención) el 09/10/2013 03:07:46
Oye no tendras un ejemplito por aiiii.... , Soy programador en una consultora de Web Sevices te puedo ayudar ??
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

ayuda con web service con rpc

Publicado por Juan (1 intervención) el 02/12/2015 19:03:05
Hola,

La verdad es que no das mucha informacion respecto del error en especifico que deseas solucionar, por lo que concidero no es posible siquiera hacer una analsis basico de lo que necesitas.

Es una verguenza que este seudo foro www.lawebdelprogramador.com permita que se den de alta este tipo de topicos en sus foros y que no hagan revisiones continuas de los mismos.

No hay nada en que pueda ayudarte, es mejor que investigues y te pongas a estudiar del tema, y entonces formules una pregunta muchisiomo mas especifica que solo subir todo el codigo y esperar a que los demas lo hagan por ti.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar