Skip to content

Commit

Permalink
Fix #28
Browse files Browse the repository at this point in the history
commit d8e267e8938327d4358d2a9743dd5997c6888517
Author: Clement Escoffier <[email protected]>
Date:   Sat Apr 19 17:13:52 2014 +0200

    Implement the XML service (#28)

    The XML service implementation is merge with the JSON service implementation as both are based on Jackson. It also simplifies the Jackson Module management

    Signed-off-by: Clement Escoffier <[email protected]>

commit 0e41b3c44b61ae2e465c2c3cb384a15da48178ee
Author: Clement Escoffier <[email protected]>
Date:   Sat Apr 19 17:11:13 2014 +0200

    Provides a XML body parser and serializer (#28)

    Signed-off-by: Clement Escoffier <[email protected]>

commit 1427b77bd2c43889d496942b1b61b32c3708052c
Author: Clement Escoffier <[email protected]>
Date:   Sat Apr 19 17:10:49 2014 +0200

    Small improvements in the XML service (#28)

    added a newDocument method
    Use Charset instead of String

    Signed-off-by: Clement Escoffier <[email protected]>

commit 42e62e529326f8baed9fa19cde87137f3f61ad50
Author: Clement Escoffier <[email protected]>
Date:   Sat Apr 19 12:19:26 2014 +0200

    Add method to provides XML document as response's payload (#28)

    Signed-off-by: Clement Escoffier <[email protected]>

commit a52a9b840108f8dc60d63671d98bca46529bbba5
Author: Clement Escoffier <[email protected]>
Date:   Sat Apr 19 11:54:22 2014 +0200

    Provide a renderable implementation taking an XML document as parameter.

    This implementation does not use Jackson as the JRE provides enough facilities.

    Signed-off-by: Clement Escoffier <[email protected]>

commit bc172308abd746e92b4904a5e5832e1208206820
Author: Clement Escoffier <[email protected]>
Date:   Sat Apr 19 11:49:24 2014 +0200

    Initial definition of the XML service (#28)

    Signed-off-by: Clement Escoffier <[email protected]>

commit 6ac12abedd5cab08795774fa45c3844afc779a51
Author: Clement Escoffier <[email protected]>
Date:   Sat Apr 19 11:13:03 2014 +0200

    Added XML related bundle to the base distribution (#28)

    Signed-off-by: Clement Escoffier <[email protected]>

Signed-off-by: Clement Escoffier <[email protected]>
  • Loading branch information
cescoffier committed Apr 19, 2014
1 parent ee0a48c commit 874837a
Show file tree
Hide file tree
Showing 18 changed files with 1,121 additions and 287 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* #%L
* Wisdom-Framework
* %%
* Copyright (C) 2013 - 2014 Wisdom Framework
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package org.wisdom.content.bodyparsers;

import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Provides;
import org.apache.felix.ipojo.annotations.Requires;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wisdom.api.content.BodyParser;
import org.wisdom.api.content.Xml;
import org.wisdom.api.http.Context;
import org.wisdom.api.http.MimeTypes;

import java.io.IOException;

@Component
@Provides
@Instantiate
public class BodyParserXML implements BodyParser {

@Requires
Xml xml;

private static final String ERROR = "Error parsing incoming XML";

private static final Logger LOGGER = LoggerFactory.getLogger(BodyParserXML.class);

public <T> T invoke(Context context, Class<T> classOfT) {
T t = null;
try {
final String content = context.body();
if (content == null || content.length() == 0) {
return null;
}
t = xml.xmlMapper().readValue(content, classOfT);
} catch (IOException e) {
LOGGER.error(ERROR, e);
}

return t;
}

@Override
public <T> T invoke(byte[] bytes, Class<T> classOfT) {
T t = null;
try {
t = xml.xmlMapper().readValue(bytes, classOfT);
} catch (IOException e) {
LOGGER.error(ERROR, e);
}

return t;
}

public String getContentType() {
return MimeTypes.XML;
}

}
Loading

0 comments on commit 874837a

Please sign in to comment.