Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for jboss/wildfly/resteasy #91

Closed
ovkhasch opened this issue Dec 12, 2018 · 3 comments
Closed

Support for jboss/wildfly/resteasy #91

ovkhasch opened this issue Dec 12, 2018 · 3 comments

Comments

@ovkhasch
Copy link

We were trying to run OCI SDK client from an app deployed to wildfly 10.1.0, but were having issues with a default client configuration. I suggest to create a specialized resteasy client configurator, similar to ApacheConfigurator. We had to resolve the following two issues:

  1. The request body is being passed as a java.lang.String object to a json provider. This results in the following error:
Caused by: javax.ws.rs.ProcessingException: RESTEASY004655: Unable to invoke request
	at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:287)
	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:436)
	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocationBuilder.post(ClientInvocationBuilder.java:195)
	at com.oracle.bmc.http.internal.ForwardingInvocationBuilder.post(ForwardingInvocationBuilder.java:154)
	at com.oracle.bmc.http.internal.RestClient.post(RestClient.java:144)
	... 9 more
Caused by: javax.ws.rs.ProcessingException: RESTEASY003215: could not find writer for content-type application/json type: java.lang.String
	at org.jboss.resteasy.core.interception.ClientWriterInterceptorContext.throwWriterNotFoundException(ClientWriterInterceptorContext.java:40)
	at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.getWriter(AbstractWriterInterceptorContext.java:140)
	at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:119)
	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.writeRequestBody(ClientInvocation.java:370)
	at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.writeRequestBodyToOutputStream(ApacheHttpClient4Engine.java:558)
	at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.buildEntity(ApacheHttpClient4Engine.java:524)
	at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.loadHttpMethod(ApacheHttpClient4Engine.java:423)
	at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:281)
	... 13 more

the workaround would be to use the following custom provider:

@Provider
@Produces(MediaType.APPLICATION_JSON)
public class RawStringJsonProvider implements MessageBodyWriter<String> {
    @Override
    public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType){
        if (String.class.equals(type) && mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) {
            return true;
        }

        return false;
    }

    @Override
    public long getSize(String s, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
        return 0;
    }

    @Override
    public void writeTo(String s, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
        Writer writer = new PrintWriter(entityStream);
        writer.write(s);
        writer.flush();
        writer.close();
    }
}
  1. A content-length header is being added by AuthnClientFilter, which results in:
Caused by: javax.ws.rs.ProcessingException: RESTEASY004655: Unable to invoke request
	at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:287)
	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:436)
	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocationBuilder.post(ClientInvocationBuilder.java:195)
	at com.oracle.bmc.http.internal.ForwardingInvocationBuilder.post(ForwardingInvocationBuilder.java:154)
	at com.oracle.bmc.http.internal.RestClient.post(RestClient.java:144)
	... 75 more
Caused by: org.apache.http.client.ClientProtocolException
	at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:886)
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
	at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:283)
	... 79 more
Caused by: org.apache.http.ProtocolException: Content-Length header already present
	at org.apache.http.protocol.RequestContent.process(RequestContent.java:96)
	at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:132)
	at org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:166)
	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:485)
	at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882)
	... 82 more

This can be fixed by either adding another filter which simply removes this header or using ApacheConfigurator like this:

VirtualNetworkClient vcnClient = VirtualNetworkClient.builder().clientConfigurator(new ApacheConfigurator()).build(provider);
@jodoglevy
Copy link
Member

jodoglevy commented Dec 13, 2018

Good timing - I think we're actually already working on exactly this :)

Hopefully should have something to report soon.

@dayongfu
Copy link

Now Java SDK should support resteasy. Please check https://github.com/oracle/oci-java-sdk/blob/master/CHANGELOG.md for the examples. Please let us know if you have any problem to use it.

@jodoglevy
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants