用于在OAuth 2.0中调用REST http方法补丁的JAVA代码

时间:2018-05-08 15:19:20

标签: java rest oauth-2.0 httpclient apache-httpclient-4.x

我需要调用补丁方法到外部OAuth2.0服务器。

我实现了java代码来调用http rest方法补丁。 但是这段代码对调用补丁调用没什么帮助。

请求您,请帮助创建一个代码来调用'patch'方法。

`

importcom.wm.data.*;
    importcom.wm.util.Values;
    importcom.wm.app.b2b.server.Service;
    importcom.wm.app.b2b.server.ServiceException;
    importcom.sun.security.ntlm.Client;
    importjava.io.*;
    importjava.net.*;
    importokhttp3.Headers;
    importokhttp3.MediaType;
    importokhttp3.OkHttpClient;
    importokhttp3.Request;
    importokhttp3.RequestBody;
    importokhttp3.Response;
    importjavax.sound.midi.Patch;
    importorg.apache.commons.io.IOUtils;
    importorg.apache.http.client.ClientProtocolException;
    importorg.apache.http.client.methods.*;
    importorg.apache.http.Header;
    importorg.apache.http.HttpEntity;
    importorg.apache.http.entity.StringEntity;
    importorg.apache.http.util.EntityUtils;
    importorg.apache.http.HttpResponse;
    importorg.apache.http.client.methods.HttpPatch;
    importorg.apache.http.impl.*;
    importorg.apache.http.impl.client.DefaultHttpClient;
    publicfinalclasstestPatchCall_SVC
    {
    /**
    *TheprimarymethodfortheJavaservice
    *
    *@parampipeline
    *TheIDatapipeline
    *@throwsServiceException
    */
    publicstaticfinalvoidtestPatchCall(IDatapipeline)throwsServiceException{
    //pipeline
    IDataCursorpipelineCursor=pipeline.getCursor();
    logger("Entered");
    StringURL=IDataUtil.getString(pipelineCursor,"URL");
    StringrequestData=IDataUtil.getString(pipelineCursor,"requestData");
    StringHttpMethod=IDataUtil.getString(pipelineCursor,"HttpMethod");
    //headers
    IData[]HeadersCall=IDataUtil.getIDataArray(pipelineCursor,"HeadersCall");
    if(HeadersCall!=null)
    {
    for(inti=0;i<HeadersCall.length;i++)
    {
    IDataCursorheadersCursor=HeadersCall[i].getCursor();
    Stringname=IDataUtil.getString(headersCursor,"name");
    Stringvalue=IDataUtil.getString(headersCursor,"value");
    headersCursor.destroy();
    }
    }
    pipelineCursor.destroy();
    MediaTypemediaType=MediaType.parse("application/json");
    OkHttpClientclient=newOkHttpClient();
    logger("Initiatingrequest");
    RequestBodybody=RequestBody.create(mediaType,requestData);
    Requestrequest=newRequest.Builder()
    .url(URL).patch(body).addHeader("content-type","application/json")
    .addHeader("Accept","application/json")
    .addHeader("Authorization","Bearer1213ABANCBYD").build();
    try{
    logger("Calling"+request);
    Responseresponse=client.newCall(request).execute();
    logger(response.body().string());
    }catch(Exceptione){
    logger(e.toString());
    }
    //pipelin
    IDataCursorpipelineCursor_1=pipeline.getCursor();
    ObjectresponseData=newObject();
    IDataUtil.put(pipelineCursor_1,"response",responseData);
    pipelineCursor_1.destroy();
    }
    //---<<IS-BEGIN-SHARED-SOURCE-AREA>>---
    privatestaticHttpURLConnectionsetRequestProperty(IData[]headers){
    //TODOAuto-generatedmethodstub
    returnnull;
    }
    privatestaticHttpURLConnectionsetRequestMethod(Stringmethod){
    //TODOAuto-generatedmethodstub
    returnnull;
    }
    //---<<IS-END-SHARED-SOURCE-AREA>>--
    /**
    *Theserviceimplementationsgivenbelowareread-onlyandshowonlythe
    *methoddefinitionsandnotthecompleteimplementation.
    */
    publicstaticfinalvoidaddInts(IDatapipeline)throwsServiceException{
    }
    publicstaticfinalvoidpatchMethod(IDatapipeline)throwsServiceException{
    }
    publicstaticfinalvoidRestPatch(IDatapipeline)throwsServiceException{
    }
    }`

我正在尝试将补丁调用数据从我的服务器发送到OAuth 2.0服务器。

这里我使用应用程序作为OAuth(资源服务器)的客户端。

我已经通过调用POST http方法实现了获取Bearer令牌的代码。并成功获得令牌。

在我尝试拨打补丁电话后。

谢谢, SRINIVAS

0 个答案:

没有答案