コード例 #1
0
ファイル: soap.py プロジェクト: Inkalabs/Soapbox
    def django_dispatch(request):

        from django.http import HttpResponse
        from soapbox import py2wsdl

        SOAP = service.version

        if request.method == 'GET' and 'wsdl' in request.GET:
            wsdl = py2wsdl.generate_wsdl(service)
            wsdl = etree.tostring(
                wsdl, encoding='utf-8', pretty_print=True,
                xml_declaration=True)

            return HttpResponse(wsdl, content_type='text/xml')

        try:
            xml = request.body
            envelope = SOAP.Envelope.parsexml(xml)
            message = envelope.Body.content()
            soap_action = SOAP.determin_soap_action(request)
            tagname, return_object = call_the_method(
                request, message, soap_action)
            soap_message = SOAP.Envelope.response(tagname, return_object)
            return HttpResponse(soap_message, content_type=SOAP.CONTENT_TYPE)
        except (ValueError, etree.XMLSyntaxError) as e:
            response = SOAP.get_error_response(SOAP.Code.CLIENT, str(e))
        except Exception, e:
            response = SOAP.get_error_response(SOAP.Code.SERVER, str(e))
コード例 #2
0
ファイル: service.py プロジェクト: pyj4104/FOTransBaseBE
def call_service(func, api_kwargs, context, request):
    """Wraps the request and the response, once a route does match."""
    pattern = request.matched_route.pattern
    service = request.registry['soap_services'].get(pattern)
    request.META = request.headers.environ  # to be used by soapbox, like django
    request.service = service

    SOAP = service.version

    if request.method == 'GET' and 'wsdl' in request.params:
        tree = py2wsdl.generate_wsdl(request.service)
        body = etree.tostring(tree, pretty_print=True)
        return Response(body=body, content_type=SOAP.CONTENT_TYPE)

    try:
        xml = request.body
        envelope = SOAP.Envelope.parsexml(xml)
        message = envelope.Body.content()
        soap_action = SOAP.determin_soap_action(request)
        tagname, return_object = call_the_method(service,
                                                 request, message, soap_action)
        soap_message = SOAP.Envelope.response(tagname, return_object)
        return Response(body=soap_message, content_type=SOAP.CONTENT_TYPE)
    except (ValueError, etree.XMLSyntaxError) as e:
        response = SOAP.get_error_response(SOAP.Code.CLIENT, str(e))
    except Exception, e:
        response = SOAP.get_error_response(SOAP.Code.SERVER, str(e))
コード例 #3
0
def call_service(func, api_kwargs, context, request):
    """Wraps the request and the response, once a route does match."""
    pattern = request.matched_route.pattern
    service = request.registry['soap_services'].get(pattern)
    request.META = request.headers.environ  # to be used by soapbox, like django
    request.service = service

    SOAP = service.version

    if request.method == 'GET' and 'wsdl' in request.params:
        tree = py2wsdl.generate_wsdl(request.service)
        body = etree.tostring(tree, pretty_print=True)
        return Response(body=body, content_type=SOAP.CONTENT_TYPE)

    try:
        xml = request.body
        envelope = SOAP.Envelope.parsexml(xml)
        message = envelope.Body.content()
        soap_action = SOAP.determin_soap_action(request)
        tagname, return_object = call_the_method(service, request, message,
                                                 soap_action)
        soap_message = SOAP.Envelope.response(tagname, return_object)
        return Response(body=soap_message, content_type=SOAP.CONTENT_TYPE)
    except (ValueError, etree.XMLSyntaxError) as e:
        response = SOAP.get_error_response(SOAP.Code.CLIENT, str(e))
    except Exception, e:
        response = SOAP.get_error_response(SOAP.Code.SERVER, str(e))