500 ERRO when create image with non-iso name #915

Open
liujunpengwork opened this Issue Jan 9, 2017 · 3 comments

Projects

None yet

2 participants

@liujunpengwork
Contributor

I got error 500 when I create a image with non-iso name.
the code as follow:
image = osclient.images().create(
Builders.image()
.name("中文").ispublic(true)
.containerFormat(ContainerFormat.BARE)
.diskFormat(DiskFormat.QCOW2).build(),
Payloads.create(new File("test.img")));
I use httpclient connector,and openstack is mitaka. I can create the image with nos-iso name using horizon UI.

@auhlig
Member
auhlig commented Jan 11, 2017

Could you share more details @liujunpengwork?
For instance some logs, rest request and response..

@liujunpengwork
Contributor

Request

[2017-01-16 14:55:56.511] [DEBUG] [main] [org.apache.http.wire] [org.apache.http.impl.conn.Wire.wire(Wire.java:72)] - [http-outgoing-1 >> "POST /v1/images HTTP/1.1[\r][\n]"]
[2017-01-16 14:55:56.511] [DEBUG] [main] [org.apache.http.wire] [org.apache.http.impl.conn.Wire.wire(Wire.java:72)] - [http-outgoing-1 >> "Accept: application/json; charset=utf-8[\r][\n]"]
[2017-01-16 14:55:56.511] [DEBUG] [main] [org.apache.http.wire] [org.apache.http.impl.conn.Wire.wire(Wire.java:72)] - [http-outgoing-1 >> "X-Image-Meta-Protected: false[\r][\n]"]
[2017-01-16 14:55:56.511] [DEBUG] [main] [org.apache.http.wire] [org.apache.http.impl.conn.Wire.wire(Wire.java:72)] - [http-outgoing-1 >> "X-Image-Meta-Name: -[0x87][\r][\n]"]
[2017-01-16 14:55:56.511] [DEBUG] [main] [org.apache.http.wire] [org.apache.http.impl.conn.Wire.wire(Wire.java:72)] - [http-outgoing-1 >> "X-Image-Meta-Min_ram: 0[\r][\n]"]
[2017-01-16 14:55:56.511] [DEBUG] [main] [org.apache.http.wire] [org.apache.http.impl.conn.Wire.wire(Wire.java:72)] - [http-outgoing-1 >> "X-Image-Meta-Min_disk: 0[\r][\n]"]
[2017-01-16 14:55:56.511] [DEBUG] [main] [org.apache.http.wire] [org.apache.http.impl.conn.Wire.wire(Wire.java:72)] - [http-outgoing-1 >> "X-Image-Meta-Is_public: true[\r][\n]"]
[2017-01-16 14:55:56.511] [DEBUG] [main] [org.apache.http.wire] [org.apache.http.impl.conn.Wire.wire(Wire.java:72)] - [http-outgoing-1 >> "X-Auth-Token: f27f76d52fae4a41bccea706a911b9db[\r][\n]"]
[2017-01-16 14:55:56.511] [DEBUG] [main] [org.apache.http.wire] [org.apache.http.impl.conn.Wire.wire(Wire.java:72)] - [http-outgoing-1 >> "User-Agent: OpenStack4j / OpenStack Client[\r][\n]"]
[2017-01-16 14:55:56.511] [DEBUG] [main] [org.apache.http.wire] [org.apache.http.impl.conn.Wire.wire(Wire.java:72)] - [http-outgoing-1 >> "X-Image-Meta-Container_format: bare[\r][\n]"]
[2017-01-16 14:55:56.511] [DEBUG] [main] [org.apache.http.wire] [org.apache.http.impl.conn.Wire.wire(Wire.java:72)] - [http-outgoing-1 >> "X-Image-Meta-Disk_format: qcow2[\r][\n]"]
[2017-01-16 14:55:56.511] [DEBUG] [main] [org.apache.http.wire] [org.apache.http.impl.conn.Wire.wire(Wire.java:72)] - [http-outgoing-1 >> "Transfer-Encoding: chunked[\r][\n]"]
[2017-01-16 14:55:56.511] [DEBUG] [main] [org.apache.http.wire] [org.apache.http.impl.conn.Wire.wire(Wire.java:72)] - [http-outgoing-1 >> "Content-Type: application/octet-stream[\r][\n]"]
[2017-01-16 14:55:56.511] [DEBUG] [main] [org.apache.http.wire] [org.apache.http.impl.conn.Wire.wire(Wire.java:72)] - [http-outgoing-1 >> "Host: 100.2.30.96:9292[\r][\n]"]
[2017-01-16 14:55:56.511] [DEBUG] [main] [org.apache.http.wire] [org.apache.http.impl.conn.Wire.wire(Wire.java:72)] - [http-outgoing-1 >> "Connection: Keep-Alive[\r][\n]"]
[2017-01-16 14:55:56.511] [DEBUG] [main] [org.apache.http.wire] [org.apache.http.impl.conn.Wire.wire(Wire.java:72)] - [http-outgoing-1 >> "Accept-Encoding: gzip,deflate[\r][\n]"]

Response

Exception in thread "main" ServerResponseException{message=Internal Server Error, status=500, status-code=INTERNAL_SERVER_ERROR}
at org.openstack4j.core.transport.HttpExceptionHandler.mapException(HttpExceptionHandler.java:40)
at org.openstack4j.core.transport.HttpExceptionHandler.mapException(HttpExceptionHandler.java:23)
at org.openstack4j.core.transport.HttpEntityHandler.handle(HttpEntityHandler.java:51)
at org.openstack4j.connectors.httpclient.HttpResponseImpl.getEntity(HttpResponseImpl.java:65)
at org.openstack4j.openstack.internal.BaseOpenStackService$Invocation.execute(BaseOpenStackService.java:193)
at org.openstack4j.openstack.internal.BaseOpenStackService$Invocation.execute(BaseOpenStackService.java:187)
at org.openstack4j.openstack.image.internal.ImageServiceImpl.create(ImageServiceImpl.java:143)
at dubbo.test.testM.main(testM.java:30)

The reason

I found is that http-connector doesn't encode non-iso chars to ISO8859-1 in the http header.
https://github.com/ContainX/openstack4j/blob/master/connectors/httpclient/src/main/java/org/openstack4j/connectors/httpclient/HttpCommand.java

private void populateHeaders(HttpRequest request) {

    if (!request.hasHeaders())
        return;

    for (Map.Entry<String, Object> h : request.getHeaders().entrySet()) {
        clientReq.addHeader(h.getKey(), String.valueOf(h.getValue()));
    }
}
@auhlig
Member
auhlig commented Jan 17, 2017

Cool @liujunpengwork.
Since you already found the root cause, would you like to contribute and submit a fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment