I need to resolve certain methods (status, jsonPath, content) mentioned in code shown below -
mockMvc.perform(MockMvcRequestBuilders.get("/api/token")
.with(getAuthentication(getOauthTestAuthentication()))
.sessionAttr("scopedTarget.oauth2ClientContext", getOauth2ClientContext()))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$.username").value("cominventor"))
.andExpect(jsonPath("$.token").value("my-fun-token"));
When I searched for related projects containing these methods, many of them are importing the following
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
The problem is that I am unable to find a counterpart in package spring-security-test with version 4.2.2.RELEASE
The closest options that could have worked but haven't are
import static org.springframework.test.web.servlet.ResultMatcher.*;
import static org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.*;
The above don't contain the methods I am looking for. Any idea where should I look for these methods or their newer counterparts.
Everything worked out once I set the spring-security-test version to 4.0.2.RELEASE
I had the same problem, and I solved it importing the artifact
org.springframework.security:spring-security-test:4.2.3.RELEASE
I am using spring-boot-starter-test:1.5.3, and for some reason the folks at Spring decided not to include spring-security-test in its POM.
Related
I am currently attempting to write my first Quarkus extension, which needs to deploy a rest service. For that purpose I have been looking at the Quarkus tutorial for creating extensions here, and it is pretty close to what I need to do. The problem is that it shows a Servlet, and I would very much like to deploy a RestEasy(Jackson) service instead.
I have created an extension project and added the following service in the runtime module
package my.test.quarkus.extension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
#Path("/mytest")
public class TestEndpoint {
private static Logger LOGGER = LoggerFactory.getLogger(TestEndpoint.class);
#POST
#Path("/service")
public void testService(){
LOGGER.info("Logit!");
}
}
But the service is not being picked up it seems, as my test returns 404.
package my.test.quarkus.extension.test;
import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
public class ExtensionTest {
#RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withEmptyApplication();
#Test
public void testGreeting() {
RestAssured.when().post("/mytest/service").then().statusCode(200);
}
}
I assume i need a BuildItem registering the service inside the deployment project of my extension, but my question is, which BuildItem do i use? Looking at the list of BuildItems there are loads of them, and even filtering those out that has nothing to do with RestEasy, still leaves over 50, most of them without JavaDoc.
If someone can help me with the problem at hand, simply registering a RestEasy service, as well as an interceptor, from an extension, that would be appreciated. And you will get bonus gratitude if you can explain exactly how to navigate through the Quarkus BuildItems when building extensions, because to me it just seems like a jungle of code, but I am guessing I am missing something.
In gradle 7.3, I found the following source code:
package org.gradle.util;
import com.google.common.base.Objects;
import com.google.common.collect.Ordering;
import javax.annotation.Nullable;
/**
* This class is only here to maintain binary compatibility with existing plugins.
*
* #deprecated Will be removed in Gradle 8.0.
*/
#Deprecated
public class VersionNumber implements Comparable<VersionNumber> {
...
So is this feature dropped or moved? What's the new way of using VersionNumber related functionality?
That class and many others in the util package were not intended to be used in plugins or anything outside of Gradle's codebase.
In #16745, the Gradle team formally deprecated many of the utility classes and moved/copied them into an internal utility package. Some utility classes have replacements as noted in their respective Javadoc, but some such as VersionNumber have no public replacement provided by Gradle. As such, this should be considered a private API and you should not use it anywhere in your project's build or plugins.
As an alternative, you can use a semver library of your choosing as a replacement.
I'm trying to start a Jersey/1.7 based project from scratch (as opposed to copying an existing project and adding new code on top, which is what my client normally does) in order to learn how stuff works. I'm stuck in a very early phase, trying to process a simple HTTP request:
package com.example.foo.view.rest;
import javax.ws.rs.Path;
import javax.annotation.security.RolesAllowed; // package javax.annotation.security does not exist
#Path("user")
#RolesAllowed("valid-users") // cannot find symbol
public class UserService extends BaseService {
public UserService() {
super();
}
}
I've copied these files from another project:
asm-3.1.jar
jackson-core-asl-1.9.2.jar
jackson-jaxrs-1.9.2.jar
jackson-mapper-asl-1.9.2.jar
jackson-xc-1.9.2.jar
jersey-client-1.17.jar
jersey-core-1.17.jar
jersey-json-1.17.jar
jersey-multipart-1.17.jar
jersey-server-1.17.jar
jersey-servlet-1.17.jar
jettison-1.1.jar
jsr311-api-1.1.1.jar
Project authentication works with Oracle SSO (Oracle Identity Directory).
The only javax.annotation.security.RolesAllowed I can find is an interface and I can certainly not see an actual implementation anywhere in my codebase. In fact the whole javax.annotation.security package is missing. I don't even know what library is supposed to provide it.
I'd appreciate any hint, no matter how obvious it looks.
javax.annotation is part of java, but not included directly in the jre.
It is not included in jersey.
You have to add this jar to your project for it to work.
When I autowire the client interface for my Micronaut declarative client, I get this error:
Caused by: java.lang.IllegalStateException: At least one #Introduction method interceptor required, but missing. Check if your #Introduction stereotype annotation is marked with #Retention(RUNTIME) and #Type(..) with the interceptor type. Otherwise do not load #Introduction beans if their interceptor definitions are missing!
at io.micronaut.aop.chain.InterceptorChain.resolveIntroductionInterceptors(InterceptorChain.java:194)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1494)
What's the proper way to fix it?
Details
I have an established Grails application that I recently upgraded from 3.x to 4.0.1.
This app has a service which does several REST calls in parallel, and I am trying to add a new REST call that uses the new Micronaut HTTP declarative client.
I added the client library to dependencies in build.gradle:
compile "io.micronaut:micronaut-http-client"
My client interface looks like this (in src/main/groovy):
package com.mycompany.xyz.rest
import com.mycompany.xyz.rest.myendpoint.Results
import io.micronaut.http.annotation.Get
import io.micronaut.http.annotation.Header
import io.micronaut.http.client.annotation.Client
#Client('xyzRest')
#Header(name = 'myauthkey', value = '${myAuthKey}')
interface XyzRestClient {
#Get('/myendpoint')
Results myendpoint(String param1, String param2)
}
package com.mycompany.xyz.rest.myendpoint
import com.mycompany.xyz.rest.myendpoint.DataItem
import groovy.transform.CompileStatic
#CompileStatic
interface Results extends List<DataItem> {
}
I configured the URL in application.yml:
environments:
development:
micronaut:
http:
services:
xyzRest:
urls:
- http://xyz.mycompany.com/rest/v1
The message about #Introduction makes me think that Micronaut is not doing the process of compiling the declarative client. Is there some
What else am I missing?
Update:
I tried changing the build.gradle dependency to implementation as shown in the Micronaut docs, insteadl of compile, as shown in the Grails docs. No dice.
Update 2:
I found that the constructor for HttpClientIntroductionAdvice is never invoked during startup. I don't know why it's not being included in my project. IntelliJ shows micronaut-http-client:1.1.4 in external libraries, and it's set to compile scope.
A gradlew clean seems to have fixed the issue.
I tried to work backwards and duplicate the problem for posterity's sake, but so far I have not been able to.
I have bundle that deals mostly with interfaces and it uses a factory from a thrid party jar to get the instances for the interfaces it is using.
For example,
my-bundle.jar has...
com.oth.itf.Intrface itf = Fctry.getInstance('ABC');
has the
imports-package for com.oth.itf
third-party.jar has..
public static com.oth.itf.Intrface getInstance(String abc) {
if (...) {
return new com.oth.impl.ItfInstance();
}
}
has the exports-package for com.oth.itf and com.oth.impl
Everything works fine and bundles also get deployed but the issue is that I am getting
ClassNotFoundException for ItfInstance
on
my-bundle
when the code gets executed.
I tried adding import-package for com.oth.impl but to no avail. Things started to work when I added a
dummy declaration of com.oth.impl.ItfInstance
some where in my-bundle.jar. Looks like, Karaf gets the imports only if we explicitly use them. Is there a better way? Is there a way to force Karaf to import packages even if we don't use them explicitly?
Neil is right, if it's not used in the code it can't be imported. With Karaf you have the possibility to help. With the command bundle:dynamic-import you can add a dynamical import to the bundle on run-time. With this you're able to find the actually needed imports via bundle:headers you'll find the imported packages of this bundle. Take those and add those missing imports to your manifest generation and your're set.
If you doesn't has bundle: option, uses this dev: command:
dev:dynamic-import <BundleID>
This allows Karaf import dependencies on runtime.