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

Location support in Response #320

Closed
tharindu1st opened this issue Nov 6, 2016 · 4 comments
Closed

Location support in Response #320

tharindu1st opened this issue Nov 6, 2016 · 4 comments

Comments

@tharindu1st
Copy link
Contributor

We are going to use below snippets in order to do POST request with 201 response. We want to send the Created resource location through the Response. Once we implement that we came up with below stack trace.

WARN {org.wso2.msf4j.internal.MSF4JMessageProcessor} - Unmapped exception java.lang.UnsupportedOperationException
at org.wso2.msf4j.delegates.MSF4JResponse$Builder.location(MSF4JResponse.java:334)
at javax.ws.rs.core.Response.created(Response.java:699)
at org.wso2.carbon.apimgt.rest.api.publisher.impl.ApisApiServiceImpl.apisPost(ApisApiServiceImpl.java:260)
at org.wso2.carbon.apimgt.rest.api.publisher.ApisApi.apisPost(ApisApi.java:425)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.wso2.msf4j.internal.router.HttpMethodInfo.invoke(HttpMethodInfo.java:132)
at org.wso2.msf4j.internal.MSF4JMessageProcessor.dispatchMethod(MSF4JMessageProcessor.java:130)
at org.wso2.msf4j.internal.MSF4JMessageProcessor.receive(MSF4JMessageProcessor.java:72)
at org.wso2.carbon.transport.http.netty.listener.WorkerPoolDispatchingSourceHandler.lambda$publishToWorkerPool$12(WorkerPoolDispatchingSourceHandler.java:125)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

https://github.com/wso2/carbon-apimgt/blob/a94893c66473febc597b2895afe329ceccb1fbd3/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/impl/ApisApiServiceImpl.java#L260

@thusithathilina
Copy link
Contributor

thusithathilina commented Nov 6, 2016

ATM, MSF4J doesn't support the Response.location(). We will fix this in the next release. Until that, as a workaround, you can set the status code and location header manually.

e.g.
Response.status(Response.Status.CREATED).header(HttpHeaders.LOCATION, "http://localhost:8080/service/abc?page=2").build();

@tharindu1st
Copy link
Contributor Author

HI,
If we are going to send the Location as Header how we can resolve the Base Uri of the Host in order to create the full url.

@thusithathilina
Copy link
Contributor

Hi Tharindu,

Can you try like below

@GET
@Path("/")
public Response abc(.... @Context Request request) {
       String host = request.getHeader("Host"); //request.getProperty("LOCAL_ADDRESS") should also work
       .....
}

@imesh
Copy link
Contributor

imesh commented Mar 28, 2017

Tharindu, we are closing this issue as this problem has been fixed in #345. If you find any problems please feel free to reopen. Thanks!

@imesh imesh closed this as completed Mar 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants