小编cat*_*hyk的帖子

如何在Spring Boot中处理传入和传出的SOAP XML消息

我有一个使用的SOAP客户端WebServiceGatewaySupport。它可以按预期工作:它具有编组功能,可以完美地发送和检索XML消息。但是,现在我想在服务中处理该XML消息。我只能记录的跟踪消息WebServiceTemplate。但是,我需要围绕服务的纯XML消息。如何实现呢?

@Service
public class SampleGatewayClient extends WebServiceGatewaySupport {
    ...
    public SampleGatewayClient() {
        this.setMarshaller(marshaller);
        this.setUnmarshaller(marshaller);
        this.setDefaultUri(defaultUri);
    }
    ...

    private ResponseObject sendAndRetrieveMessage() {
        ...
        // No control over sended and received messages!
        return (ResponseObject) getWebServiceTemplate()
            .marshalSendAndReceive(gatewayUri, requestPayload);
    }
}
Run Code Online (Sandbox Code Playgroud)

xml spring soap

6
推荐指数
0
解决办法
87
查看次数

如何使用 authlib 保存和重用令牌

我是authlib的初学者,并试图理解它的概念。

我尝试了解,如何保存和重用获取的令牌authlib

我创建了一个小FastAPI项目:

from fastapi import FastAPI
from starlette.config import Config
from starlette.middleware.sessions import SessionMiddleware
from starlette.requests import Request
from authlib.integrations.starlette_client import OAuth


app = FastAPI()
app.add_middleware(SessionMiddleware, secret_key="some-random-secret")

config = Config(".env")
oauth = OAuth(config)

oauth.register(
    name="some_service",
    client_id="client_id",
    client_secret="client_secret",
    authorize_url="https://some-service.com/auth",
    access_token_url="https://some-service.com/token",
    client_kwargs={
        "token_endpoint_auth_method": "client_secret_post",
    },
)


@app.get("/login")
async def login(request: Request):
    redirect_uri = "https://myservice.com/auth"
    return await oauth.some_service.authorize_redirect(request, redirect_uri)


@app.get("/auth")
async def auth(request: Request):
    token = await oauth.some_service.authorize_access_token(request)
    # I suppose that I should save somehow token …
Run Code Online (Sandbox Code Playgroud)

python authlib starlette fastapi

5
推荐指数
1
解决办法
898
查看次数

如何在Django Rest Framework中隐藏一些字段以进行响应

另一个DRF新手在这里。

我想隐藏一些字段以响应我的REST API。

假设我有一些基本的Exchange服务

serializers.py

class ConversionSerializer(serializers.Serializer):
    value = serializers.FloatField()
    from_ = serializers.ChoiceField(choices=SOME_CHOICES)
    to_ = serializers.ChoiceField(choices=SOME_CHOICES)
    converted_value = serializers.SerializerMethodField(read_only=True)
    ....
Run Code Online (Sandbox Code Playgroud)

views.py

class ConversionAPIView(APIView):
    serializer_class = ConversionSerializer
    permission_classes = []

    def post(self, request, *args, **kwargs):
        serializer = self.serializer_class(data=request.data)
        serializer.is_valid(raise_exception=True)
        return Response(serializer.data)
        ....
Run Code Online (Sandbox Code Playgroud)

对于我的POST请求,我传递了3个值:value,from,to。作为响应,我得到4个值:value,from,to,converted_value。

{
    "value": 100,
    "from_": "foo",
    "to_": "bar",
    "converted_value": 200
} 
Run Code Online (Sandbox Code Playgroud)

现在,我只想获得而不是所有字段作为响应的converted_value。如何执行呢?谢谢

django django-rest-framework

2
推荐指数
1
解决办法
1614
查看次数

如何在 Spring REST 服务中获取所有传入请求的详细信息?

我想查看使用 Spring Boot 构建的端点中的所有请求相关详细信息(例如标头、正文)。如何获得?

@RestController
public class SomeRestController {
    ...
    @PostMapping("path/")
    public String getResponse(@RequestBody SomeObject object) {
        // There I want to look at Request details... but how?
        ...
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

java spring http-post spring-boot

1
推荐指数
1
解决办法
3043
查看次数

如何启动/测试/尝试 Bootstrap 示例?

我已经从https://getbootstrap.com/docs/4.1/examples/下载了 Bootstrap 4.1 源代码。我只想测试或运行它。我认为只需打开index.html并以 HTML 文档形式查看执行的源代码就足够了。它绝对没有按预期运行。

请帮助新手。

npm twitter-bootstrap

1
推荐指数
1
解决办法
3688
查看次数

在MacOS Sierra上安装mysqlclient时出错(Python 3.6)

我正在尝试为我的MacOS Sierra(Python3)安装mysqlclient.

好吧,我试图按照官方页面https://github.com/PyMySQL/mysqlclient-python上的说明操作.

所以,一切都很好,直到:

pip install mysqlclient
pip3 install mysqlclient
Run Code Online (Sandbox Code Playgroud)

它让我接下来的事情:

Collecting mysqlclient
  Using cached mysqlclient-1.3.10.tar.gz
  Complete output from command python setup.py egg_info:
  Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/q4/j199zrpj015c7dyj7qfl22qm0000gn/T/pip-build-9v6DOo/mysqlclient/setup.py", line 17, in <module>
    metadata, options = get_config()
      File "setup_posix.py", line 54, in get_config libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
      File "setup_posix.py", line 12, in dequote if s[0] in "\"'" and s[0] == s[-1]:
  IndexError: string index out of …
Run Code Online (Sandbox Code Playgroud)

python mysql pip python-3.6

0
推荐指数
1
解决办法
2028
查看次数