WO2017008645A1 - 对http请求进行统一映射的方法和设备 - Google Patents

对http请求进行统一映射的方法和设备 Download PDF

Info

Publication number
WO2017008645A1
WO2017008645A1 PCT/CN2016/088297 CN2016088297W WO2017008645A1 WO 2017008645 A1 WO2017008645 A1 WO 2017008645A1 CN 2016088297 W CN2016088297 W CN 2016088297W WO 2017008645 A1 WO2017008645 A1 WO 2017008645A1
Authority
WO
WIPO (PCT)
Prior art keywords
http request
http
interface
request
mapping file
Prior art date
Application number
PCT/CN2016/088297
Other languages
English (en)
French (fr)
Inventor
杨思枢
Original Assignee
阿里巴巴集团控股有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 阿里巴巴集团控股有限公司 filed Critical 阿里巴巴集团控股有限公司
Publication of WO2017008645A1 publication Critical patent/WO2017008645A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs

Definitions

  • the present application relates to the field of computers, and in particular, to a technology for uniformly mapping HTTP requests.
  • the technical problem to be solved by the present application is to separate the configuration parameters of the third-party HTTP request from the logical content of the service, and how to use the separate configuration parameters to complete the HTTP request, thereby implementing HTTP in the case of improving the multiplexing rate of the configuration parameters. request.
  • the present application provides a method for uniformly mapping an HTTP request, where the method for uniformly mapping an HTTP request includes:
  • mapping file for accessing a third-party HTTP service, where the mapping file includes a configuration parameter and an encapsulation path method of the HTTP request;
  • the interface includes a plurality of interface methods, and the attributes of the interface method are in one-to-one correspondence with the attributes of the encapsulated path method of the HTTP request;
  • the dynamic proxy object is used to intercept the request, and the corresponding JAVA object is obtained according to the request, and the HTTP request base service is invoked by using a reflection mechanism. Method to complete the HTTP request.
  • configuration parameter of the HTTP request includes at least one of the following:
  • the encapsulation path method of the HTTP request includes at least one of the following:
  • mapping file includes:
  • JAVA object Generating a corresponding JAVA object according to the configuration parameter and the encapsulation path method in the mapping file, where the JAVA object includes:
  • URL object public parameter object
  • encapsulation path method object
  • mapping file includes:
  • mapping file is loaded into the memory by JAXB, and the corresponding JAVA object is generated.
  • the method for obtaining the corresponding JAVA object according to the request and calling the HTTP request basic service by using a reflection mechanism includes:
  • the JAVA object includes a URL object, a public parameter object, and an encapsulation path method object;
  • methods in calling the HTTP request base service include:
  • the attributes of the dynamic proxy annotation are the same as the attributes of the interface.
  • mapping file is an XML format file.
  • the HTTP request basic service includes a basic HTTP request method, where the basic HTTP request method includes at least one of the following:
  • the HTTP request basic service further includes a custom HTTP request method.
  • a device for uniformly mapping an HTTP request where the device includes:
  • mapping file obtaining device configured to acquire a mapping file for accessing a third-party HTTP service, where the mapping file includes a configuration parameter and an encapsulation path method of the HTTP request;
  • An interface obtaining device configured to acquire an interface for accessing a third-party HTTP service and a dynamic proxy annotation with the interface, wherein the interface includes a plurality of interface methods, and an attribute of the interface method and an encapsulation of the HTTP request One-to-one correspondence of the attributes of the path method;
  • An object generating apparatus configured to generate a JAVA object according to the mapping file, and generate a dynamic proxy object according to a dynamic proxy annotation of the corresponding interface;
  • An HTTP request execution apparatus configured to intercept the request by using the dynamic proxy object when acquiring a request to invoke an interface with a dynamic proxy annotation, and obtain a corresponding JAVA object according to the request, and utilize a reflection mechanism Invoke the method in the HTTP request base service to complete the HTTP request.
  • configuration parameter of the HTTP request includes at least one of the following:
  • the encapsulation path method of the HTTP request includes at least one of the following:
  • the object generating device is configured to:
  • JAVA object Generating a corresponding JAVA object according to the configuration parameter and the encapsulation path method in the mapping file, where the JAVA object includes:
  • URL object public parameter object
  • encapsulation path method object
  • the object generating device is configured to:
  • mapping file is loaded into the memory by JAXB, and the corresponding JAVA is generated.
  • the HTTP request execution apparatus is configured to:
  • the JAVA object includes a URL object, a public parameter object, and an encapsulation path method object;
  • the HTTP request execution apparatus is configured to:
  • the method in the HTTP request base service is invoked using reflection technology, and an HTTP call is made using the real HTTP request address.
  • the attributes of the dynamic proxy annotation are the same as the attributes of the interface.
  • mapping file is an XML format file.
  • the HTTP request basic service includes a basic HTTP request method, where the basic HTTP request method includes at least one of the following:
  • the HTTP request basic service further includes a custom HTTP request method.
  • the process of performing unified mapping on the HTTP request includes:
  • mapping file for accessing a third-party HTTP service, where the mapping file includes a configuration parameter such as a URL address, a port, and a public parameter for accessing a third-party HTTP request, an attribute of the encapsulation path method, a path, and a call thereof HTTP request base service method;
  • an interface for accessing a third-party HTTP service and its dynamic proxy annotation wherein the interface includes a plurality of interface methods, and the plurality of interface methods are in one-to-one correspondence with the names of the attributes (IDs) of the encapsulated path method in the mapping file, so as to be able to pass
  • the corresponding manner of the attribute corresponds to the mapping file from the interface
  • the attribute of the dynamic proxy annotation corresponds to the attribute of the interface
  • JAXB jackson-module-jaxb-annotations, which can use Jackson's support for JAXB annotations
  • the dynamic proxy annotation corresponding to the interface corresponding to the object is found, and a dynamic proxy object is generated according to the attribute of the dynamic proxy annotation;
  • the dynamic proxy object intercepts and reflects to the underlying HTTP request basic service, wherein the reflection process includes: obtaining the HOST object in the JAVA object; from the HOST object Obtain a URL object, obtain a path, a URL address, and a public parameter from the URL object; encapsulate the path; obtain a public parameter; encapsulate a real HTTP request address; and according to the URL address, reflect the HTTP request base service to complete an HTTP call . And use the underlying HTTP request basic service method to initiate an HTTP request and complete an HTTP request call.
  • the method and device for uniformly mapping an HTTP request obtain a mapping file for accessing a third-party HTTP service, acquire an interface corresponding to the mapping file, and inject a reflection into the interface, where
  • the mapping file separates the configuration content of the HTTP request URL address, the port, the public parameter, and the attribute of the encapsulation path method, the path, and the method in the HTTP request basic service invoked from the business logic content, and maps the file.
  • the mapping file is associated with the interface.
  • the corresponding JAVA object is generated according to the mapping file
  • the dynamic proxy object is generated according to the request of the corresponding reflection proxy corresponding to the corresponding interface.
  • the dynamic proxy object uses the JAVA object generated according to the mapping file.
  • the request is processed, and the method in the HTTP request basic service is invoked to complete the HTTP request, thereby implementing one development and multiple reuse of the mapping file, thereby implementing the HTTP request in the case of simplifying the development difficulty and increasing the reuse rate.
  • FIG. 1 is a schematic flowchart diagram of a method for uniformly mapping an HTTP request according to an aspect of the present application
  • FIG. 2 is a schematic structural diagram of an apparatus for uniformly mapping an HTTP request according to an aspect of the present application.
  • FIG. 1 is a schematic flowchart diagram of a method for uniformly mapping an HTTP request according to an aspect of the present application, where the method includes: step S11, step S12, step S13, and step S14.
  • the step S11 includes: acquiring a mapping file for accessing a third-party HTTP service, where the mapping file includes a configuration parameter and an encapsulation path method of the HTTP request; and the step S12 includes: obtaining the third-party HTTP for accessing An interface of the service and a dynamic proxy annotation with the interface, wherein the interface includes a plurality of interface methods, and attributes of the interface method are in one-to-one correspondence with attributes of the encapsulated path method of the HTTP request; the step S13 includes Generating a JAVA object according to the mapping file, and generating a dynamic proxy object according to the dynamic proxy annotation of the corresponding interface; the step S14 includes: when obtaining a request to invoke the interface with the dynamic proxy annotation, using the The dynamic proxy object intercepts the request, and obtains the corresponding JAVA object according to the request, and invokes a method in the HTTP request base service to complete the HTTP request.
  • the configuration parameter of the HTTP request includes at least one of the following: a URL address, a port, or a public parameter of the third-party HTTP service; and the encapsulation path method of the HTTP request includes at least one of the following: the encapsulation The attribute of the path method, the path, or the method name of the HTTP request base service invoked by the path method.
  • the method for uniformly mapping an HTTP request is independent of a request configuration code such as a configuration parameter and an encapsulation path method by creating a mapping file for accessing a third-party HTTP service, and the mapping file is The interfaces correspond.
  • the interface corresponding to the mapping file and the dynamic reflection proxy annotation injected by the interface are obtained, and the dynamic proxy object is generated according to the dynamic proxy annotation of the corresponding interface, and then
  • the dynamic proxy object processes the request by using a JAVA object generated according to the mapping file, and invokes a method in the HTTP request basic service to complete the HTTP request, thereby implementing a development of the mapping file, which can be developed.
  • People use it multiple times, and developers don't need to pay attention to the underlying technical implementation of HTTP, enabling HTTP request invocations while simplifying development complexity and improving development efficiency.
  • the step S11 is used to obtain a mapping file for accessing a third-party HTTP service, where the mapping file includes a configuration parameter and an encapsulation path method of the HTTP request.
  • the configuration parameter of the HTTP request includes at least one of the following: a URL address, a port, or a public parameter of the third-party HTTP service; and the encapsulation path method of the HTTP request includes at least one of the following: the encapsulation The attribute of the path method, the path, or the method name of the HTTP request base service invoked by the path method.
  • the mapping file is a mapping file, and the mapping file may subsequently load and generate a JAVA object.
  • the dynamic proxy object intercepts and uses the JAVA object to implement the HTTP request.
  • mapping file includes but is not limited to:
  • the publicParam is a public parameter (wherein, access to a third-party application, the other party generally has some mandatory parameters due to the safe consideration of all requests, some parameters are fixed , some parameters are generated when the code is dynamically run, the key is the name of the public parameter, the dynamic is used to indicate that the parameter is dynamically generated, and the Query is used to indicate that the parameter is placed in the request header.
  • the AddHeader is used to indicate that the parameter is placed in the request header
  • the className is a tool class that needs to be
  • mapping file including the content of the configuration parameters such as the URL address, the port, the public parameter, and the encapsulation path method may appear in the future. If the application can be used, it can be incorporated herein by reference.
  • the step S12 is configured to acquire an interface for accessing a third-party HTTP service and a dynamic proxy annotation with the interface, where the interface includes several interface methods, and attributes of the interface method and the HTTP The attributes of the requested encapsulation path method correspond one-to-one.
  • the interface is a channel called between the objects provided by the HTTP request calling process, and by injecting a dynamic proxy to the interface, a dynamic proxy mechanism can be provided in the HTTP request calling process to implement the successful completion of the HTTP request.
  • the specific code implementation of the interface for accessing a third-party HTTP service can be, but is not limited to:
  • the interface includes an interface method, such as newTenant, newBaseUser, and addTenantMember, and the attributes of the interface method are in one-to-one correspondence with the attributes of the id in the ⁇ url> in the mapping file of the previous example, so that the subsequent dynamic proxy according to the interface and the The one-to-one correspondence of the mapping file is reflected, wherein the input parameter of the interface method is a Map ⁇ String, Object> object, and the parameter is deserialized into a customized object according to the string returned by the HTTP.
  • an interface method such as newTenant, newBaseUser, and addTenantMember
  • the step S13 generates a JAVA object by using the mapping file acquired in the step S12.
  • the step S13 includes: generating a JAVA object according to the mapping file, and generating a dynamic proxy object according to the dynamic proxy annotation of the corresponding interface.
  • the label in the mapping file may be used by JAXB according to the mapping file.
  • JAXB is used to load the tags in the mapping file into memory and generate corresponding JAVA objects.
  • the generated JAVA object may include a URL object, a public parameter object, and an encapsulation path method object according to the configuration parameters of the mapping file and the content of the encapsulation path method.
  • the URL object includes information such as a URL address and a port
  • the public parameter object includes information such as a common parameter
  • the encapsulated path method object includes an attribute, a path, or the HTTP request invoked by the encapsulated path method.
  • Information about the method name of the underlying service is not limited to a URL address and a port
  • the public parameter object includes information such as a common parameter
  • the encapsulated path method object includes an attribute, a path, or the HTTP request invoked by the encapsulated path method.
  • the implementation code of the JAVA object that generates the mapping file can be, but is not limited to:
  • the publicParams corresponds to a ⁇ publicParams> (public parameter) tag in the mapping file
  • the urls corresponds to a ⁇ urls> tag (encapsulation path method) in the mapping file.
  • the name (URL object) pair uses ⁇ hostname> (URL) in the mapping file.
  • the step S14 includes: when the request for invoking the interface with the dynamic proxy annotation is obtained, intercepting the request by using the dynamic proxy object, and acquiring the corresponding JAVA object according to the request, and utilizing The reflection mechanism invokes methods in the HTTP request base service to complete the HTTP request.
  • step S14 is used to acquire the JAVA object generated in step S13 by using the dynamic proxy object interception service generated in step S13 to intercept the interface containing the dynamic proxy annotation during the execution of the HTTP request, and use the reflection mechanism to call HTTP requests the methods in the underlying service to complete the HTTP request.
  • the step S14 uses the reflection mechanism to invoke the method in the HTTP request basic service to complete the HTTP request, and specifically includes: acquiring the JAVA object according to the request, wherein the JAVA object includes a URL object, a public parameter object, and an encapsulation path. a method object; obtaining a URL address from the URL object, obtaining a public parameter from the public parameter object, and obtaining a path from the encapsulated path method object; encapsulating the public parameter and the path with a true HTTP request address Calling the method in the HTTP request base service to complete an HTTP call using the real HTTP request address.
  • JAXB jackson-module-jaxb-annotations, which can be implemented using Jackson's support for JAXB annotations
  • the dynamic proxy annotation corresponding to the interface corresponding to the object is found, and a dynamic proxy object is generated according to the attribute of the dynamic proxy annotation;
  • the dynamic proxy object intercepts and reflects to the underlying HTTP request basic service, wherein the reflection process includes: obtaining the HOST object in the JAVA object; from the HOST object Obtain a URL object, obtain a path, a URL address, and a public parameter from the URL object; encapsulate the path; obtain a public parameter; encapsulate a real HTTP request address; and according to the URL address, reflect the HTTP request base service to complete an HTTP call And use the underlying HTTP request base service method to initiate an HTTP request and complete an HTTP request call.
  • the reflection process includes: obtaining the HOST object in the JAVA object; from the HOST object Obtain a URL object, obtain a path, a URL address, and a public parameter from the URL object; encapsulate the path; obtain a public parameter; encapsulate a real HTTP request address; and according to the URL address, reflect the HTTP request base service to complete an HTTP call And use the underlying HTTP request base service method to initiate an HTTP request and complete an HTTP request call.
  • code implementation that invokes the HTTP request base service to complete an HTTP call may be, but is not limited to, the following:
  • the HTTP request basic service includes a basic HTTP request method, where the basic HTTP The request method includes at least one of the following:
  • POST A method by which the requesting server accepts the specified document as a new dependent entity to the identified URI;
  • PUT A method of replacing the contents of a specified document with data transmitted from the client to the server;
  • DELETE The method of requesting the server to delete the specified page.
  • HTTP request basic service may also include other HTTP request methods, such as HEAD, OPTIONS, TRACE, CONNECT, etc.
  • HTTP request method may also be defined by the developer, and will not be described herein.
  • the implementation code of the HTTP request base service may be, but is not limited to, the following:
  • the framework for uniformly mapping the HTTP request may be created, including: creating a mapping file for accessing a third-party HTTP service, where the mapping file includes the configuration. a parameter and encapsulation path method, wherein the configuration parameter includes a URL address, a port, and a public parameter of the third-party HTTP service; the encapsulation path method includes: an attribute of the encapsulation path method, a path, and the HTTP request base invoked by the method The method name of the service.
  • an interface for accessing a third-party HTTP service is created at the application layer, where the interface includes a plurality of interface methods, and the interface methods are in one-to-one correspondence with the attributes (ID) of the encapsulated path method in the mapping file, so as to be able to pass the attribute
  • the corresponding mode corresponds to the mapping file from the interface; at the application layer, the dynamic proxy annotation is injected into the interface, and the attributes of the dynamic proxy annotation correspond to the attributes of the interface.
  • the parameters and the URL are logically spliced; the HTTP request basic service is created at the bottom layer, and the method in the HTTP request basic service includes basic HTTP requests: GET, POST, PUT, and DELETE, in addition, You can also customize HTTP requests based on user needs.
  • the process of performing unified mapping on the HTTP request includes:
  • the dynamic proxy annotation corresponding to the interface corresponding to the object is found, and a dynamic proxy object is generated according to the attribute of the dynamic proxy annotation;
  • the dynamic proxy object intercepts and reflects to the underlying HTTP request basic service, wherein the reflection process includes: obtaining the JAVA object; obtaining the URL from the JAVA object An object, a public parameter object, and an encapsulation path method object, obtain a URL address from the URL object, obtain a public parameter from the public parameter object, and obtain a path from the encapsulation path method object; encapsulate the path; acquire a public parameter; Encapsulating a real HTTP request address; according to the URL address, the call invokes the HTTP request base service to complete an HTTP call. And use the underlying HTTP request basic service method to initiate an HTTP request and complete an HTTP request call.
  • the device 1 includes: a mapping file acquiring apparatus 11, an interface obtaining apparatus 12, an object generating apparatus 13, and an HTTP request execution.
  • Device 14 includes: a mapping file acquiring apparatus 11, an interface obtaining apparatus 12, an object generating apparatus 13, and an HTTP request execution.
  • the mapping file obtaining device 11 is configured to obtain a mapping file for accessing a third-party HTTP service, where the mapping file includes a configuration parameter and an encapsulation path method of the HTTP request, and the interface obtaining device 12 is configured to obtain a third-party for accessing the third party.
  • An interface of the HTTP service and a dynamic proxy annotation with the interface wherein the interface includes a plurality of interface methods, and attributes of the interface method are in one-to-one correspondence with attributes of the encapsulated path method of the HTTP request;
  • the object generating apparatus 13 Generating a JAVA object according to the mapping file, and generating a dynamic proxy object according to a dynamic proxy annotation of the corresponding interface;
  • the HTTP request execution device 14 is configured to use when a request for an interface with a dynamic proxy annotation is obtained
  • the dynamic proxy object intercepts the request, and obtains the corresponding JAVA object according to the request, and invokes a method in the HTTP request base service by using a reflection mechanism to complete the HTTP request.
  • the configuration parameter of the HTTP request includes at least one of the following: a URL address, a port, or a public parameter of the third-party HTTP service; and the encapsulation path method of the HTTP request includes at least one of the following: the encapsulation The attribute of the path method, the path, or the method name of the HTTP request base service invoked by the path method.
  • the device 1 includes an automatic calculation and a numerical calculation according to an instruction set or stored in advance.
  • Electronic devices for information processing including but not limited to microprocessors, application specific integrated circuits (ASICs), programmable gate arrays (FPGAs), digital processors (DSPs), embedded devices, and the like.
  • the network device includes, but is not limited to, a computer, a network host, a single network server, a plurality of network server sets, or a plurality of servers; wherein the cloud is composed of a large number of computers or network servers based on Cloud Computing Among them, cloud computing is a kind of distributed computing, a virtual supercomputer composed of a group of loosely coupled computers.
  • the network includes, but is not limited to, the Internet, a wide area network, a metropolitan area network, a local area network, a VPN network, a wireless ad hoc network (Ad Hoc network), and the like.
  • the device 1 may further include a script program running on the user equipment, the network device, or a device formed by integrating the user equipment and the network device, or a combination of the script program and the electronic device.
  • a script program running on the user equipment, the network device, or a device formed by integrating the user equipment and the network device, or a combination of the script program and the electronic device.
  • the method for uniformly mapping an HTTP request is independent of a request configuration code such as a configuration parameter and an encapsulation path method by creating a mapping file for accessing a third-party HTTP service, and the mapping file is The interfaces correspond.
  • the interface corresponding to the mapping file and the dynamic reflection proxy annotation injected by the interface are obtained, and the dynamic proxy object is generated according to the dynamic proxy annotation of the corresponding interface, and then
  • the dynamic proxy object processes the request by using a JAVA object generated according to the mapping file, and invokes a method in the HTTP request basic service to complete the HTTP request, thereby implementing a development of the mapping file, which can be developed.
  • People use it multiple times, and developers don't need to pay attention to the underlying technical implementation of HTTP, enabling HTTP request invocations while simplifying development complexity and improving development efficiency.
  • the mapping file obtaining apparatus 11 is configured to acquire a mapping file for accessing a third-party HTTP service, where the mapping file includes a configuration parameter of an HTTP request and an encapsulation path method.
  • the configuration parameter of the HTTP request includes at least one of the following: a URL address, a port, or a public parameter of the third-party HTTP service; and the encapsulation path method of the HTTP request includes at least one of the following: the encapsulation The attribute of the path method, the path, or the method name of the HTTP request base service invoked by the path method.
  • the mapping file is an XML file, and the XML file may be subsequently loaded and generated by a JAVA object.
  • the dynamic proxy object intercepts and uses the JAVA object to implement the HTTP request.
  • the publicParam is a public parameter (wherein, access to a third-party application, the other party generally has some mandatory parameters due to the safe consideration of all requests, some parameters are fixed , some parameters are generated when the code is dynamically run, the key is the name of the public parameter, the dynamic is used to indicate that the parameter is dynamically generated, and the Query is used to indicate that the parameter is placed in the request header.
  • the AddHeader is used to indicate that the parameter is placed in the request header
  • the className is a tool class that needs to be
  • the id is used to indicate that each business method corresponds to a different unique identifier (this must be the same as the method name of the defined service interface, and the program is reflected by this), and the path is used to describe different services.
  • the path address which is the name of the method used to call the underlying HTTP request base service.
  • mapping file including the content of the configuration parameters such as the URL address, the port, the public parameter, and the encapsulation path method may appear in the future. If the application can be used, it can be incorporated herein by reference.
  • the interface obtaining apparatus 12 acquires an interface for accessing a third-party HTTP service and a dynamic proxy annotation with the interface, wherein the interface includes a plurality of interface methods, and attributes of the interface method are The attributes of the encapsulated path method of the HTTP request correspond one-to-one.
  • the interface is a channel called between the objects provided by the HTTP request calling process, and by injecting a dynamic proxy to the interface, a dynamic proxy mechanism can be provided in the HTTP request calling process to implement the successful completion of the HTTP request.
  • the specific code implementation of the interface for accessing a third-party HTTP service can be, but is not limited to:
  • the interface includes an interface method, such as newTenant, newBaseUser, and addTenantMember, and the attributes of the interface method are in one-to-one correspondence with the attributes of the id in the ⁇ url> in the mapping file of the previous example, so that the subsequent dynamic proxy according to the interface and the The one-to-one correspondence of the mapping file is reflected, wherein the input parameter of the interface method is a string in the form of a Map ⁇ String, Object> object returned from HTTP, and the parameter returned from the HTTP is serialized into a string.
  • the defined object is a string in the form of a Map ⁇ String, Object> object returned from HTTP, and the parameter returned from the HTTP is serialized into a string.
  • the object generation device 13 generates a JAVA object from the mapping file acquired by the interface acquisition device 12.
  • the object generating apparatus 13 includes: generating a JAVA object according to the mapping file, and generating a dynamic proxy object according to a dynamic proxy annotation of the corresponding interface.
  • the tags in the mapping file may be loaded into the memory by JAXB and the corresponding JAVA objects are generated.
  • the generated JAVA object may include a URL object, a public parameter object, and an encapsulation path method object according to the configuration parameters of the mapping file and the content of the encapsulation path method.
  • the URL object includes information such as a URL address and a port
  • the public parameter object includes a public parameter.
  • the information such as the encapsulation path method object includes information of the attribute of the encapsulation path method, the path, or the method name of the HTTP request base service invoked by the encapsulation path method.
  • the implementation code of the JAVA object that generates the mapping file can be, but is not limited to:
  • the publicParams corresponds to a ⁇ publicParams> (public parameter) tag in the mapping file
  • the urls corresponds to a ⁇ urls> tag (encapsulation path method) in the mapping file.
  • the name (URL object) pair uses ⁇ hostname> (URL) in the mapping file.
  • the HTTP request execution apparatus 14 includes, when a request for invoking an interface having a dynamic proxy annotation is acquired, intercepting the request by using the dynamic proxy object, and acquiring the corresponding JAVA object according to the request, And use the reflection mechanism to call the method in the HTTP request base service to complete the HTTP request.
  • the HTTP request execution device 14 is configured to use the dynamic proxy object interception service generated in the HTTP request execution device 13 to make a call to the interface containing the dynamic proxy annotation during the execution of the HTTP request, and acquire the HTTP request execution device 13 to generate The JAVA object, and uses the reflection mechanism to call the methods in the HTTP request base service to complete the HTTP request.
  • the HTTP request execution apparatus 14 specifically includes: acquiring the JAVA object according to the request, wherein the JAVA object includes a URL object, a public parameter object, and an encapsulation path method object; and obtaining a URL address from the URL object Obtaining a public parameter from the public parameter object, and obtaining a path from the encapsulated path method object; encapsulating the public parameter and the path with a true HTTP request address; calling an HTTP request base service method, using the The actual HTTP request address completes an HTTP call.
  • the HTTP request execution device 14 invokes a subunit of the method in the HTTP request base service using a reflection technique.
  • JAXB jackson-module-jaxb-annotations, which can be implemented using Jackson's support for JAXB annotations.
  • the label in the mapping file is loaded into the memory to generate the corresponding JAVA object;
  • the dynamic proxy annotation corresponding to the interface corresponding to the object is found, and a dynamic proxy object is generated according to the attribute of the dynamic proxy annotation;
  • the dynamic proxy object intercepts and reflects to the underlying HTTP request basic service, wherein the reflection process includes: obtaining the HOST object in the JAVA object; from the HOST object Obtain a URL object, obtain a path, a URL address, and a public parameter from the URL object; encapsulate the path; obtain a public parameter; encapsulate a real HTTP request address; and according to the URL address, reflect the HTTP request base service to complete an HTTP call And use the underlying HTTP request base service method to initiate an HTTP request and complete an HTTP request call.
  • the reflection process includes: obtaining the HOST object in the JAVA object; from the HOST object Obtain a URL object, obtain a path, a URL address, and a public parameter from the URL object; encapsulate the path; obtain a public parameter; encapsulate a real HTTP request address; and according to the URL address, reflect the HTTP request base service to complete an HTTP call And use the underlying HTTP request base service method to initiate an HTTP request and complete an HTTP request call.
  • the HTTP request execution device 14 reflects the call to the HTTP request base service, and the code implementation of completing an HTTP call may be, but is not limited to, the following:
  • the HTTP request basic service includes a basic HTTP request method, where the basic HTTP request method includes at least one of the following:
  • POST A method by which the requesting server accepts the specified document as a new dependent entity to the identified URI;
  • PUT A method of replacing the contents of a specified document with data transmitted from the client to the server;
  • DELETE The method of requesting the server to delete the specified page.
  • HTTP request basic service may also include other HTTP request methods, such as HEAD, OPTIONS, TRACE, CONNECT, etc.
  • HTTP request method may also be defined by the developer, and will not be described herein.
  • the implementation code of the HTTP request base service may be, but is not limited to, the following:
  • the framework for uniformly mapping the HTTP request may be created, including: creating a mapping file for accessing a third-party HTTP service, where the mapping file includes the configuration. a parameter and encapsulation path method, wherein the configuration parameter includes a URL address, a port, and a public parameter of the third-party HTTP service; the encapsulation path method includes: an attribute of the encapsulation path method, a path, and the HTTP request base invoked by the method The method name of the service.
  • an interface for accessing a third-party HTTP service is created at the application layer, where the interface includes a plurality of interface methods, and the interface methods are in one-to-one correspondence with the attributes (ID) of the encapsulated path method in the mapping file, so as to be able to pass the attribute
  • the corresponding mode corresponds to the mapping file from the interface; at the application layer, the dynamic proxy annotation is injected into the interface, and the attributes of the dynamic proxy annotation correspond to the attributes of the interface.
  • the parameters and the URL are logically spliced; the HTTP request basic service is created at the bottom layer, and the method in the HTTP request basic service includes basic HTTP requests: GET, POST, PUT, and DELETE, in addition, You can also customize HTTP requests based on user needs.
  • the process of performing unified mapping on the HTTP request includes:
  • the dynamic proxy annotation corresponding to the interface corresponding to the object is found, and a dynamic proxy object is generated according to the attribute of the dynamic proxy annotation;
  • the dynamic proxy object intercepts and reflects to the underlying HTTP request basic service, wherein the reflection process includes: obtaining the JAVA object; obtaining the URL from the JAVA object An object, a public parameter object, and an encapsulation path method object, obtain a URL address from the URL object, obtain a public parameter from the public parameter object, and obtain a path from the encapsulation path method object; encapsulate the path; acquire a public parameter; Encapsulating a real HTTP request address; according to the URL address, the call invokes the HTTP request base service to complete an HTTP call. And use the underlying HTTP request basic service method to initiate an HTTP request and complete an HTTP request call.
  • the method and device for uniformly mapping an HTTP request obtain a mapping file for accessing a third-party HTTP service, acquire an interface corresponding to the mapping file, and inject a reflection into the interface, where
  • the mapping file separates the configuration content of the HTTP request URL address, the port, the public parameter, and the attribute of the encapsulation path method, the path, and the method in the HTTP request basic service invoked from the business logic content, and maps the file.
  • the mapping file is associated with the interface.
  • the corresponding JAVA object is generated according to the mapping file
  • the dynamic proxy object is generated according to the request of the corresponding reflection proxy corresponding to the corresponding interface.
  • the dynamic proxy object uses the JAVA object generated according to the mapping file.
  • the request is processed, and the method in the HTTP request basic service is invoked to complete the HTTP request, thereby implementing one development and multiple reuse of the mapping file, thereby implementing the HTTP request in the case of simplifying the development difficulty and increasing the reuse rate.
  • the terminal, the device of the service network, and the trusted party each include one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
  • the memory may include non-persistent memory, random access memory (RAM), and/or non-volatile memory in a computer readable medium, such as read only memory (ROM) or flash memory.
  • RAM random access memory
  • ROM read only memory
  • Memory is an example of a computer readable medium.
  • Computer readable media includes both permanent and non-persistent, removable and non-removable media.
  • Information storage can be implemented by any method or technology. The information can be computer readable instructions, data structures, modules of programs, or other data.
  • Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory. (ROM), EEPROM, flash memory or other memory technology, CD-ROM, digital multiplex A compact disc (DVD) or other optical storage, magnetic cassette, magnetic tape storage or other magnetic storage device or any other non-transportable medium can be used to store information that can be accessed by a computing device.
  • PRAM phase change memory
  • SRAM static random access memory
  • DRAM dynamic random access memory
  • RAM random access memory
  • ROM read only memory
  • EEPROM electrically erasable programmable read only memory
  • flash memory or other memory technology
  • CD-ROM compact disc
  • DVD digital multiplex A compact disc
  • magnetic cassette magnetic tape storage or other magnetic storage device or any other non-transportable medium
  • computer readable media does not include non-transitory computer readable media, such as modulated data signals and carrier waves.
  • the present application can be implemented in software and/or a combination of software and hardware, for example, using an application specific integrated circuit (ASIC), a general purpose computer, or any other similar hardware device.
  • the software program of the present application can be executed by a processor to implement the steps or functions described above.
  • the software programs (including related data structures) of the present application can be stored in a computer readable recording medium such as a RAM memory, a magnetic or optical drive or a floppy disk and the like.
  • some of the steps or functions of the present application may be implemented in hardware, for example, as a circuit that cooperates with a processor to perform various steps or functions.
  • a portion of the present application can be applied as a computer program product, such as computer program instructions, which, when executed by a computer, can invoke or provide a method and/or technical solution in accordance with the present application.
  • the program instructions for invoking the method of the present application may be stored in a fixed or removable recording medium, and/or transmitted by a data stream in a broadcast or other signal bearing medium, and/or stored in a The working memory of the computer device in which the program instructions are run.
  • an embodiment in accordance with the present application includes a device including a memory for storing computer program instructions and a processor for executing program instructions, wherein when the computer program instructions are executed by the processor, triggering
  • the apparatus operates based on the aforementioned methods and/or technical solutions in accordance with various embodiments of the present application.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Devices For Executing Special Programs (AREA)
  • Information Transfer Between Computers (AREA)
  • Stored Programmes (AREA)

Abstract

一种对HTTP请求进行统一映射的方法和设备,通过获取用于访问第三方HTTP服务的映射文件,将配置内容从业务逻辑内容中独立,并将映射文件与接口相对应,根据映射文件生成相应JAVA对象,并根据请求调用相应接口对应的反射代理注解生成动态代理对象,则在进行HTTP请求时,动态代理对象会利用根据所述映射文件生成的JAVA对象处理所述请求,并调用HTTP请求基础服务中的方法,完成HTTP请求,从而实现映射文件的一次开发多次复用,从而在简化开发难度提高复用率的情况下实现HTTP请求调用。

Description

对HTTP请求进行统一映射的方法和设备
本申请要求2015年07月13日递交的申请号为201510408395.3、发明名称为“对HTTP请求进行统一映射的方法和设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及计算机领域,尤其涉及一种用于对HTTP请求进行统一映射的技术。
背景技术
现在很多的JAVA后端应用要通过HTTP(HTTP,HyperText Transfer Protocol,网络协议)请求调用第三方应用的接口,则编写的代码里必须有HTTP请求的URL(Uniform Resource Locator,统一资源定位符),端口和传递的配置参数。
现有JAVA(一种可以撰写跨平台应用软件的面向对象的程序设计语言)的后端发送HTTP请求时,根据不同的业务的逻辑,调用不同第三方应用的HTTP请求就得定义不同的方法,里面的逻辑就是拼装参数,在调用底层的HTTP公用的请求方法,这样就导致代码的冗余和开发的重复。会在代码里定义多个调用第三方的URL、端口以及配置参数,导致业务逻辑的代码和请求的配置参数的代码混合在一起,没有很好的分离,并且不同的开发人员根据业务的不断重复开发访问HTTP请求的基础代码,导致代码复用率较低,开发效率有所下降。
发明内容
本申请要解决的技术问题是将调用第三方HTTP请求的配置参数从业务的逻辑内容中分离后,如何利用分离的配置参数完成HTTP请求,从而在提高配置参数的复用率情况下,实现HTTP请求。
为解决上述技术问题,本申请提供一种对HTTP请求进行统一映射的方法,其中,所述对HTTP请求进行统一映射的方法包括:
获取用于访问第三方HTTP服务的映射文件,其中,所述映射文件包括HTTP请求的配置参数和封装路径方法;
获取用于访问第三方HTTP服务的接口及与所述接口的动态代理注解,其中,所述 接口包括若干接口方法,且所述接口方法的属性与所述HTTP请求的封装路径方法的属性一一对应;
根据所述映射文件生成JAVA对象,并根据相应所述接口的动态代理注解生成动态代理对象;
当获取到对具有动态代理注解的接口进行调用的请求时,利用所述动态代理对象拦截所述请求,并根据所述请求获取相应所述JAVA对象,并利用反射机制调用HTTP请求基础服务中的方法,以完成HTTP请求。
进一步地,所述HTTP请求的配置参数至少包括以下任一项:
所述第三方HTTP服务的URL地址、端口或公共参数;
所述HTTP请求的封装路径方法至少包括以下任一项:
所述封装路径方法的属性、路径或其所调用的所述HTTP请求基础服务的方法名称。
进一步地,根据所述映射文件生成JAVA对象包括:
根据所述映射文件中的配置参数和封装路径方法生成相对应的JAVA对象,其中,所述JAVA对象包括:
URL对象、公共参数对象和封装路径方法对象。
进一步地,根据所述映射文件生成JAVA对象包括:
利用JAXB将所述映射文件中加载到内存,并生成相对应的所述JAVA对象。
进一步地,根据所述请求获取相应所述JAVA对象,并利用反射机制调用HTTP请求基础服务中的方法包括:
根据所述请求获取所述JAVA对象,其中,所述JAVA对象包括URL对象、公共参数对象和封装路径方法对象;
从所述URL对象中获取URL地址、从所述公共参数对象获取公共参数、并从所述封装路径方法对象中获取路径;
将所述公共参数和所述路径封装真正的HTTP请求地址;
调用HTTP请求基础服务中的方法,利用所述真正的HTTP请求地址完成一次HTTP调用。
进一步地,调用HTTP请求基础服务中的方法包括:
利用反射技术调用HTTP请求基础服务中的方法。
进一步地,所述动态代理注解的属性与所述接口的属性相同。
进一步地,所述映射文件为XML格式文件。
进一步地,所述HTTP请求基础服务包括基础HTTP请求方法,其中,所述基础HTTP请求方法至少包括以下任一项:
请求指定的页面信息,并返回实体主体的方法;
请求服务器接受所指定的文档作为对所标识的URI的新的从属实体的方法;
从客户端向服务器传送的数据取代指定的文档的内容的方法;或
请求服务器删除指定的页面的方法。
进一步地,所述HTTP请求基础服务还包括自定义HTTP请求方法。
根据本申请另一方面提供的一种对HTTP请求进行统一映射的设备,其中,所述设备包括:
映射文件获取装置,用于获取用于访问第三方HTTP服务的映射文件,其中,所述映射文件包括HTTP请求的配置参数和封装路径方法;
接口获取装置,用于获取用于访问第三方HTTP服务的接口及与所述接口的动态代理注解,其中,所述接口包括若干接口方法,且所述接口方法的属性与所述HTTP请求的封装路径方法的属性一一对应;
对象生成装置,用于根据所述映射文件生成JAVA对象,并根据相应所述接口的动态代理注解生成动态代理对象;
HTTP请求执行装置,用于当获取到对具有动态代理注解的接口进行调用的请求时,利用所述动态代理对象拦截所述请求,并根据所述请求获取相应所述JAVA对象,并利用反射机制调用HTTP请求基础服务中的方法,以完成HTTP请求。
进一步地,所述HTTP请求的配置参数至少包括以下任一项:
所述第三方HTTP服务的URL地址、端口或公共参数;
所述HTTP请求的封装路径方法至少包括以下任一项:
所述封装路径方法的属性、路径或其所调用的所述HTTP请求基础服务的方法名称。
进一步地,所述对象生成装置用于:
根据所述映射文件中的配置参数和封装路径方法生成相对应的JAVA对象,其中,所述JAVA对象包括:
URL对象、公共参数对象和封装路径方法对象。
进一步地,所述对象生成装置用于:
利用JAXB将所述映射文件中加载到内存,并生成所述相对应的JAVA。
进一步地,所述HTTP请求执行装置用于:
根据所述请求获取所述JAVA对象,其中,所述JAVA对象包括URL对象、公共参数对象和封装路径方法对象;
从所述URL对象中获取URL地址、从所述公共参数对象获取公共参数、并从所述封装路径方法对象中获取路径;
将所述公共参数和所述路径封装真正的HTTP请求地址;
调用HTTP请求基础服务中的方法,并利用所述真正的HTTP请求地址完成一次HTTP调用。
进一步地,所述HTTP请求执行装置用于:
利用反射技术调用HTTP请求基础服务中的方法,并利用所述真正的HTTP请求地址完成一次HTTP调用。
进一步地,所述动态代理注解的属性与所述接口的属性相同。
进一步地,所述映射文件为XML格式文件。
进一步地,所述HTTP请求基础服务包括基础HTTP请求方法,其中,所述基础HTTP请求方法至少包括以下任一项:
请求指定的页面信息,并返回实体主体的方法;
请求服务器接受所指定的文档作为对所标识的URI的新的从属实体的方法;
从客户端向服务器传送的数据取代指定的文档的内容的方法;或
请求服务器删除指定的页面的方法。
进一步地,所述HTTP请求基础服务还包括自定义HTTP请求方法。
具体地,当需要向第三方发起HTTP请求时,对HTTP请求进行统一映射的执行过程包括:
获取用于访问第三方HTTP服务的映射文件,其中,所述映射文件包括用于访问第三方的HTTP请求的URL地址、端口和公用参数等配置参数、封装路径方法的属性、路径及其所调用的HTTP请求基础服务的方法;
获取用于访问第三方HTTP服务的接口及其动态代理注解,其中接口包括若干接口方法,若干接口方法与所述映射文件中的封装路径方法的属性(ID)的名称一一对应,以能够通过属性的对应方式从接口对应到映射文件,所述动态代理注解的属性与所述接口的属性相对应;
当WEB容器启动时,利用JAXB(jackson-module-jaxb-annotations,能够使用Jackson对JAXB注解的支持实现)把自定义的映射文件里的标签,加载到内存生成相对应的 JAVA对象;
为每个对象初始化之后,会找到这个对象对应的接口所对应的动态代理注解,并根据所述动态代理注解的属性,生成动态代理对象;
当有业务对相应动态代理注解的接口进行调用的时,动态代理对象就会进行拦截,反射到底层的HTTP请求基础服务,其中,反射过程包括:获取JAVA对象中的HOST对象;从HOST对象中获取URL对象,从URL对象中获取路径、URL地址及公共参数;封装路径;获取公共参数;封装真正的HTTP请求地址;根据所述URL地址,反射调用所述HTTP请求基础服务,完成一次HTTP调用。并利用底层的HTTP请求基础服务的方法发起HTTP请求,完成一次HTTP请求调用。
与现有技术相比,所述对HTTP请求进行统一映射的方法和设备通过获取用于访问第三方HTTP服务的映射文件,并获取所述映射文件对应的接口并为所述接口注入反射,其中,所述映射文件将HTTP请求的URL地址、端口、公共参数、和封装路径方法的属性、路径及其调用的HTTP请求基础服务中的方法等配置内容从业务逻辑内容中独立,并将映射文件将所述映射文件与所述接口相对应。当WEB启动时,根据映射文件生成相应JAVA对象,并根据请求调用相应接口对应的反射代理注解生成动态代理对象,则在进行HTTP请求时,动态代理对象会利用根据所述映射文件生成的JAVA对象处理所述请求,并调用HTTP请求基础服务中的方法,完成HTTP请求,从而实现映射文件的一次开发多次复用,从而在简化开发难度提高复用率的情况下实现HTTP请求调用。
附图说明
通过阅读参照以下附图所作的对非限制性实施例所作的详细描述,本申请的其它特征、目的和优点将会变得更明显:
图1示出根据本申请一方面提供的一种对HTTP请求进行统一映射的方法的流程示意图;
图2示出根据本申请一方面提供的一种对HTTP请求进行统一映射的设备的结构示意图。
附图中相同或相似的附图标记代表相同或相似的部件。
具体实施方式
下面结合附图对本申请作进一步详细描述。
图1示出根据本申请一方面提供的一种对HTTP请求进行统一映射的方法的流程示意图,所述方法包括:步骤S11、步骤S12、步骤S13和步骤S14。
其中,所述步骤S11包括:获取用于访问第三方HTTP服务的映射文件,其中,所述映射文件包括HTTP请求的配置参数和封装路径方法;所述步骤S12包括:获取用于访问第三方HTTP服务的接口及与所述接口的动态代理注解,其中,所述接口包括若干接口方法,且所述接口方法的属性与所述HTTP请求的封装路径方法的属性一一对应;所述步骤S13包括:根据所述映射文件生成JAVA对象,并根据相应所述接口的动态代理注解生成动态代理对象;所述步骤S14包括:当获取到对具有动态代理注解的接口进行调用的请求时,利用所述动态代理对象拦截所述请求,并根据所述请求获取相应所述JAVA对象,调用HTTP请求基础服务中的方法,以完成HTTP请求。
进一步地,所述HTTP请求的配置参数至少包括以下任一项:所述第三方HTTP服务的URL地址、端口或公共参数;所述HTTP请求的封装路径方法至少包括以下任一项:所述封装路径方法的属性、路径或其所调用的所述HTTP请求基础服务的方法名称。
根据本申请一实施例,所述对HTTP请求进行统一映射的方法通过创建用于访问第三方HTTP服务的映射文件,将配置参数和封装路径方法等请求配置代码独立,并将所述映射文件与所述接口相对应。当需要访问相应第三方HTTP服务的HTTP请求时,获取所述映射文件对应的接口和所述接口注入的动态反射代理注解,并根据相应所述接口的动态代理注解生成动态代理对象,则在进行HTTP请求时,所述动态代理对象会利用根据所述映射文件生成的JAVA对象处理所述请求,并调用HTTP请求基础服务中的方法,完成HTTP请求,从而实现映射文件的一次开发,可以被开发人员多次利用,并且开发人员无需关注HTTP底层的技术实现,从而实现在简化开发复杂度并提高开发效率的情况下实现HTTP请求调用。
具体地,所述步骤S11用于获取用于访问第三方HTTP服务的映射文件,其中,所述映射文件包括HTTP请求的配置参数和封装路径方法。进一步地,所述HTTP请求的配置参数至少包括以下任一项:所述第三方HTTP服务的URL地址、端口或公共参数;所述HTTP请求的封装路径方法至少包括以下任一项:所述封装路径方法的属性、路径或其所调用的所述HTTP请求基础服务的方法名称。
优选的,所述映射文件为映射文件,所述映射文件可以在后续加载并生成JAVA对象,业务调用相应接口时,动态代理对象会进行拦截,并利用所述JAVA对象,实现HTTP请求。
其中,所述映射文件的代码实现包括但不限于:
Figure PCTCN2016088297-appb-000001
在此,<host name=“${dataplus.base.host}”>的name(URL地址)是调用第三方的地址,所述地址可以是URL地址也可以是IP地址(Internet Protocol Address),例如<host name=“127.0.0.1”>,接着,在<String port=host.getPort();//获取端口>中的String port记录的端口的信息,接着,在<publicParam key="timestamp">dynamic:Query:ClassName</publicParam>中,所述的publicParam是公共参数(其中,访问第三方应用,对方一般由于要安全的考虑所有的请求会有一些必定传得参数,一些参数是固定不变的,一些参数是代码动态运行时生成的),所述key是公共参数的名称,所述dynamic是用于说明参数是动态生成的,所述Query是用于说明参数是放在请求头里,所述AddHeader是用于说明参数是放在请求头里,所述className是用于说明动态参数生成的规则所需要调用的工具类。
其中,所述<url id="newTenant"path="/api2.0/tenant"method="doPostEntity"/>封装路 径方法,其中,所述url是用于说明每个业务需要调用不同的路径地址,所述id是用于说明每个业务方法对应不同的唯一标识(这个必须跟定义的业务接口的方法名称一样,程序是通过这个来进行反射的),所述path是用于说明业务不同的路径地址,所述method是用于调用底层HTTP请求基础服务里的方法名称。
当然,本领域技术人员应当能够理解,上述对映射文件的代码实现的方式仅为举例,今后可能出现的包括URL地址、端口、公共参数、封装路径方法等配置参数的内容的映射文件的实现方式,如能使用本申请,均可以以引用的方式包含于此。
具体地,所述步骤S12用于获取用于访问第三方HTTP服务的接口及与所述接口的动态代理注解,其中,所述接口包括若干接口方法,且所述接口方法的属性与所述HTTP请求的封装路径方法的属性一一对应。
在此,所述接口为HTTP请求调用过程提供的对象之间调用的通道,并且通过对所述接口注入动态代理,能够在HTTP请求调用过程提供了动态代理机制,以实现HTTP请求的顺利完成。
在具体场景中,用于访问第三方HTTP服务的接口的具体代码实现可以但不限于:
public interface BaseClientService{
Map<String,Object>newTenant(Map<String,Object>params);
Map<String,Object>newBaseUser(Map<String,Object>params);
Map<String,Object>addTenantMember(Map<String,Object>params);
……
}
所述接口包括newTenant、newBaseUser和addTenantMember等接口方法,且所述接口方法的属性与前例的映射文件中所述<url>中id的属性一一对应,以便后续动态代理根据所述接口与所述映射文件的一一对应的关系进行反射,其中,所述接口方法的入参是Map<String,Object>对象,出参是根据HTTP返回的字符串再反序列化成自定义的对象。
当然,本领域技术人员应当能够理解,上述对接口的代码实现的方式仅为举例,今后可能出现的能够提供反射机制来实现对象之间的调用的接口的实现方式,如能使用本申请,均可以以引用的方式包含于此。
接着,所述步骤S13将所述步骤S12获取的映射文件生成JAVA对象。所述步骤S13包括:根据所述映射文件生成JAVA对象,并根据相应所述接口的动态代理注解生成动态代理对象。具体地,可以利用JAXB根据所述映射文件,将所述映射文件中的标签, 加载到内存,并生成相对应的JAVA对象。利用JAXB将所述映射文件中的标签,加载到内存,并生成相对应的JAVA对象。其中,根据映射文件的配置参数和封装路径方法的内容,所生成的JAVA对象可以包括URL对象、公共参数对象和封装路径方法对象。其中,所述URL对象包括URL地址和端口等信息,所述公共参数对象包括公共参数等信息,所述封装路径方法对象包括所述封装路径方法的属性、路径或其所调用的所述HTTP请求基础服务的方法名称的信息。
在此,将获取的映射文件生成JAVA对象的实现代码可以但不限于:
Figure PCTCN2016088297-appb-000002
其中,所述publicParams(公共参数对象)与映射文件里的<publicParams>(公共参数)标签对应,所述urls(封装路径方法对象)对应映射文件里的<urls>标签(封装路径方法)对应,所述name(URL对象)对用所述映射文件中的<hostname>(URL)。
当然,本领域技术人员应当能够理解,上述将获取的映射文件生成JAVA对象的实现代码的方式仅为举例,今后可能出现的JAVA对象生成过程的实现方式,如能使用本申请,均可以以引用的方式包含于此。
进一步地,所述步骤S14包括:当获取到对具有动态代理注解的接口进行调用的请求时,利用所述动态代理对象拦截所述请求,并根据所述请求获取相应所述JAVA对象,并利用反射机制调用HTTP请求基础服务中的方法,以完成HTTP请求。
在此,所述步骤S14用于在HTTP请求执行过程中,利用步骤S13中生成的动态代理对象拦截业务对含有动态代理注解的接口的调用,获取步骤S13生成的JAVA对象,并利用反射机制调用HTTP请求基础服务中的方法,以完成HTTP请求。
其中,步骤S14利用反射机制调用HTTP请求基础服务中的方法,以完成HTTP请求,具体包括:根据所述请求获取所述JAVA对象,其中,所述JAVA对象包括URL对象、公共参数对象和封装路径方法对象;从所述URL对象中获取URL地址、从所述公共参数对象获取公共参数、并从所述封装路径方法对象中获取路径;将所述公共参数和所述路径封装真正的HTTP请求地址;调用HTTP请求基础服务中的方法,利用所述真正的HTTP请求地址完成一次HTTP调用。
当WEB容器(一种服务程序,用于处理从客户端发出的请求)启动时,利用JAXB(jackson-module-jaxb-annotations,能够使用Jackson对JAXB注解的支持实现)把自定义的映射文件里的标签,加载到内存生成相对应的JAVA对象;
为每个对象初始化之后,会找到这个对象对应的接口所对应的动态代理注解,并根据所述动态代理注解的属性,生成动态代理对象;
当有业务对相应动态代理注解的接口进行调用的时,动态代理对象就会进行拦截,反射到底层的HTTP请求基础服务,其中,反射过程包括:获取JAVA对象中的HOST对象;从HOST对象中获取URL对象,从URL对象中获取路径、URL地址及公共参数;封装路径;获取公共参数;封装真正的HTTP请求地址;根据所述URL地址,反射调用所述HTTP请求基础服务,完成一次HTTP调用,并利用底层的HTTP请求基础服务的方法发起HTTP请求,完成一次HTTP请求调用。
具体地,反射调用所述HTTP请求基础服务,完成一次HTTP调用的代码实现可以但不限于如下:
Figure PCTCN2016088297-appb-000003
Figure PCTCN2016088297-appb-000004
当然,本领域技术人员应当能够理解,上述对反射调用所述HTTP请求基础服务,完成一次HTTP调用的实现代码的方式仅为举例,今后可能出现的反射调用所述HTTP请求基础服务,完成一次HTTP调用的实现方式,如能使用本申请,均可以以引用的方式包含于此。
进一步地,所述HTTP请求基础服务包括基础HTTP请求方法,其中,所述基础HTTP 请求方法至少包括以下任一项:
GET:请求指定的页面信息,并返回实体主体的方法;
POST:请求服务器接受所指定的文档作为对所标识的URI的新的从属实体的方法;
PUT:从客户端向服务器传送的数据取代指定的文档的内容的方法;
DELETE:请求服务器删除指定的页面的方法。
此外,所述HTTP请求基础服务还可包括其他HTTP请求方法,例如HEAD、OPTIONS、TRACE、CONNECT等,此外,还可以由开发人员自行定义HTTP请求方法,在此不做赘述。
所述HTTP请求基础服务的实现代码可以但不限于如下:
Figure PCTCN2016088297-appb-000005
当然,本领域技术人员应当能够理解,上述对所述HTTP请求基础服务的实现代码的方式仅为举例,今后可能出现的所述HTTP请求基础服务的实现方式,如能使用本申请,均可以以引用的方式包含于此。
在一具体的场景中,对HTTP请求进行统一映射之前,可以首先创建对HTTP请求进行统一映射的框架,包括:创建一个用于访问第三方HTTP服务的映射文件,其中,所述映射文件包括配置参数和封装路径方法,其中,配置参数包括所述第三方HTTP服务的URL地址、端口及公共参数;封装路径方法包括:所述封装路径方法的属性、路径及其所调用的所述HTTP请求基础服务的方法名称。接着,在应用层创建用于访问第三方HTTP服务的接口,其中接口包括若干接口方法,若干接口方法与所述映射文件中的封装路径方法的属性(ID)一一对应,以能够通过属性的对应方式从接口对应到映射文件;在应用层,对所述接口注入动态代理注解,所述动态代理注解的属性与所述接口的属性相对应。然后,在应用层的业务方法中,将参数和URL进行逻辑拼接;在底层创建HTTP请求基础服务,所述HTTP请求基础服务中的方法包括基本HTTP请求:GET、POST、PUT和DELETE,此外,还可根据用户需要自定义HTTP请求。
则,当需要向第三方发起HTTP请求时,对HTTP请求进行统一映射的执行过程包括:
1.获取上述创建的用于访问第三方HTTP服务的映射文件、接口及接口的动态代理注解、以及应用层的业务方法;
2.当WEB容器启动时,利用JAXB(jackson-module-jaxb-annotations,能够使用Jackson对JAXB注解的支持实现)把自定义的映射文件里的标签,加载到内存生成相对应的JAVA对象;
3.为每个对象初始化之后,会找到这个对象对应的接口所对应的动态代理注解,并根据所述动态代理注解的属性,生成动态代理对象;
4.当有业务对相应动态代理注解的接口进行调用的时,动态代理对象就会进行拦截,反射到底层的HTTP请求基础服务,其中,反射过程包括:获取JAVA对象;从JAVA对象中获得URL对象、公用参数对象和封装路径方法对象,从所述URL对象中获取URL地址、从所述公共参数对象获取公共参数、并从所述封装路径方法对象中获取路径;封装路径;获取公共参数;封装真正的HTTP请求地址;根据所述URL地址,反射调用所述HTTP请求基础服务,完成一次HTTP调用。并利用底层的HTTP请求基础服务的方法发起HTTP请求,完成一次HTTP请求调用。
图2示出根据本申请一方面提供的一种对HTTP请求进行统一映射的设备的结构示意图,所述设备1包括:映射文件获取装置11、接口获取装置12、对象生成装置13和HTTP请求执行装置14。
其中,映射文件获取装置11用于获取用于访问第三方HTTP服务的映射文件,其中,所述映射文件包括HTTP请求的配置参数和封装路径方法;接口获取装置12用于获取用于访问第三方HTTP服务的接口及与所述接口的动态代理注解,其中,所述接口包括若干接口方法,且所述接口方法的属性与所述HTTP请求的封装路径方法的属性一一对应;对象生成装置13用于根据所述映射文件生成JAVA对象,并根据相应所述接口的动态代理注解生成动态代理对象;HTTP请求执行装置14用于当获取到对具有动态代理注解的接口进行调用的请求时,利用所述动态代理对象拦截所述请求,并根据所述请求获取相应所述JAVA对象,并利用反射机制调用HTTP请求基础服务中的方法,以完成HTTP请求。
进一步地,所述HTTP请求的配置参数至少包括以下任一项:所述第三方HTTP服务的URL地址、端口或公共参数;所述HTTP请求的封装路径方法至少包括以下任一项:所述封装路径方法的属性、路径或其所调用的所述HTTP请求基础服务的方法名称。
在此,所述设备1包括一种能够按照事先设定或存储的指令,自动进行数值计算和 信息处理的电子设备,其硬件包括但不限于微处理器、专用集成电路(ASIC)、可编程门阵列(FPGA)、数字处理器(DSP)、嵌入式设备等。所述网络设备其包括但不限于计算机、网络主机、单个网络服务器、多个网络服务器集或多个服务器构成的云;在此,云由基于云计算(Cloud Computing)的大量计算机或网络服务器构成,其中,云计算是分布式计算的一种,由一群松散耦合的计算机集组成的一个虚拟超级计算机。所述网络包括但不限于互联网、广域网、城域网、局域网、VPN网络、无线自组织网络(Ad Hoc网络)等。此外,所述设备1还可以包括运行于所述用户设备、网络设备、或用户设备与网络设备相集成所构成的设备上的脚本程序,或所述脚本程序与电子设备的结合。当然,本领域技术人员应能理解上述设备1仅为举例,其他现有的或今后可能出现的设备1如可适用于本申请,也应包含在本申请保护范围以内,并在此以引用方式包含于此。
根据本申请一实施例,所述对HTTP请求进行统一映射的方法通过创建用于访问第三方HTTP服务的映射文件,将配置参数和封装路径方法等请求配置代码独立,并将所述映射文件与所述接口相对应。当需要访问相应第三方HTTP服务的HTTP请求时,获取所述映射文件对应的接口和所述接口注入的动态反射代理注解,并根据相应所述接口的动态代理注解生成动态代理对象,则在进行HTTP请求时,所述动态代理对象会利用根据所述映射文件生成的JAVA对象处理所述请求,并调用HTTP请求基础服务中的方法,完成HTTP请求,从而实现映射文件的一次开发,可以被开发人员多次利用,并且开发人员无需关注HTTP底层的技术实现,从而实现在简化开发复杂度并提高开发效率的情况下实现HTTP请求调用。
具体地,所述映射文件获取装置11用于获取用于访问第三方HTTP服务的映射文件,其中,所述映射文件包括HTTP请求的配置参数和封装路径方法。进一步地,所述HTTP请求的配置参数至少包括以下任一项:所述第三方HTTP服务的URL地址、端口或公共参数;所述HTTP请求的封装路径方法至少包括以下任一项:所述封装路径方法的属性、路径或其所调用的所述HTTP请求基础服务的方法名称。
优选的,所述映射文件为XML文件,所述XML文件可以在后续加载并生成JAVA对象,业务调用相应接口时,动态代理对象会进行拦截,并利用所述JAVA对象,实现HTTP请求。
Figure PCTCN2016088297-appb-000006
Figure PCTCN2016088297-appb-000007
在此,<host name=“${dataplus.base.host}”>的name(URL地址)是调用第三方的地址,所述地址可以是URL地址也可以是IP地址(Internet Protocol Address),例如<host name=“127.0.0.1”>,接着,在<String port=host.getPort();//获取端口>中的String port记录的端口的信息,接着,在<publicParam key="timestamp">dynamic:Query:ClassName</publicParam>中,所述的publicParam是公共参数(其中,访问第三方应用,对方一般由于要安全的考虑所有的请求会有一些必定传得参数,一些参数是固定不变的,一些参数是代码动态运行时生成的),所述key是公共参数的名称,所述dynamic是用于说明参数是动态生成的,所述Query是用于说明参数是放在请求头里,所述AddHeader是用于说明参数是放在请求头里,所述className是用于说明动态参数生成的规则所需要调用的工具类。
其中,所述<url id="newTenant"path="/api2.0/tenant"method="doPostEntity"/>封装路径方法,其中,所述url是用于说明每个业务需要调用不同的路径地址,所述id是用于说明每个业务方法对应不同的唯一标识(这个必须跟定义的业务接口的方法名称一样,程序是通过这个来进行反射的),所述path是用于说明业务不同的路径地址,所述method是用于调用底层HTTP请求基础服务里的方法名称。
当然,本领域技术人员应当能够理解,上述对映射文件的代码实现的方式仅为举例,今后可能出现的包括URL地址、端口、公共参数、封装路径方法等配置参数的内容的映射文件的实现方式,如能使用本申请,均可以以引用的方式包含于此。
具体地,所述接口获取装置12用获取用于访问第三方HTTP服务的接口及与所述接口的动态代理注解,其中,所述接口包括若干接口方法,且所述接口方法的属性与所述HTTP请求的封装路径方法的属性一一对应。
在此,所述接口为HTTP请求调用过程提供的对象之间调用的通道,并且通过对所述接口注入动态代理,能够在HTTP请求调用过程提供了动态代理机制,以实现HTTP请求的顺利完成。
在具体场景中,用于访问第三方HTTP服务的接口的具体代码实现可以但不限于:
public interface BaseClientService{
Map<String,Object>newTenant(Map<String,Object>params);
Map<String,Object>newBaseUser(Map<String,Object>params);
Map<String,Object>addTenantMember(Map<String,Object>params);
……
}
所述接口包括newTenant、newBaseUser和addTenantMember等接口方法,且所述接口方法的属性与前例的映射文件中所述<url>中id的属性一一对应,以便后续动态代理根据所述接口与所述映射文件的一一对应的关系进行反射,其中,所述接口方法的入参是从HTTP返回的以Map<String,Object>对象形式的字符串,出参是从HTTP返回的字符串序列化成自定义的对象。
当然,本领域技术人员应当能够理解,上述对接口的代码实现的方式仅为举例,今后可能出现的能够提供反射机制来实现对象之间的调用的接口的实现方式,如能使用本申请,均可以以引用的方式包含于此。
接着,所述对象生成装置13将所述接口获取装置12获取的映射文件生成JAVA对象。所述对象生成装置13包括:根据所述映射文件生成JAVA对象,并根据相应所述接口的动态代理注解生成动态代理对象。具体地,可以利用JAXB将所述映射文件中的标签加载到内存并生成相对应的JAVA对象。其中,根据映射文件的配置参数和封装路径方法的内容,所生成的JAVA对象可以包括URL对象、公共参数对象和封装路径方法对象。其中,所述URL对象包括URL地址和端口等信息,所述公共参数对象包括公共参 数等信息,所述封装路径方法对象包括所述封装路径方法的属性、路径或其所调用的所述HTTP请求基础服务的方法名称的信息。
在此,将获取的映射文件生成JAVA对象的实现代码可以但不限于:
Figure PCTCN2016088297-appb-000008
其中,所述publicParams(公共参数对象)与映射文件里的<publicParams>(公共参数)标签对应,所述urls(封装路径方法对象)对应映射文件里的<urls>标签(封装路径方法)对应,所述name(URL对象)对用所述映射文件中的<hostname>(URL)。
当然,本领域技术人员应当能够理解,上述将获取的映射文件生成JAVA对象的实现代码的方式仅为举例,今后可能出现的JAVA对象生成过程的实现方式,如能使用本申请,均可以以引用的方式包含于此。
进一步地,所述HTTP请求执行装置14包括当获取到对具有动态代理注解的接口进行调用的请求时,利用所述动态代理对象拦截所述请求,并根据所述请求获取相应所述JAVA对象,并利用反射机制调用HTTP请求基础服务中的方法,以完成HTTP请求。
在此,所述HTTP请求执行装置14用于在HTTP请求执行过程中,利用HTTP请求执行装置13中生成的动态代理对象拦截业务对含有动态代理注解的接口的调用,获取HTTP请求执行装置13生成的JAVA对象,并利用反射机制调用HTTP请求基础服务中的方法,以完成HTTP请求。
其中,所述HTTP请求执行装置14具体包括:根据所述请求获取所述JAVA对象,其中,所述JAVA对象包括URL对象、公共参数对象和封装路径方法对象;从所述URL对象中获取URL地址、从所述公共参数对象获取公共参数、并从所述封装路径方法对象中获取路径;将所述公共参数和所述路径封装真正的HTTP请求地址;调用HTTP请求基础服务中的方法,利用所述真正的HTTP请求地址完成一次HTTP调用。
进一步地,所述HTTP请求执行装置14利用反射技术调用HTTP请求基础服务中的方法的子单元。
当WEB容器(一种服务程序,用于处理从客户端发出的请求)启动时,利用JAXB(jackson-module-jaxb-annotations,能够使用Jackson对JAXB注解的支持实现)把自定 义的映射文件里的标签,加载到内存生成相对应的JAVA对象;
为每个对象初始化之后,会找到这个对象对应的接口所对应的动态代理注解,并根据所述动态代理注解的属性,生成动态代理对象;
当有业务对相应动态代理注解的接口进行调用的时,动态代理对象就会进行拦截,反射到底层的HTTP请求基础服务,其中,反射过程包括:获取JAVA对象中的HOST对象;从HOST对象中获取URL对象,从URL对象中获取路径、URL地址及公共参数;封装路径;获取公共参数;封装真正的HTTP请求地址;根据所述URL地址,反射调用所述HTTP请求基础服务,完成一次HTTP调用,并利用底层的HTTP请求基础服务的方法发起HTTP请求,完成一次HTTP请求调用。
具体地,所述HTTP请求执行装置14反射调用所述HTTP请求基础服务,完成一次HTTP调用的代码实现可以但不限于如下:
Figure PCTCN2016088297-appb-000009
Figure PCTCN2016088297-appb-000010
当然,本领域技术人员应当能够理解,上述对反射调用所述HTTP请求基础服务,完成一次HTTP调用的实现代码的方式仅为举例,今后可能出现的反射调用所述HTTP请求基础服务,完成一次HTTP调用的实现方式,如能使用本申请,均可以以引用的方式包含于此。
进一步地,所述HTTP请求基础服务包括基础HTTP请求方法,其中,所述基础HTTP请求方法至少包括以下任一项:
GET:请求指定的页面信息,并返回实体主体的方法;
POST:请求服务器接受所指定的文档作为对所标识的URI的新的从属实体的方法;
PUT:从客户端向服务器传送的数据取代指定的文档的内容的方法;
DELETE:请求服务器删除指定的页面的方法。
此外,所述HTTP请求基础服务还可包括其他HTTP请求方法,例如HEAD、OPTIONS、TRACE、CONNECT等,此外,还可以由开发人员自行定义HTTP请求方法,在此不做赘述。
所述HTTP请求基础服务的实现代码可以但不限于如下:
Figure PCTCN2016088297-appb-000011
当然,本领域技术人员应当能够理解,上述对所述HTTP请求基础服务的实现代码的方式仅为举例,今后可能出现的所述HTTP请求基础服务的实现方式,如能使用本申请,均可以以引用的方式包含于此。
在一具体的场景中,对HTTP请求进行统一映射之前,可以首先创建对HTTP请求进行统一映射的框架,包括:创建一个用于访问第三方HTTP服务的映射文件,其中,所述映射文件包括配置参数和封装路径方法,其中,配置参数包括所述第三方HTTP服务的URL地址、端口及公共参数;封装路径方法包括:所述封装路径方法的属性、路径及其所调用的所述HTTP请求基础服务的方法名称。接着,在应用层创建用于访问第三方HTTP服务的接口,其中接口包括若干接口方法,若干接口方法与所述映射文件中的封装路径方法的属性(ID)一一对应,以能够通过属性的对应方式从接口对应到映射文件;在应用层,对所述接口注入动态代理注解,所述动态代理注解的属性与所述接口的属性相对应。然后,在应用层的业务方法中,将参数和URL进行逻辑拼接;在底层创建HTTP请求基础服务,所述HTTP请求基础服务中的方法包括基本HTTP请求:GET、POST、PUT和DELETE,此外,还可根据用户需要自定义HTTP请求。
则,当需要向第三方发起HTTP请求时,对HTTP请求进行统一映射的执行过程包括:
1.获取上述创建的用于访问第三方HTTP服务的映射文件、接口及接口的动态代理注解、以及应用层的业务方法;
2.当WEB容器启动时,利用JAXB(jackson-module-jaxb-annotations,能够使用Jackson对JAXB注解的支持实现)把自定义的映射文件里的标签,加载到内存生成相对应的JAVA对象;
3.为每个对象初始化之后,会找到这个对象对应的接口所对应的动态代理注解,并根据所述动态代理注解的属性,生成动态代理对象;
4.当有业务对相应动态代理注解的接口进行调用的时,动态代理对象就会进行拦截,反射到底层的HTTP请求基础服务,其中,反射过程包括:获取JAVA对象;从JAVA对象中获得URL对象、公用参数对象和封装路径方法对象,从所述URL对象中获取URL地址、从所述公共参数对象获取公共参数、并从所述封装路径方法对象中获取路径;封装路径;获取公共参数;封装真正的HTTP请求地址;根据所述URL地址,反射调用所述HTTP请求基础服务,完成一次HTTP调用。并利用底层的HTTP请求基础服务的方法发起HTTP请求,完成一次HTTP请求调用。
与现有技术相比,所述对HTTP请求进行统一映射的方法和设备通过获取用于访问第三方HTTP服务的映射文件,并获取所述映射文件对应的接口并为所述接口注入反射,其中,所述映射文件将HTTP请求的URL地址、端口、公共参数、和封装路径方法的属性、路径及其调用的HTTP请求基础服务中的方法等配置内容从业务逻辑内容中独立,并将映射文件将所述映射文件与所述接口相对应。当WEB启动时,根据映射文件生成相应JAVA对象,并根据请求调用相应接口对应的反射代理注解生成动态代理对象,则在进行HTTP请求时,动态代理对象会利用根据所述映射文件生成的JAVA对象处理所述请求,并调用HTTP请求基础服务中的方法,完成HTTP请求,从而实现映射文件的一次开发多次复用,从而在简化开发难度提高复用率的情况下实现HTTP请求调用。
在本申请一个典型的配置中,终端、服务网络的设备和可信方均包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功 能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括非暂存电脑可读媒体(transitory media),如调制的数据信号和载波。
需要注意的是,本申请可在软件和/或软件与硬件的组合体中被实施,例如,可采用专用集成电路(ASIC)、通用目的计算机或任何其他类似硬件设备来实现。在一个实施例中,本申请的软件程序可以通过处理器执行以实现上文所述步骤或功能。同样地,本申请的软件程序(包括相关的数据结构)可以被存储到计算机可读记录介质中,例如,RAM存储器,磁或光驱动器或软磁盘及类似设备。另外,本申请的一些步骤或功能可采用硬件来实现,例如,作为与处理器配合从而执行各个步骤或功能的电路。
另外,本申请的一部分可被应用为计算机程序产品,例如计算机程序指令,当其被计算机执行时,通过该计算机的操作,可以调用或提供根据本申请的方法和/或技术方案。而调用本申请的方法的程序指令,可能被存储在固定的或可移动的记录介质中,和/或通过广播或其他信号承载媒体中的数据流而被传输,和/或被存储在根据所述程序指令运行的计算机设备的工作存储器中。在此,根据本申请的一个实施例包括一个装置,该装置包括用于存储计算机程序指令的存储器和用于执行程序指令的处理器,其中,当该计算机程序指令被该处理器执行时,触发该装置运行基于前述根据本申请的多个实施例的方法和/或技术方案。
对于本领域技术人员而言,显然本申请不限于上述示范性实施例的细节,而且在不背离本申请的精神或基本特征的情况下,能够以其他的具体形式实现本申请。因此,无论从哪一点来看,均应将实施例看作是示范性的,而且是非限制性的,本申请的范围由所附权利要求而不是上述说明限定,因此旨在将落在权利要求的等同要件的含义和范围内的所有变化涵括在本申请内。不应将权利要求中的任何附图标记视为限制所涉及的权利要求。此外,显然“包括”一词不排除其他单元或步骤,单数不排除复数。装置权利要求中陈述的多个单元或装置也可以由一个单元或装置通过软件或者硬件来实现。第一,第二等词语用来表示名称,而并不表示任何特定的顺序。

Claims (20)

  1. 一种对HTTP请求进行统一映射的方法,其中,所述方法包括:
    获取用于访问第三方HTTP服务的映射文件,其中,所述映射文件包括HTTP请求的配置参数和封装路径方法;
    获取用于访问第三方HTTP服务的接口及与所述接口的动态代理注解,其中,所述接口包括若干接口方法,且所述接口方法的属性与所述HTTP请求的封装路径方法的属性一一对应;
    根据所述映射文件生成JAVA对象,并根据相应所述接口的动态代理注解生成动态代理对象;
    当获取到对具有动态代理注解的接口进行调用的请求时,利用所述动态代理对象拦截所述请求,并根据所述请求获取相应所述JAVA对象,并利用反射机制调用HTTP请求基础服务中的方法,以完成HTTP请求。
  2. 根据权利要求1所述的方法,其中,所述HTTP请求的配置参数至少包括以下任一项:
    所述第三方HTTP服务的URL地址、端口或公共参数;
    所述HTTP请求的封装路径方法至少包括以下任一项:
    所述封装路径方法的属性、路径或其所调用的所述HTTP请求基础服务的方法名称。
  3. 根据权利要求2所述的方法,其中,根据所述映射文件生成JAVA对象包括:
    根据所述映射文件中的配置参数和封装路径方法生成相对应的JAVA对象,其中,所述JAVA对象包括:
    URL对象、公共参数对象和封装路径方法对象。
  4. 根据权利要求3所述的方法,其中,根据所述映射文件生成JAVA对象包括:
    利用JAXB将所述映射文件中加载到内存,并生成相对应的所述JAVA对象。
  5. 根据权利要求3或4所述的方法,其中,根据所述请求获取相应所述JAVA对象,并利用反射机制调用HTTP请求基础服务中的方法包括:
    根据所述请求获取所述JAVA对象,其中,所述JAVA对象包括URL对象、公共参数对象和封装路径方法对象;
    从所述URL对象中获取URL地址、从所述公共参数对象获取公共参数、并从所述封装路径方法对象中获取路径;
    将所述公共参数和所述路径封装真正的HTTP请求地址;
    调用HTTP请求基础服务中的方法,利用所述真正的HTTP请求地址完成一次HTTP调用。
  6. 根据权利要求5所述的方法,其中,调用HTTP请求基础服务中的方法包括:
    利用反射技术调用HTTP请求基础服务中的方法。
  7. 根据权利要求1至6中任一项所述的方法,其中,所述动态代理注解的属性与所述接口的属性相同。
  8. 根据权利要求1至7中任一项所述的方法,其中,所述映射文件为XML格式文件。
  9. 根据权利要求1至8中任一项所述的方法,其中,所述HTTP请求基础服务包括基础HTTP请求方法,其中,所述基础HTTP请求方法至少包括以下任一项:
    请求指定的页面信息,并返回实体主体的方法;
    请求服务器接受所指定的文档作为对所标识的URI的新的从属实体的方法;
    从客户端向服务器传送的数据取代指定的文档的内容的方法;或
    请求服务器删除指定的页面的方法。
  10. 根据权利要求9所述的方法,其中,所述HTTP请求基础服务还包括自定义HTTP请求方法。
  11. 一种对HTTP请求进行统一映射的设备,其中,所述设备包括:
    映射文件获取装置,用于获取用于访问第三方HTTP服务的映射文件,其中,所述映射文件包括HTTP请求的配置参数和封装路径方法;
    接口获取装置,用于获取用于访问第三方HTTP服务的接口及与所述接口的动态代理注解,其中,所述接口包括若干接口方法,且所述接口方法的属性与所述HTTP请求的封装路径方法的属性一一对应;
    对象生成装置,用于根据所述映射文件生成JAVA对象,并根据相应所述接口的动态代理注解生成动态代理对象;
    HTTP请求执行装置,用于当获取到对具有动态代理注解的接口进行调用的请求时,利用所述动态代理对象拦截所述请求,并根据所述请求获取相应所述JAVA对象,并利用反射机制调用HTTP请求基础服务中的方法,以完成HTTP请求。
  12. 根据权利要求11所述的设备,其中,所述HTTP请求的配置参数至少包括以下任一项:
    所述第三方HTTP服务的URL地址、端口或公共参数;
    所述HTTP请求的封装路径方法至少包括以下任一项:
    所述封装路径方法的属性、路径或其所调用的所述HTTP请求基础服务的方法名称。
  13. 根据权利要求12所述的设备,其中,所述对象生成装置用于:
    根据所述映射文件中的配置参数和封装路径方法生成相对应的JAVA对象,其中,所述JAVA对象包括:
    URL对象、公共参数对象和封装路径方法对象。
  14. 根据权利要求13所述的设备,其中,所述对象生成装置用于:
    利用JAXB将所述映射文件中加载到内存,并生成所述相对应的JAVA。
  15. 根据权利要求13或14所述的设备,其中,所述HTTP请求执行装置用于:
    根据所述请求获取所述JAVA对象,其中,所述JAVA对象包括URL对象、公共参数对象和封装路径方法对象;
    从所述URL对象中获取URL地址、从所述公共参数对象获取公共参数、并从所述封装路径方法对象中获取路径;
    将所述公共参数和所述路径封装真正的HTTP请求地址;
    调用HTTP请求基础服务中的方法,并利用所述真正的HTTP请求地址完成一次HTTP调用。
  16. 根据权利要求15所述的设备,其中,所述HTTP请求执行装置用于:
    利用反射技术调用HTTP请求基础服务中的方法,并利用所述真正的HTTP请求地址完成一次HTTP调用。
  17. 根据权利要求11至16中任一项所述的设备,其中,所述动态代理注解的属性与所述接口的属性相同。
  18. 根据权利要求11或17所述的设备,其中,所述映射文件为XML格式文件。
  19. 根据权利要求11至18中任一项所述的设备,其中,所述HTTP请求基础服务包括基础HTTP请求方法,其中,所述基础HTTP请求方法至少包括以下任一项:
    请求指定的页面信息,并返回实体主体的方法;
    请求服务器接受所指定的文档作为对所标识的URI的新的从属实体的方法;
    从客户端向服务器传送的数据取代指定的文档的内容的方法;或
    请求服务器删除指定的页面的方法。
  20. 根据权利要求19所述的设备,其中,所述HTTP请求基础服务还包括自定义HTTP请求方法。
PCT/CN2016/088297 2015-07-13 2016-07-04 对http请求进行统一映射的方法和设备 WO2017008645A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201510408395.3A CN106354481B (zh) 2015-07-13 2015-07-13 对http请求进行统一映射的方法和设备
CN201510408395.3 2015-07-13

Publications (1)

Publication Number Publication Date
WO2017008645A1 true WO2017008645A1 (zh) 2017-01-19

Family

ID=57756822

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/088297 WO2017008645A1 (zh) 2015-07-13 2016-07-04 对http请求进行统一映射的方法和设备

Country Status (2)

Country Link
CN (1) CN106354481B (zh)
WO (1) WO2017008645A1 (zh)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109818980A (zh) * 2019-03-21 2019-05-28 中国铁塔股份有限公司 一种通信方法及装置
CN112181535A (zh) * 2020-09-21 2021-01-05 中国建设银行股份有限公司 一种接口调用方法、装置、服务器及存储介质
CN113626225A (zh) * 2021-10-11 2021-11-09 中航金网(北京)电子商务有限公司 程序调用方法、终端设备及介质
CN114489830A (zh) * 2021-12-23 2022-05-13 阿里巴巴(中国)有限公司 配置页面操作方法、处理方法和计算设备
CN114489830B (zh) * 2021-12-23 2024-06-07 阿里巴巴(中国)有限公司 配置页面操作方法、处理方法和计算设备

Families Citing this family (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108694194A (zh) * 2017-04-10 2018-10-23 北京京东尚科信息技术有限公司 一种构造数据对象的方法和装置
CN108134834A (zh) * 2017-12-22 2018-06-08 福建榕基软件股份有限公司 一种web端调用本地服务的方法及系统
CN108829467B (zh) * 2018-04-28 2020-05-22 蜂助手股份有限公司 第三方平台对接实现方法、装置、设备及存储介质
CN110554857B (zh) * 2018-05-30 2021-06-22 马上消费金融股份有限公司 JavaBean生成方法、装置、系统及可读存储介质
CN110704200A (zh) * 2018-07-09 2020-01-17 北京京东尚科信息技术有限公司 转换调用接口的方法和装置
CN109254808A (zh) * 2018-07-18 2019-01-22 平安科技(深圳)有限公司 接口调用方法、装置及计算机可读存储介质
CN109040316B (zh) * 2018-09-19 2021-08-27 天津字节跳动科技有限公司 Http服务处理方法和装置
CN110502224B (zh) * 2019-08-22 2023-04-28 深圳前海环融联易信息科技服务有限公司 基于http请求的接口模拟方法、装置和计算机设备
CN110795646A (zh) * 2019-09-30 2020-02-14 北京奇艺世纪科技有限公司 请求处理方法、装置、电子设备和计算机可读存储介质
CN111931087B (zh) * 2020-09-15 2021-02-05 新华三半导体技术有限公司 一种网页请求处理方法及装置
CN112202869B (zh) * 2020-09-27 2021-10-22 华人运通(上海)云计算科技有限公司 数据传输方法、服务器、车辆和计算机存储介质
CN112328917A (zh) * 2020-11-04 2021-02-05 浪潮云信息技术股份公司 一种面向SQL编写生成http接口服务和数据展示页面的方法
CN113507527B (zh) * 2021-07-20 2023-05-30 上海万物新生环保科技集团有限公司 一种基于网关转发的代码数据访问方法及设备

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103067511A (zh) * 2012-12-28 2013-04-24 上海寰创通信科技股份有限公司 一种http请求处理的控制方法
CN103561083A (zh) * 2013-10-31 2014-02-05 广州视源电子科技股份有限公司 一种物联网数据处理方法
US20140109041A1 (en) * 2012-10-09 2014-04-17 Tamer Yunten Yunten's Web Application Methodology & Web Programming Language (YWAM & WPL)
CN104317591A (zh) * 2014-10-23 2015-01-28 西安未来国际信息股份有限公司 一种基于OSGi的web界面框架系统及web业务处理方法
CN104580501A (zh) * 2015-01-23 2015-04-29 广东能龙教育股份有限公司 一种基于反射机制的Http接口动态发布方法与系统

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120209942A1 (en) * 2008-10-28 2012-08-16 Cotendo, Inc. System combining a cdn reverse proxy and an edge forward proxy with secure connections
WO2012106573A1 (en) * 2011-02-04 2012-08-09 Opnet Technologies, Inc. Correlating input and output requests between client and server components in a multi-tier application
US9104404B2 (en) * 2012-05-07 2015-08-11 Oracle International Corporation System and method for supporting a deferred reference to an object in an objected-oriented programming language environment
CN102799424B (zh) * 2012-06-12 2016-03-02 上海雷腾软件股份有限公司 一种敏捷式高效分层服务器端接口架构的实现方法

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140109041A1 (en) * 2012-10-09 2014-04-17 Tamer Yunten Yunten's Web Application Methodology & Web Programming Language (YWAM & WPL)
CN103067511A (zh) * 2012-12-28 2013-04-24 上海寰创通信科技股份有限公司 一种http请求处理的控制方法
CN103561083A (zh) * 2013-10-31 2014-02-05 广州视源电子科技股份有限公司 一种物联网数据处理方法
CN104317591A (zh) * 2014-10-23 2015-01-28 西安未来国际信息股份有限公司 一种基于OSGi的web界面框架系统及web业务处理方法
CN104580501A (zh) * 2015-01-23 2015-04-29 广东能龙教育股份有限公司 一种基于反射机制的Http接口动态发布方法与系统

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109818980A (zh) * 2019-03-21 2019-05-28 中国铁塔股份有限公司 一种通信方法及装置
CN112181535A (zh) * 2020-09-21 2021-01-05 中国建设银行股份有限公司 一种接口调用方法、装置、服务器及存储介质
CN113626225A (zh) * 2021-10-11 2021-11-09 中航金网(北京)电子商务有限公司 程序调用方法、终端设备及介质
CN114489830A (zh) * 2021-12-23 2022-05-13 阿里巴巴(中国)有限公司 配置页面操作方法、处理方法和计算设备
CN114489830B (zh) * 2021-12-23 2024-06-07 阿里巴巴(中国)有限公司 配置页面操作方法、处理方法和计算设备

Also Published As

Publication number Publication date
CN106354481B (zh) 2019-12-27
CN106354481A (zh) 2017-01-25

Similar Documents

Publication Publication Date Title
WO2017008645A1 (zh) 对http请求进行统一映射的方法和设备
US10579442B2 (en) Inversion-of-control component service models for virtual environments
US8839266B1 (en) Inter-application communication on mobile platforms
US9672140B1 (en) Processing special requests at dedicated application containers
CN111600909A (zh) 数据处理方法、装置、协议转换设备及存储介质
US8516554B2 (en) Dynamic web services system and method
WO2017045563A1 (zh) 一种web app访问方法、装置和系统
WO2017152753A1 (zh) 一种业务执行方法及装置
JP2015503799A (ja) 埋込まれたプロセス通信のための仮想チャネル
US20080082679A1 (en) Method and system for management protocol-based data streaming
US10162952B2 (en) Security model for network information service
WO2019057055A1 (zh) 一种任务处理方法、装置、电子设备及存储介质
JP6016808B2 (ja) Webアクセスを実装するための方法およびサーバシステム
US20180253342A1 (en) Discovery and exposure of transactional middleware server-based applications as consumable service endpoints
WO2017016408A1 (zh) 一种基于服务调用的故障处理方法、装置和系统
US8291432B2 (en) Providing invocation context to IMS service provider applications
KR20150089301A (ko) 매쉬업 서비스를 위한 가상 api 제공 장치 및 방법
WO2016206566A1 (zh) 一种网页请求的处理方法、装置和系统
CN113381866A (zh) 基于网关的服务调用方法、装置、设备及存储介质
US20070255720A1 (en) Method and system for generating and employing a web services client extensions model
AU2018390863B2 (en) Computer system and method for extracting dynamic content from websites
US10402307B2 (en) System and method for providing runtime tracing for a web-based client accessing a transactional middleware platform using an extension interface
TW201735583A (zh) 調用文件之方法與裝置
US7571236B2 (en) System and method for managing connections
US7716197B2 (en) XCAP and SIP filter chain state transforms via dynamic helper functions for internet multimedia subsystems

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 16823792

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 16823792

Country of ref document: EP

Kind code of ref document: A1