Retrofit2 and baseurl in GitLap - retrofit2

I am trying to learn retrofit2 by showing my project's GitLab name into recyclerView . but I can not find what is exactly what to do!!!
according gitlab wiki I found private-tokens and list of projrct.
this is my baseUrl and I create a builder:
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl("https://gitlab.com/api/v4/projects?private_token=xxxxxx")
.addConverterFactory(GsonConverterFactory.create());
and this is my endpoint:
#GET("/users/:{userid}/projects")
Call<List<GitLabRepo>> reposForUser(#Path("userid") int user);
my GitLabRepo pojo class:
class GitLabRepo {
private String name;
public String getName() {
return name;
}
}
after running I got this error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sayres.createandroidclient/com.example.sayres.createandroidclient.MainActivity}: java.lang.IllegalArgumentException: baseUrl must end in /: https://gitlab.com/api/v4/projects?private_token=rjezfrSUTn3fcugxLujm/
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.IllegalArgumentException: baseUrl must end in /: https://gitlab.com/api/v4/projects?private_token=xxxxxx/
at retrofit2.Retrofit$Builder.baseUrl(Retrofit.java:513)
at retrofit2.Retrofit$Builder.baseUrl(Retrofit.java:456)
at com.example.sayres.createandroidclient.MainActivity.onCreate(MainActivity.java:34)
at android.app.Activity.performCreate(Activity.java:6679)
I know my problem is related to baseUrl but what is correct gitLab BaseUrl?
I want just show my project name into list at recycelerview list.
******************Edit******************
I use of poster :
https://gitlab.com/api/v4/projects?private_token=******/users/:******/projects
And I got :
{
"message": "401 Unauthorized"
}
I see into Status codes at gitlab wiki and wrote there:
401 Unauthorized The user is not authenticated, a valid user token is necessary.
but I have added Private Tokens .

remove the forward slash '/' from get i.e,change your code like this
#GET("users/:{userid}/projects/")
Call<List<GitLabRepo>> reposForUser(#Path("userid") int user);
and add '/' in your endpoint like this
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl("https://gitlab.com/api/v4/projects?private_token=xxxxxx/")
.addConverterFactory(GsonConverterFactory.create());

Related

Quarkus security smallrye jwt

I'm making a webservice in quarkus, and I want to generate tokens validate the user in my endpoints (the users are located in a JDBC). I will not use other services like keycloak. Just quarkus and my front (vuejs).
I'm trying to generate the tokens just in quarkus. How can I do it?
I'm doing something like this...
`#ApplicationScoped
public class JwtGen {
public void gen() {
String token =
Jwt.upn("arthur")
.groups(new HashSet<>(Arrays.asList("User")))
.sign();
System.out.println(token);
}
}
`
I created a publicKey.pem and in application.propperties, make this linemp.jwt.verify.publickey.location=publicKey.pem
Edit: My application.properties
quarkus.http.cors=true
quarkus.http.cors.origins=*
quarkus.smallrye-jwt.enabled=true
mp.jwt.verify.publickey=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlivFI8qB4D0y2jy0CfEqFyy46R0o7S8TKpsx5xbHKoU1VWg6QkQm+ntyIv1p4kE1sPEQO73+HY8+Bzs75XwRTYL1BmR1w8J5hmjVWjc6R2BTBGAYRPFRhor3kpM6ni2SPmNNhurEAHw7TaqszP5eUF/F9+KEBWkwVta+PZ37bwqSE4sCb1soZFrVz/UT/LF4tYpuVYt3YbqToZ3pZOZ9AX2o1GCG3xwOjkc4x0W7ezbQZdC9iftPxVHR8irOijJRRjcPDtA6vPKpzLl6CyYnsIYPd99ltwxTHjr3npfv/3Lw50bAkbT4HeLFxTx4flEoZLKO/g0bAoV2uqBhkA9xnQIDAQAB
mp.jwt.decrypt.key.location=privateKey.pem
mp.jwt.verify.issuer=https://example.com/issuer
This is the log error
io.smallrye.jwt.build.JwtSignatureException: SRJWT05009:
at io.smallrye.jwt.build.impl.JwtSignatureImpl.sign(JwtSignatureImpl.java:77)
at br.com.infralog.JwtGen.gen(JwtGen.java:17)
at br.com.infralog.JwtGen_Subclass.gen$$superforward1(JwtGen_Subclass.zig:89)
at br.com.infralog.JwtGen_Subclass$$function$$6.apply(JwtGen_Subclass$$function$$6.zig:24)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:62)
at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)
at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(InvocationInterceptor_Bean.zig:521)
at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
at br.com.infralog.JwtGen_Subclass.gen(JwtGen_Subclass.zig:145)
at br.com.infralog.JwtGen_ClientProxy.gen(JwtGen_ClientProxy.zig:126)
at br.com.infralog.webservice.StateWsResource.list(StateWsResource.java:58)
at br.com.infralog.webservice.StateWsResource_Subclass.list$$superforward1(StateWsResource_Subclass.zig:324)
at br.com.infralog.webservice.StateWsResource_Subclass$$function$$27.apply(StateWsResource_Subclass$$function$$27.zig:53)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:62)
at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)
at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(InvocationInterceptor_Bean.zig:521)
at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
at br.com.infralog.webservice.StateWsResource_Subclass.list(StateWsResource_Subclass.zig:556)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:170)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:130)
at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:660)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:524)
at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$2(ResourceMethodInvoker.java:474)
at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:476)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:434)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:408)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:69)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:492)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:261)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:161)
at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:164)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:247)
at io.quarkus.resteasy.runtime.standalone.RequestDispatcher.service(RequestDispatcher.java:73)
at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.dispatch(VertxRequestHandler.java:138)
at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler$1.run(VertxRequestHandler.java:93)
at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:481)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2442)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1476)
at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalArgumentException: SRJWT05021: Please set a 'smallrye.jwt.sign.key.location' property
at io.smallrye.jwt.build.impl.JwtSignatureImpl.getKeyLocationFromConfig(JwtSignatureImpl.java:187)
at io.smallrye.jwt.build.impl.JwtSignatureImpl.sign(JwtSignatureImpl.java:72)
... 53 more
Please I'm in this for almost a weak... PLEASE HELPPP!!
I think that the answer is in the Exception message:
Please set a 'smallrye.jwt.sign.key.location' property
So if you did not yet set the private key in your application.properties this will most probably help you. Without it, it is impossible to generate a token.
This can be found in the documentation as well:
Note for this code to work we need the content of the RSA private key that corresponds to the public key we have in the TokenSecuredResource application.
How to configure and generate public and private keys is also described there.

Extend StagedModelDataHandler for Journal Article in Staging

I am working on local live staging in Liferay 7.1, in which I have one custom field in Web content. When I export those web content to local live, I want to check that custom field as result I would be export that web content.
So for that, I am extending doExportStagedModel in BaseStagedModelDataHandler as below.
#Component(immediate = true,service = {StagedModelDataHandler.class})
public class Demo extends BaseStagedModelDataHandler<JournalArticle> {
// All the stuff
#Override
protected void doExportStagedModel(
PortletDataContext portletDataContext, JournalArticle article)
throws Exception {
// overridden stuff
}
// Other stuff
}
When I am deploying this, I got below exception.
2018-11-20 04:04:12.669 ERROR The setJournalCreationStrategy method
has thrown an exception java.lang.IllegalArgumentException: argument
type mismatch
2018-11-20 04:04:12.850 ERROR The
setJournalFeedExportImportContentProcessor method has thrown an
exception java.lang.IllegalArgumentException: argument type mismatch
Does anybody having idea how can I do this proper way on this?

MVCResourceCommand to send binary data inside native journal portlet

I would like to send a binary file via an appended MVCResourceCommand I coded for the native journal portlet. But the program is unable to use the OutputStream provided by the resource request.
IOUtils.copy( input, response.getPortletOutputStream() );
Considering:
The code works perfectly on StrutsActions
In custom portlets, it also works
In StrutsActions:
IOUtils.copy( input, response.getOutputStream() );
However, the code throws an IllegalStateException, saying that the writer is being used when I call response.getOutputStream().
I know we can not mix these two
The code is not attempting to do so
I wonder if Liferay is doing something with that request before it reaches my extension of BaseMVCResourceCommand, this is specifically for that native portlet.
I checked the preview feature for a webcontect item, but its URL is for the view mode.
The URL is created from a portlet:resourceURL tag inserted through a JSP fragment and the command is in its own OSGi module.
For sure, the URL is correct and the command logs that it was hit, but the exception is thrown afterwards.
The portlet I am trying to change is the:
"com_liferay_journal_web_portlet_JournalPortlet"
Any thoughts?
PS: I know about the Servlet and Portlet ResponseUtils. but they also eventually try getting the stream, leadin to the same exception.
#Component( immediate = true,
property = {
"javax.portlet.name=" + JOURNAL, "mvc.command.name=/command"
},
service = MVCResourceCommand.class )
public class Resource extends BaseMVCResourceCommand {
#Override
public void doServeResource( ResourceRequest request, ResourceResponse response ) throws PortletException {
try {
response.getPortletOutputStream();
}
catch ( Exception e ) {
throw new PortletException( e );
}
}
}
Caused by: java.lang.IllegalStateException: Unable to obtain OutputStream because Writer is already in use
at com.liferay.portlet.MimeResponseImpl.getPortletOutputStream(MimeResponseImpl.java:75)
Update:
It seems this is the source of my issues (PortletURLImpl), still looking for a solution though:
if (lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {
_copyCurrentRenderParameters = true;
}
When the URL is created it comes with all sources of garbage from the render phase. Including an MVCPath

JDT SearchEngine throws a NullPointerException

I'm trying to use JDT SearchEngine to find references to a given object. But I'm getting a "NullPointerException" while invoking the "search" method of org.eclipse.jdt.core.search.SearchEngine.
Following is the error trace:
java.lang.NullPointerException at
org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:214)
at
org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:515)
at
org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:582)
And following is the method I'm using to perform search:
private static void search(String elementName) { //elementName -> a method Name
try {
SearchPattern pattern = SearchPattern.createPattern(elementName, IJavaSearchConstants.METHOD,
IJavaSearchConstants.REFERENCES, SearchPattern.R_PATTERN_MATCH);
IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
SearchRequestor requestor = new SearchRequestor() {
#Override
public void acceptSearchMatch(SearchMatch match) {
System.out.println("Element - " + match.getElement());
}
};
SearchEngine searchEngine = new SearchEngine();
SearchParticipant[] searchParticipants = new SearchParticipant[] { SearchEngine
.getDefaultSearchParticipant() };
searchEngine.search(pattern, searchParticipants, scope, requestor, null);
} catch (Exception e) {
e.printStackTrace();
}
}
Refer the "Variables" window of the following snapshot to check the values of the arguments passing to the "searchEngine.search()":
I think the the issue is because of the value of "scope" [Highlighted in 'BLACK' above].
Which means "SearchEngine.createWorkspaceScope()" doesn't return expected values in this case.
NOTE: Please note that this is a part of my program which runs as a stand-alone java program (not an eclipse plugin) using JDT APIs to parse a given source code (using JDT-AST).
Isn't it possible to use JDT SearchEngine in such case (non eclipse plugin program), or is this issue due to some other reason?
Really appreciate your answer on this.
No. You cannot use the search engine without openning a workspace. The reason is that the SearchEngine relies on the eclipse filesystem abstraction (IResource, IFile, IFolder, etc.). This is only available when the workspace is open.

ClassNotFoundException trown when registering Midlet in the PushRegistry

I'm getting an odd error I can't get to the bottom of. When I register the midlet in the Push Registry it throws the ClassNotFoundException. I've used a very standard implementation straight from the API documentation just the url has been altered
// MIDlet class name
String midletClassName = this.getClass().getName();
// Register a static connection.
String url = "sms://:2049";
// Use an unrestricted filter.
String filter = "*";
PushRegistry.registerConnection(url, midletClassName, filter);
this for some reason throws the java.lang.ClassNotFoundException! When I view the JAD it looks ok:
MIDlet-1: AlarmHandler, ,sweoch.test.AlarmHandler
which is the class midletClassName equals at debug. So why is this trowing exceptions?

Resources