Showing posts with label wsdl. Show all posts
Showing posts with label wsdl. Show all posts

Friday, September 9, 2011

javax.wsdl.WSDLException: no content-type: java.net.UnknownServiceException

Whe you read a WSDL from local disc, no error, but if you read a wsdl from a URL throw a exception that: 

Retrieving document at  WSDLException: faultCode=OTHER_ERROR: Unable to resolve imported document at 'http://localhost:8080/mifichero.wsdl'
no content-type: java.net.UnknownServiceException: no content-type

This error is fixed if change the  plugin reference javax.wsdl_1.5 by 
 javax.wsdl_1.6.2.v200806030405

Friday, April 29, 2011

Modificar los tipos de datos de un Wsdl por codigo.

Si quieres modificar los tipos de datos de un WSDL usa la implememtacion de la especificacion JSWDL llamada  wsdl4j

javax.wsdl.xml.WSDLWriter wsdlWriter= javax.wsdl.factory.WSDLFactory.newInstance().newWSDLWriter();

        javax.wsdl.xml.WSDLReader wsdlReader = javax.wsdl.factory.WSDLFactory.newInstance().newWSDLReader();

        Definition wsdlDefinition =(Definition) wsdlReader.readWSDL(wsdlfile);

//elimina el esquema de datos antiguo
javax.wsdl.Types type=wsdlDefinition.getTypes();

for (Object e : type.getExtensibilityElements()) {

            if (e instanceof com.ibm.wsdl.extensions.schema.SchemaImpl) {
                //schema = (com.ibm.wsdl.extensions.schema.SchemaImpl)e;
                //TODO:erase all schema
                type.getExtensibilityElements().remove(e);
                break;
            }
        }
//importa el el nuevo esquema de tipo de datos
       com.ibm.wsdl.extensions.schema.SchemaImpl schema;
          
            schema = (com.ibm.wsdl.extensions.schema.SchemaImpl) wsdlDefinition.getExtensionRegistry()
            .createExtension(javax.wsdl.Types.class, new QName("http://www.w3.org/2001/XMLSchema", "schema"));
          
            //com.ibm.wsdl.extensions.schema.SchemaImpl schema = new com.ibm.wsdl.extensions.schema.SchemaImpl();
            SchemaReference schemaReference  = new SchemaReferenceImpl();
          
            schemaReference.setSchemaLocationURI("http://localhost:8000/allTypes2.xsd");
          
            schema.addInclude(schemaReference);
            type.addExtensibilityElement(schema);
   
       
     
        wsdlDefinition.addNamespace(ns, nameSpace);
       
        File file2 = new File("newwsdl.wsdl");
        BufferedWriter output;
        try {
            output = new BufferedWriter(new FileWriter(file2));
            wsdlWriter.writeWSDL(wsdlDefinition, output);
            output.close();
           
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

Crear una estructura de Map dentro de otra

Si quieres trabajar con una estructura compleja de un Map dentro de otra, usando generic, se realiza de la siguiente manera:

//definicion
Map <javax.xml.namespace.QName , Map < javax.xml.namespace.QName,String>> mapaComplejo;
//y lo inicializamos
mapaSimple=new HashMap<javax.xml.namespace.QName,String>();
mapaSimple.put(new QName("part"),"type");
//inicializamos mapa complejo
mapaComplejo = new HashMap <javax.xml.namespace.QName , Map<javax.xml.namespace.QName,String>>();
mapaComplejo.put(msg.getQName(), mapaSimple);